我目前有一个语音识别器正在听语音,它通过一个按钮激活,该按钮分别切换startListening()和stopListening()。我的问题是stopListening()在第一次之后实际上没有停止speechRecognizer。使用按钮激活和取消激活speechRecognizer时,您可以清晰地听到独特的声音。但是,在第一次(成功)之后调用stopListening()之后,不会产生结束声音,并且它结束的唯一方法是它是否超时。
我像这样创建speechRecognizer:
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(this);
我覆盖了所有必要的方法:
@Override
public void onReadyForSpeech(Bundle params) {
Log.i(TAG, "Ready for speech input");
}
@Override
public void onBeginningOfSpeech() {
mIsEndOfSpeech = false;
Log.i(TAG, "Speech beginning");
}
@Override
public void onRmsChanged(float rmsdB) {
Log.i(TAG, "Speech RMS Changed: " + rmsdB);
}
@Override
public void onBufferReceived(byte[] buffer) {
Log.i(TAG, "Speech buffer received: " + buffer.toString());
}
@Override
public void onEndOfSpeech() {
mIsEndOfSpeech = true;
Log.i(TAG, "Speech recognition ended");
}
@Override
public void onError(int error) {
Log.e(TAG, "Speech recognition error: " + error);
}
@Override
public void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
if (mSpeechRecognizer != null) {
mSpeechRecognizer.destroy();
Log.i(TAG, "Speech destroy");
}
}
@Override
public void onResults(Bundle results) {
Log.i(TAG, "Speech recognition results received");
ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
}
@Override
public void onPartialResults(Bundle partialResults) {
Log.i(TAG, "Speech recognition partial results received");
}
@Override
public void onEvent(int eventType, Bundle params) {
Log.i(TAG, "Speech recognition event called: " + eventType);
}
我的问题在于第一次尝试调用startListening()和stopListening()成功。但是,之后的任何尝试,stopListening()都不起作用,它必须超时才能结束。我注意到的一件事是,在LogCat中,它表示即使调用了startListening(),也不能在startListening()之前调用stopListening()。
答案 0 :(得分:2)
假设Google是您的默认识别服务提供商,那么当前版本的Google&#39; Now&#39; stopListening()
无效。
请参阅this thread for more information及其他相关错误。
如果您要对其进行测试以确认您的问题,则已在most recent beta release中进行了修复。还有一些其他错误仍然存在。