Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Speechrecognizer stopListening() has no effect?

I have a problem when using SpeechRecognizer.stopListening() on Android, after having invoked startListening(). It simply seems to have no effect. The audio continues to be processed, and the recognition results are returned, just as if stopListening() had not been invoked.

Has anyone else had similar problems? May I be doing something wrong?

A possible clue: Immediately after invoking stopListening(), onError() is called with SpeechRecognizer.ERROR_CLIENT. Perhaps this means that the stop invocation failed?

The problem appears both when stopListening() is invoked before the start of speech is detected, or while speech is being processed.

startListening() and stopListening() are both invoked from the main thread.

Tested with both Android 5 and six on at least two different devices.

like image 915
Alex B Avatar asked Jun 22 '16 09:06

Alex B


1 Answers

stopListening() in your explanation is behaving as expected. This call does not prevent the Recognizer from processing the speech input up until this point.

It is also expected that it will call onError() with SpeechRecognizer.ERROR_CLIENT. If you don't wish to handle this as an 'error', then at the point in your code where you call stopListening() add a simple boolean value:

deliberatelyCalledStop = true;

And then inside the error handling, you'll know if this has been thrown as an expected outcome and you can disregard it.

In order to shut down the recognition service and ignore all speech input detected thus far, you need to call:

recognizer.cancel();
recognizer.destroy(); // if you want to destroy it

These methods will achieve what you want.

Please be aware, at the time of writing, there are some pretty major bugs with Google's Recognition Service.

I recommend you read my answer to this question and then check out the gist of the bugs that I've already reported.

like image 134
brandall Avatar answered Sep 22 '22 20:09

brandall