正如标题所说,在我使用Android Marshmallow手机更新Google App后,语音识别需要7秒才能停止,在我说完之后。 当我在带有旧版Google App的Lollipop设备中运行我的应用程序时,语音结束超时仅需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毫秒。
替代方法: 相反,如果我打电话给语音识别,请使用“Speak”弹出窗口,如下所示:
this.startActivityForResult(speechIntent, SPEECHRECON_CODE);
然后,语音结束超时很短(大约2秒),一切都很好。
如果没有Popup,我怎样才能进行语音识别,绕过最新Google App更新中的语音结束“bug”?任何想法?