我目前有一个语音识别器听声音,它是通过一个按钮激活,分别切换startListening()和stoppllistening()。我的问题是,stoppllistening()实际上并没有在第一次之后停止语音识别器。当使用按钮激活和关闭语音识别器时,您可以清楚地听到不同的声音。然而,在第一次调用stoppllistening()之后(它成功了),结束声音不会产生,它结束的唯一方式是超时。
我创建的语音识别器如下:
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()和stoppllistening()的第一次尝试成功。然而,在此之后的任何尝试,stoppllistening()都不起作用,它必须超时才能结束。我注意到的一件事是,在LogCat中,它声明'不能在没有startListening()之前调用stoppllistening(),即使startListening()已经被调用。
假设Google是您默认的识别服务提供商,当前版本的Google 'Now' stopListening()
无法正常工作。
请参阅此主题了解更多信息和其他相关错误。
如果您想测试以确认您的问题,它已在最近的测试版中修复。其他一些bug仍然存在。