0

正如标题所说,在我更新了我的 Android Marshmallow 手机中的 Google App 后,语音识别在我说完之后最多需要 7 秒才能停止。当我在 Lollipop 设备中使用旧版 Google App 运行我的应用程序时,语音结束超时仅需要 2 秒。

这是我的代码:

SpeechRecognizer speechrecognizer;
    String TAG="joshtag";
    class listener implements RecognitionListener          
       { 
                public void onReadyForSpeech(Bundle params)
                { 
                         loge("onReadyForSpeech");
                } 
                public void onBeginningOfSpeech() 
                { 
                         loge("onBeginningOfSpeech");
                } 
                public void onRmsChanged(float rmsdB)
                { 
                         loge("onRmsChanged");
                } 
                public void onBufferReceived(byte[] buffer)
                { 
                         loge("onBufferReceived");
                } 
                public void onEndOfSpeech() 
                { 
                         loge("onEndofSpeech");
                } 
                public void onError(int error)
                { 
                         loge("error " +  error);
                         stopMicrophoneGlow();
                } 
                public void onResults(Bundle results)                   
                { 
                    stopMicrophoneGlow();
                         String str = new String();
                         loge("ASR2 onResults " + results);
                         ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                         loge("result " + data.get(0));
                         sendTextInputFromUser(data.get(0).toString())  ; 
                } 
                public void onPartialResults(Bundle partialResults)
                { 
                         loge("onPartialResults");
                } 
                public void onEvent(int eventType, Bundle params)
                { 
                         loge("onEvent " + eventType);
                } 
       } 

speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);      
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);       speechIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 2000);     speechIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 1500);    speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en");
speechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());
speechrecognizer = SpeechRecognizer.createSpeechRecognizer(this);       
speechrecognizer.setRecognitionListener(new listener());   

在上面的代码中,我使用“new Listener()”调用语音识别。它允许我在没有 Google Speak Popup 的情况下进行语音识别,但是语音超时的结束时间很长:大约 7 秒,尽管我在 Intent 中只指定了 2000 毫秒。

解决方法:相反,如果我调用语音识别,使用“说话”弹出窗口,如下所示:

this.startActivityForResult(speechIntent, SPEECHRECON_CODE);

然后,语音超时结束时间很短(大约 2 秒),一切都很好。

如何在没有弹出窗口的情况下进行语音识别,绕过最新谷歌应用更新中的语音“错误”?有任何想法吗?

4

0 回答 0