语音识别意图开始TTS结束前讲话 [英] Speech recognition intent starts before TTS ends speaking

查看:602
本文介绍了语音识别意图开始TTS结束前讲话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个Android应用程序这给使用TTS命令(文本到语音),然后听使用语音识别意向的用户的声音回答。

I've developed an Android App which give commands using tts (Text to Speech) and then listen to the vocal answer of the user using Speech Recognition Intent.

显然,只有当TTS结束说话,然后语音识别的意图被抛出。
有时,大多是当我从一个活动,务必到另一个,或者当我通过一个按钮来激活这一过程中,语音识别意图开始之前TTS装饰说话!
问题是,该命令的相同的文本,然后获取和分析,而不是用户的话。在code,告诉语音识别等的部分是这个:

Obviously, only when tts finishes to speak, then the intent of speech recognition is thrown. Sometimes, mostly when I swich from an activity to another, or when I activate this process through a button, THE SPEECH RECOGNIZER INTENT STARTS BEFORE TTS FINISHES TO TALK! The problem is that the same text of the command is then acquired and analyzed instead of the words of the user. The part of the code that tells speech recognizer to wait is this one:

while(tts.isSpeaking()){
    //DOING NOTHING
}
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

try {
      startActivityForResult(intent, RESULT_SPEECH);
} catch (ActivityNotFoundException a) {
    Toast t = Toast.makeText(getApplicationContext(),"Opps! Your device doesn't support Speech to Text", Toast.LENGTH_SHORT);
    t.show();
}    

任何人是否有一个解决方案吗?这似乎是相当随机的。有时它会等待,有时没有。
谢谢大家!

Does anybody have a solution? It seems to be quite random. Sometimes it waits, sometimes not. Thanks everyone!!

推荐答案

使用 tts.isSpeaking()是没用的原因有几个,你可以阅读这个详细信息:

Using tts.isSpeaking() is useless for several reasons, you can read this for details:

<一个href=\"http://stackoverflow.com/questions/6401805/problem-with-isspeaking-when-using-text-to-speech-on-android\">Problem与isSpeaking()在Android 使用文本到语音转换时

Problem with isSpeaking() when using Text-to-Speech on Android

这一翻译,你需要设置OnUtteranceProgressListener

Intead, you need to set OnUtteranceProgressListener

    tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
        @Override
        public void onStart(String utteranceId) {
            // Nothing
        }

        @Override
        public void onError(String utteranceId) {
            // Nothing
        }

        @Override
        public void onDone(String utteranceId) {
            // Restart recognizer here

请注意,为了使您需要设置 TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID 在tts.speak通话PARAMS这个监听器的工作。

Please note that to make this listener work you need to set TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID with params in tts.speak call.

这篇关于语音识别意图开始TTS结束前讲话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆