In Android 5, I ran into a strange problem. The first startListening call results in onError with error code 7 ( ERROR_NO_MATCH ).
I made a test application with the following code:
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);
And to have these log messages after the first startListening call:
onError 7 onReadyForSpeech onBeginningOfSpeech onEndOfSpeech onResults
And the following messages after another startListening call:
onRmsChanged ... onRmsChanged onReadyForSpeech onRmsChanged ... onRmsChanged onBeginningOfSpeech onRmsChanged ... onRmsChanged onEndOfSpeech onRmsChanged onRmsChanged onRmsChanged onResults
So what is the cause of this error and how to fix it?
source share