在Android 5中我遇到了一個奇怪的問題。 SpeechRecognizer的startListening
的第一個調用結果爲錯誤代碼7的onError(ERROR_NO_MATCH)。SpeechRecognizer在第一次聽時會拋出onError
我做了測試應用程序用下面的代碼:
if (speechRecognizer == null) {
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle bundle) {
Log.d(TAG, "onReadyForSpeech");
}
@Override
public void onBeginningOfSpeech() {
Log.d(TAG, "onBeginningOfSpeech");
}
@Override
public void onRmsChanged(float v) {
Log.d(TAG, "onRmsChanged");
}
@Override
public void onBufferReceived(byte[] bytes) {
Log.d(TAG, "onBufferReceived");
}
@Override
public void onEndOfSpeech() {
Log.d(TAG, "onEndOfSpeech");
}
@Override
public void onError(int i) {
Log.d(TAG, "onError " + i);
}
@Override
public void onResults(Bundle bundle) {
Log.d(TAG, "onResults");
}
@Override
public void onPartialResults(Bundle bundle) {
Log.d(TAG, "onPartialResults");
}
@Override
public void onEvent(int i, Bundle bundle) {
Log.d(TAG, "onEvent");
}
});
}
final Intent sttIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en");
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
speechRecognizer.startListening(sttIntent);
而且具有第一startListening
調用後此日誌消息:
onError 7
onReadyForSpeech
onBeginningOfSpeech
onEndOfSpeech
onResults
又經過startListening
調用以下消息:
onRmsChanged
...
onRmsChanged
onReadyForSpeech
onRmsChanged
...
onRmsChanged
onBeginningOfSpeech
onRmsChanged
...
onRmsChanged
onEndOfSpeech
onRmsChanged
onRmsChanged
onRmsChanged
onResults
那麼,這個錯誤的原因是什麼?我修復它?
可能是您正在使用的SpeechRecognizer實施中的一個錯誤。它是什麼實現?例如。我看到類似於Google App 4.7.13.19.arm的內容。 – Kaarel
是的,@Kaarel,問題是版本4.7.13.19.arm – xVir