Voice Recognition stops listening after a few seconds

The only solution that will for sure get around this issue is to use a 3rd party service. 4.1.1 and 4.2 both rely on a version of the speech recognition service that does not adhere to the documented behavior in that the service running it dies silently.

If you do not wish to use a 3rd party API, and you need to account for this service death in some manner, it is possible but it’s not pretty or ideal.

Once the service dies, none of the following methods will ever be called :

  • onBeginningOfSpeech
  • onError
  • onResults
  • onEndOfSpeech

But if onBeginningOfSpeech is called before the service dies, you can be assured that either onError or onEndOfSpeech will eventually be called.

Therefore, if all you want is to be sure you are made aware of the life and death of the service in Jellybean the workaround for this problem in the built-in SpeechRecognizer is to do the following:

  • Create a boolean flag like isSpeechRecognizerAlive.
  • Any time you start up the SpeechRecognizer, set the above flag to false.
  • In onBeginningOfSpeech, if it is called, set isSpeechRecognizerAlive to true.
  • Maintain a Handler that, on a 4 second delay will check the status of isSpeechRecognizerAlive. If it is false, manually kill the SpeechRecognizer instance. If is is true, do nothing. The normal flow will take care of things for you.

Why this is not an ideal solution to maintain a continuous speech recognition setup

It wasn’t directly stated in your question but a few people want to do this so they can have continuous speech recognition. This is not really a good way to do that in 4.1.1 and 4.2 because Google’s SpeechRecognition service now kicks off with a non-optional “bloop” sound effect. There appears to be no way to turn this sound off. Nothing is listed in the API to control it. Your users WILL NOT appreciate being “blooped” at on a 4 second repeating loop.

Leave a Comment