I stumbled with this random issue... Here is my code
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext);
initializeRecognitionListener();
mSpeechRecognizer.setRecognitionListener(mRecognitionListener);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, Long.valueOf(3000L));
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
mSpeechRecognizer.startListening(intent);
Method initializeRecognitionListener():
private void initializeRecognitionListener() {
mRecognitionListener = new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle params) {
Log.d("onReadyForSpeech()", "onReadyForSpeech!");
isRecognizing = true;
}
@Override
public void onBeginningOfSpeech() {
Log.d("onBeginningOfSpeech()", "onBeginningOfSpeech!");
}
@Override
public void onEndOfSpeech() {
Log.e("onEndOfSpeech()", "onEndOfSpeech! stop SCO");
}
...
}
Main issue that is "onReadyForSpeech()" and "onBeginningOfSpeech()" methods sometimes doesn't called after mSpeechRecognizer.startListening(intent). Also "onEndOfSpeech()" also can be not called.
I'm using Nexus 4 with Android 4.2.2