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
I posted a very similar answer on another post:
This is a Google Voice Search/Jelly Bean bug that has been outstanding on the AOSP bug tracker for nearly a year.
I posted on the Google Product Forum about it here too, but no response. If you are reading this and would like these issues to be resolved, please do star the AOSP issue and comment on the Product Forum post to get it noticed!
To work around this issue, you'll need an implementation such as the one demonstrated here.
In my testing today, it does appear that the latest version of Google Search has fixed this problem internally though - So update Google Search on the Play Store and this problem may disappear - If that's not the case for you, please do comment below, as it may be fixed in only certain versions of the Google Search apk, in which case it would be helpful to know where these variations occur to handle them gracefully in our code!
Seems to be I've fixed my problem. Main idea to fix is keep single instance of SpeechRecognizer object instead of recreating it each time. After these changes I didn't get any "Recognizer busy" error. But my HTC One S still freezes when I use my app. I could not understand why...