Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does RecognitionListener.onError() automatically SpeechRecognizer.cancel()?

For various reasons, I need to use the raw SpeechRecognizer API instead of the easier RecognizerIntent (RECOGNIZE_SPEECH) activity.

That means, among other things, that I need to handle RecognitionListener.onError() myself.

In response to some of the errors, I simply want to re-start listening. This looks straightforward but when I just call SpeechRecognizer.startListening() upon error, this sometimes seems to trigger two different errors:

 ERROR/ServerConnectorImpl(619): Previous session not destroyed

and

"concurrent startListening received - ignoring this call"

Which hints that I should have done some cleanup before attempting to call SpeechRecognizer.startListening() again.

If this is true, it means that upon a RecognitionListener error, listening is not automatically stopped and/or canceled.

It is also possible that some errors do stop/cancel listening, while others don't. There are really only 9 SpeechRecognizer errors:

  1. ERROR_NETWORK_TIMEOUT
  2. ERROR_NETWORK
  3. ERROR_AUDIO
  4. ERROR_SERVER
  5. ERROR_CLIENT
  6. ERROR_SPEECH_TIMEOUT
  7. ERROR_NO_MATCH
  8. ERROR_RECOGNIZER_BUSY
  9. ERROR_INSUFFICIENT_PERMISSIONS

Since the documentation isn't very detailed about which error cancels listening and which doesn't, do you happen to know, based on your experience, which errors require doing cleanup (and to which extent) before attempting SpeechRecognizer.startListening() again?

like image 877
srf Avatar asked May 01 '11 14:05

srf


2 Answers

No, cancel is not called when onError is invoked. You can look at the source here.

like image 84
Femi Avatar answered Sep 26 '22 10:09

Femi


you can destroy current session by destroy(). And you can restart it again

like image 28
kis Avatar answered Sep 25 '22 10:09

kis