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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With