Voice Recognition end of speech timeout is takes too long, after updating Google App in Android

174 views Asked by At

As the title says, after I updated the Google App in my Android Marshmallow phone, speech recognition takes up to 7 seconds to stop, after I have finished talking. The end of speech timeout takes only 2 seconds when I run my app in a Lollipop device with an older version of Google App.

Here is my code:

SpeechRecognizer speechrecognizer;
    String TAG="joshtag";
    class listener implements RecognitionListener          
       { 
                public void onReadyForSpeech(Bundle params)
                { 
                         loge("onReadyForSpeech");
                } 
                public void onBeginningOfSpeech() 
                { 
                         loge("onBeginningOfSpeech");
                } 
                public void onRmsChanged(float rmsdB)
                { 
                         loge("onRmsChanged");
                } 
                public void onBufferReceived(byte[] buffer)
                { 
                         loge("onBufferReceived");
                } 
                public void onEndOfSpeech() 
                { 
                         loge("onEndofSpeech");
                } 
                public void onError(int error)
                { 
                         loge("error " +  error);
                         stopMicrophoneGlow();
                } 
                public void onResults(Bundle results)                   
                { 
                    stopMicrophoneGlow();
                         String str = new String();
                         loge("ASR2 onResults " + results);
                         ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                         loge("result " + data.get(0));
                         sendTextInputFromUser(data.get(0).toString())  ; 
                } 
                public void onPartialResults(Bundle partialResults)
                { 
                         loge("onPartialResults");
                } 
                public void onEvent(int eventType, Bundle params)
                { 
                         loge("onEvent " + eventType);
                } 
       } 

speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);      
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);       speechIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 2000);     speechIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 1500);    speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en");
speechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());
speechrecognizer = SpeechRecognizer.createSpeechRecognizer(this);       
speechrecognizer.setRecognitionListener(new listener());   

In the above code I call speech recognition, with "new Listener()". It allows me to do Voice Recognition without the Google Speak Popup, but the end of Speech timeout is way to long: around 7 seconds, despite I specified only 2000 miliseconds in the Intent.

WORKAROUND: Instead, if I call Voice Recognition, WITH the "Speak" popup, like this:

this.startActivityForResult(speechIntent, SPEECHRECON_CODE);

Then, the end of speech timeout is very short (some 2 secs) and everything is fine.

How can I do Voice Recognition without the Popup, bypassing the lond end of speech "bug" in the latest Google App update?? any ideas?

0

There are 0 answers