i am building an application which collects user data through speech recognition. My problem is that it only takes about 5 seconds before the speech timeout error is called which stops the speech recogniser from recognising any other voice. My question is: how do i increase the time for the timeout error or how do i stop the error.
My code:
SpeechRecogniser sr = createSpeechRecogniser(this)
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
sr.startListening(recogniserIntent);
sr.setOnRecognitionListener(new OnRecognitionListener(){
//implenent all its methods
onError(int code){
switch(code){
case ERROR_SPEECH_TIMEOUT:
//this is where the error is called and stops the speech recogniser
//i want the time for this error to be increased
break;
}
}
});
These optional arguments help to extend the time, if you need to increase beyond(there are limits to what time the service respects via this arguments) then you will have to overrider recognitionlistener as in stackoverflow.com/a/49810988/806328
recognizerIntent.putExtra(RecognizerIntent.ACTION_RECOGNIZE_SPEECH, RecognizerIntent.EXTRA_PREFER_OFFLINE);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 1000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 1000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 1500);