Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the SpeechRecognizer is busy when I start it after the onEndOfSpeech has been called?

I am developing in Android and use SpeechRecognizer to implement continuous speech recognition.

After start speech recognition via following code:

private void startListening(){
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getActivity().getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,Long.valueOf(3000L));
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1);
}

And call startListening() again when onEndOfSpeech has been called.

But the onError will been called , and show SpeechRecognizer.ERROR_RECOGNIZER_BUSY.

Q1: Why the SpeechRecognizer is busy when I start it after the onEndOfSpeech has been called?

Q2 How to implement the crooect way of continuous speech recognition ?

like image 368
Wun Avatar asked Jan 31 '26 21:01

Wun


1 Answers

The Android speech recognition library is designed in such a way that there will eventually be a timeout when used extensively.

As such there is no official documentation on why Google does this and even when using Google apps there is no continuous voice recognition available.

To overcome this we need to play around with the speech callback methods to catch hold of the error and try listening again. I created a library specifically to overcome this time out issue and I think it would serve your purpose as well.

Head over to Github - DroidSpeech and add the library to your project either clone it or you can use gradle dependancy. Once added initialise Droid Speech and set the listener as mentioned below,

DroidSpeech droidSpeech = new DroidSpeech(this, null);
droidSpeech.setOnDroidSpeechListener(this);

To start listening to the user call the below code,

droidSpeech.startDroidSpeechRecognition();

And you will get the voice result in the listener method,

@Override
public void onDroidSpeechFinalResult(String finalSpeechResult, boolean droidSpeechWillListen)
{
  // Do whatever you want with the speech result
}

What makes this library different is

  1. Offers continuous speech recognition support after each word is uttered,
  2. You don't need to worry about the speech busy & time out errors as the library takes care of this and makes sure it eradicates the issue altogether,
  3. You don't have to write any lines of code specific to speech recognition other than initialising the library and setting the listener methods,
  4. Can take care of asking the microphone permissions to user if required
  5. Takes care of the annoying beep sound if there is an error
like image 79
Vikram Ezhil Avatar answered Feb 02 '26 10:02

Vikram Ezhil