Repeated listening after error RecognitionListener ERROR_RECOGNIZER_BUSY

I am improving an Android application that uses the RecognitionListener class to listen to the user's voice, here I get below results:

1-) If the user clicks on the microphone icon and says something is OK 2-) If the user clicks on the microphone icon and clicks the microphone icon again or says nothing, I get onerror , and the error type is: ERROR_RECOGNIZER_BUSY

@Override public void onError(int error) { if ((error == SpeechRecognizer.ERROR_NO_MATCH) || (error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT)){ } else if(ERROR_RECOGNIZER_BUSY){ } } 

Here is my code to start listening:

  public void recognizeSpeechDirectly() { recognizer = SpeechRecognizer.createSpeechRecognizer(this.context); recognizer.setRecognitionListener(this); recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "org.twodee.andytest"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); recognizer.startListening(recognizerIntent); } 

I want to restart listening when ERROR_RECOGNIZER_BUSY appears

Another guy talked about this error in stackoverflow, but for me this is incomprehensible and cannot implement it.

How to handle ERROR_RECOGNIZER_BUSY

Thank you in advance

+6
source share
2 answers

You have ERROR_RECOGNIZER_BUSY because you call startListening twice when the user clicks the button and clicks again. Change your code as follows:

 // class member private boolean mIsListening; @Override protected void onCreate(Bundle savedInstanceState) { ......... recognizer = SpeechRecognizer.createSpeechRecognizer(this.context); recognizer.setRecognitionListener(this); recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "org.twodee.andytest"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); } 

And when you click on the icon

 if (!mIslistening) { mIsListening = true; recognizer.startListening(recognizerIntent); } @Override public void onError(int error) { if ((error == SpeechRecognizer.ERROR_NO_MATCH) || (error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT)){ } else if(ERROR_RECOGNIZER_BUSY){ } recognizer.startListening(recognizerIntent); } @Override public void onPartialResults(Bundle partialResults) { mIsListening = false; .......... } @Override public void onResults(Bundle results) { mIsListening = false; .......... } 
0
source

start your recognition with: learn SpeechDirectly ();

 public void stopRecognition(){ recognizer.destroy(); recognizer = null; } public void onError(int error) { stopRecognition(); } public void onResults(Bundle results){ //Do something stopRecognition(); } 

It works to commit "not connected to the recognition service and " ERROR_RECOGNIZER_BUSY " .

0
source

All Articles