Daniel Daniel - 3 months ago 19
Android Question

SpeechRecognizer stopListening() not working

I currently have a speech recognizer listening to voice, it is activated via a button which toggles startListening() and stopListening() respectively. My problem is the fact that stopListening() does not actually stop the speechRecognizer after the first time. When using the button to activate and deactivate the speechRecognizer, you can clearly hear the distinctive sounds. However, after calling stopListening() after the first time (which succeeds), the end sound is not produced, and the only way it ends is if it times out.

I create the speechRecognizer like so:

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);


I override all of the necessary methods:

@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);
}


My problem lies in the fact that the first attempt at calling startListening() and stopListening() succeeds. However, any attempt after that, stopListening() does not work and it has to time out for it to end. One thing I have noticed is that in LogCat, it states that 'Cannot call stopListening() without preceeding startListening(), even though startListening() has been called.

Answer

Assuming Google is your default recognition service provider, the current release of Google 'Now' stopListening() is not working correctly.

Please see this thread for more information and other related bugs.

It has been fixed in the most recent beta release if you want to test that to confirm your issue. A few other bugs do still remain.

Comments