Voice Recognition stops listening after a few seconds
Asked Answered
R

5

45

I tried a lot but can´t find it out, so I hope you can help me.

I am trying to build my own voice recognition app, which doesn´t show up the dialog.

I already wrote some code and it works quite fine, but my problem is that the recognizer seems to stop without any errors or other messanges in the LogCat.

A strange fact is that the "onRmsChanged" from the "RecognitionListener" interface is still called all the time, but no "onBeginningOfSpeech" is called anymore.

If I speak just after the speech recognition has started it works. But it doesn´t if I wait a few seconds.

The used API is 4.0.3 and I installed it on my Nexus 7 with the Version 4.2.1

I would really appreciate if you have some good ideas.

Some code snippets:

My class:

class SpeechListener implements RecognitionListener
{

    public void onBeginningOfSpeech() 
    {
        Log.d(TAG, "onBeginningOfSpeech()");            
    }

    public void onBufferReceived(byte[] buffer) 
    {
        Log.d(TAG, "onBufferReceived()");
    }

    public void onEndOfSpeech() 
    {
        Log.d(TAG, "onEndOfSpeech()");

    }

    public void onError(int error) 
    {
        Log.d(TAG, "onError(): " + error);

        if(error == SpeechRecognizer.ERROR_NO_MATCH)
        {

        }
        else if(error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT)
        {

        }
        else
        {
            tvOutput.setText("Error: " + error);    
        }

    }

    public void onEvent(int eventType, Bundle params) 
    {
        Log.d(TAG, "onEvent()");
    }

    public void onPartialResults(Bundle partialResults) 
    {
        Log.d(TAG, "onPartialResults()");
    }

    public void onReadyForSpeech(Bundle params) 
    {
        Log.d(TAG, "onReadyForSpeech()");
    }

    public void onResults(Bundle results) 
    {
        Log.d(TAG, "onResults(): " + results);

        String str = new String();

        ArrayList<String> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

        for(int i = 0; i < data.size(); i++)
        {
            str += data.get(i) + "\n";

        }           
        tvOutput.setText(tvOutput.getText().toString() + "\n\n" + "Results: " + str);           

    }
    public void onRmsChanged(float rmsdB) 
    {
        Log.d(TAG, "onRmsChanged()");
    }

}

And my implementation in the MainActivity:

    this.srSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    this.srSpeechRecognizer.setRecognitionListener(new SpeechListener());

    this.iSpeechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    this.iSpeechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    this.iSpeechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");      
    this.iSpeechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);

And so it´s started:

srSpeechRecognizer.startListening(iSpeechIntent);

Logs with speaking:

    12-16 13:50:53.576: D/DreamManagerService(485): Dream finished:   android.os.Binder@415bbf38
    12-16 13:50:53.576: I/DreamManagerService(485): Leaving dreamland.
    12-16 13:50:53.576: I/DreamController(485): Stopping dream: name=ComponentInfo{com.google.android.deskclock/com.android.deskclock.Screensaver}, isTest=false, userId=0
    12-16 13:50:53.586: I/PowerManagerService(485): Waking up from dream...
    12-16 13:50:53.616: I/ActivityManager(485): No longer want com.google.android.gsf.login (pid 13171): empty #17
    12-16 13:50:56.796: I/GoogleRecognitionServiceImpl(1461): #startListening [de-DE]
    12-16 13:50:56.806: I/ActivityManager(485): Start proc com.google.android.gsf.login for service com.google.android.gsf.login/com.google.android.gsf.loginservice.GoogleLoginService: pid=13343 uid=10019 gids={50019, 3003, 1007, 1028, 1015, 2001, 3006}
    12-16 13:50:56.866: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:56.886: D/dalvikvm(1461): GC_FOR_ALLOC freed 516K, 12% free 8706K/9892K, paused 18ms, total 18ms
    12-16 13:50:56.906: D/dalvikvm(1461): GC_CONCURRENT freed 160K, 9% free 9015K/9892K, paused 3ms+2ms, total 21ms
    12-16 13:50:56.906: I/AudioService(485):  AudioFocus  requestAudioFocus() from android.media.AudioManager@4135e960com.google.android.speech.audio.AudioController$1@41261910
    12-16 13:50:56.916: I/VS.G3EngineManager(1461): create_rm: m=ENDPOINTER_VOICESEARCH,l=en-US
    12-16 13:50:56.916: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:56.916: I/VS.G3EngineManager(1461): Brought up new g3 instance :/system/usr/srec/en-US/endpointer_voicesearch.config for: en-USin: 3 ms
    12-16 13:50:56.926: I/ConnectionFactoryImpl(1461): Opening SSL connection: vs.google.com:14259
    12-16 13:50:56.966: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.016: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.066: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.116: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.166: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.216: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.266: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.316: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.366: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.416: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.466: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.516: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.566: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.616: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.666: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.716: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.766: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.816: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.866: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.916: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.966: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.016: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.066: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.116: I/MainActivity/SpeechListener(13268): onBeginningOfSpeech()
    12-16 13:50:58.126: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.176: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.226: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.276: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.326: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.376: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.426: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.476: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.526: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.576: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.626: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.676: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.726: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.776: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.826: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.876: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.926: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.976: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.026: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.076: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.126: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.176: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.236: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.286: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.336: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.386: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.436: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.486: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.536: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.586: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.636: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.646: I/MicrophoneInputStream(1461): mic_close
    12-16 13:50:59.666: I/AudioService(485):  AudioFocus  abandonAudioFocus() from         android.media.AudioManager@4135e960com.google.android.speech.audio.AudioController$1@41261910
    12-16 13:50:59.666: D/dalvikvm(1461): threadid=37: thread exiting, not yet detached (count=0)
    12-16 13:50:59.666: I/MainActivity/SpeechListener(13268): onEndOfSpeech()
    12-16 13:50:59.676: I/decoder(1461): INFO: recognition time wall: 2.732 sec user: 0.54 sec sys: 0.08 sec 
    12-16 13:50:59.686: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.736: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.786: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.826: I/MainActivity/SpeechListener(13268): onResults(): Bundle[mParcelledData.dataSize=292]
    12-16 13:50:59.836: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.886: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.936: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.986: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.046: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.096: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.146: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.196: D/MainActivity/SpeechListener(13268): onRmsChanged()

Logs without speaking:

    12-16 13:53:39.246: I/GoogleRecognitionServiceImpl(1461): #startListening [de-DE]
    12-16 13:53:39.296: D/dalvikvm(1461): GC_FOR_ALLOC freed 567K, 12% free 8708K/9892K, paused 21ms, total 21ms
    12-16 13:53:39.316: D/dalvikvm(1461): GC_CONCURRENT freed 164K, 9% free 9017K/9892K, paused 3ms+2ms, total 21ms
    12-16 13:53:39.316: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.316: I/AudioService(485):  AudioFocus  requestAudioFocus() from         android.media.AudioManager@4135e960com.google.android.speech.audio.AudioController$1@41261910
    12-16 13:53:39.326: I/VS.G3EngineManager(1461): create_rm: m=ENDPOINTER_VOICESEARCH,l=en-US
    12-16 13:53:39.326: I/ConnectionFactoryImpl(1461): Opening SSL connection: vs.google.com:14259
    12-16 13:53:39.326: I/VS.G3EngineManager(1461): Brought up new g3 instance :/system/usr/srec/en-US/endpointer_voicesearch.config for: en-USin: 5 ms
    12-16 13:53:39.366: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.416: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.466: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.516: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.576: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.626: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.676: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.726: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.776: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.826: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.876: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.926: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.976: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.026: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.076: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.136: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.176: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.226: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.286: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.336: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.386: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.436: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.486: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.536: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.586: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.636: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.686: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.736: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.786: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.836: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.886: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.936: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.986: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.046: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.096: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.146: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.196: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.246: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.296: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.346: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.396: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.446: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.496: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.546: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.596: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.646: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.696: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.746: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.796: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.846: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.896: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.946: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.996: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.046: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.096: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.146: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.196: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.246: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.296: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.356: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.406: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.456: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.506: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.556: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.606: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.656: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.706: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.756: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.806: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.856: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.906: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.956: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.006: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.056: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.116: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.156: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.216: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.266: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.316: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.366: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.416: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.466: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.516: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.566: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.616: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.666: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.716: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.766: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.816: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.866: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.916: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.966: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.016: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.066: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.116: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.166: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.226: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.276: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.326: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.376: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.426: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.476: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.526: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.576: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.626: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.676: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.726: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.776: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.826: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.876: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.926: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.976: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.026: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.076: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.126: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.176: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.226: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.276: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.326: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.376: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.426: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.476: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.526: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.576: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.636: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.676: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.736: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.786: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.836: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.886: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.936: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.986: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.036: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.086: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.136: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.186: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.236: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.286: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.336: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.386: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.436: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.486: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.536: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.596: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.636: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.696: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.746: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.796: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.846: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.896: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.946: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.996: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.046: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.096: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.146: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.196: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.246: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.296: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.346: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.396: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.446: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.496: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.556: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.596: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.656: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.696: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.746: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.796: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.856: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.906: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.956: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.006: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.056: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.106: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.156: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.206: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.256: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.306: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.356: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.406: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.456: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.506: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.556: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.616: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.656: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.706: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.766: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.816: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.866: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.916: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.966: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.016: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.066: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.116: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.166: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.216: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.266: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.316: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.366: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.416: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.466: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.516: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.566: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.616: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.666: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.716: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.776: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.816: D/dalvikvm(1461): GC_FOR_ALLOC freed 106K, 9% free 9025K/9892K,         paused 32ms, total 32ms
    12-16 13:53:49.816: I/dalvikvm-heap(1461): Grow heap (frag case) to 9.282MB for 320656-byte allocation
    12-16 13:53:49.836: D/dalvikvm(1461): GC_FOR_ALLOC freed 156K, 11% free 9182K/10208K, paused 19ms, total 19ms
    12-16 13:53:49.836: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.886: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.936: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.986: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:50.036: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:50.086: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:50.136: D/MainActivity/SpeechListener(13441): onRmsChanged()
Rozalie answered 2/12, 2012 at 14:50 Comment(16)
Can you give us the full Logcat? (Not only your app but the device itself). I haven't worked with voice recognition but maybe it is related with the app screen sleeping... Or just with the implementation of the voice recognition library.Goaltender
Logs are added. It´s also a bit strange that the "onRmsChanged()" event is still called after the "onEndOfSpeech" event (see Logs)Rozalie
I'm running into the same issue. Any resolution?Twibill
Logically, there must be a way to do this. How else could "Google Now" possibly perform its magic where it waits endlessly for the user to say the word "Google" so that it can hop into action and show you the VoiceSearch siri-like screen?Rhoea
Does this also work on a Nexus 7 tablet?Rozalie
I have tried on my Galaxy Nexus and Nexus 7, and get the same results.Twibill
Nexus 7 is the prime example of how this is broken for us developers, in fact. It also appears to work this way on the Nexus 4 from what I have observed as a casual user. There are clearly two different speech recognition capabilities in Jellybean. One which requires an internet connection, comes with an alert sound effect, and dies silently after inactivity, the other of which does NOT require an internet connection and appears to last perpetually.Rhoea
So it seems to be a serious problem of the new API from the version 4.2.1 @scriptocalypse: Do you have an example of that one, which doesn´t require an internet connection?Rozalie
Open the "Google Now" app and say the word "Google" to your tablet. It will open up the voice search that relies on the API that dies after a few seconds. I do not know how they are doing this, but it is obviously via a different mechanism than the SpeechRecognizer/RecognitionListener that we're using. Also, this problem exists in 4.1.1 and 4.1.2, judging by behavior on an Asus Transformer Prime, so it seems to be all about Jellybean.Rhoea
@Rozalie please remedy the following vagueness in the question: the 1-argument createSpeechRecognizer uses the "system default recognition service", but you do not specify what this is, i.e. name and version number. I'm assuming (based on the logs) that it's Google Voice Search (or whatever it's called on Jelly Bean), but the version number still seems crucial for answering this question. I'm proposing that what you describe is not a bug in Android but rather in Google Voice Search and the question should reflect this thinking.Stedfast
@Kaarel: By now it looks like that it´s probably an Google Voice Search Problem, because it depends on the android version number (as you said). So this fact is quite the worst case for programming, because now we have to wait for an update of the android version. Maybe it´s solved with Android 4.2.2 (Fingers crossed)Rozalie
I found this workaround. Better than nothing: #14941157Avra
Your End of speech calls when you speak some thing and this mean that it heard something. but it is strange that it is still listening I think it starts listening again with out showing the start listening . I think you have to make check in the On result. if the Results are your desired results , then it's ok to turn of the speech and release it else you can stop and start the speech recognition again. it will start listening again even after the end of speech is called.Barranca
hi i have some problem in voice recognition #32866739Melchizedek
Same problem. Any workaround ?Painter
Now it's Android 11 in the market and still, I am not able to figure out any proper answer for the same problem.Wescott
R
20

The only solution that will for sure get around this issue is to use a 3rd party service. 4.1.1 and 4.2 both rely on a version of the speech recognition service that does not adhere to the documented behavior in that the service running it dies silently.

If you do not wish to use a 3rd party API, and you need to account for this service death in some manner, it is possible but it's not pretty or ideal.

Once the service dies, none of the following methods will ever be called :

  • onBeginningOfSpeech
  • onError
  • onResults
  • onEndOfSpeech

But if onBeginningOfSpeech is called before the service dies, you can be assured that either onError or onEndOfSpeech will eventually be called.

Therefore, if all you want is to be sure you are made aware of the life and death of the service in Jellybean the workaround for this problem in the built-in SpeechRecognizer is to do the following:

  • Create a boolean flag like isSpeechRecognizerAlive.
  • Any time you start up the SpeechRecognizer, set the above flag to false.
  • In onBeginningOfSpeech, if it is called, set isSpeechRecognizerAlive to true.
  • Maintain a Handler that, on a 4 second delay will check the status of isSpeechRecognizerAlive. If it is false, manually kill the SpeechRecognizer instance. If is is true, do nothing. The normal flow will take care of things for you.

Why this is not an ideal solution to maintain a continuous speech recognition setup

It wasn't directly stated in your question but a few people want to do this so they can have continuous speech recognition. This is not really a good way to do that in 4.1.1 and 4.2 because Google's SpeechRecognition service now kicks off with a non-optional "bloop" sound effect. There appears to be no way to turn this sound off. Nothing is listed in the API to control it. Your users WILL NOT appreciate being "blooped" at on a 4 second repeating loop.

Rhoea answered 8/1, 2013 at 20:59 Comment(8)
Thank you very much for your work around. Unfortunately that´s not solving my problem but it´s really close. I really appreciate your dedication. Thank´s for thatRozalie
Possible workaround for the "bloop" sound, what about muting the volume for a half second, then unmuting? I guess it depends on your app, but if you're listening for speech then you're probably not playing any other audio at the same time.Crossquestion
A helpful note: by "manually kill the SpeechRecognizer instance" scriptocalypse means call the instance's destroy() method; simply setting it to null will cause the service to throw a BUSY error when you try and restart it.Crossquestion
@Crossquestion : Thank you for the clarification, that is in fact what I meant to say. The recognizer should be stopped and handled properly. As for the solution for the bloop sound, that does depend on what your app is intended to accomplish. Sadly that is not a good solution for my use case.Rhoea
@Rhoea Any pointers to such 3rd party service? I would love to know what alternatives there are. I prefer alternatives with licensing terms that would not limit imagination & creativity... Thanks +1.Fealty
See my work around including muting the beep sound at #14941157Strait
As for third-party service, it's worth to look on #9534308Narceine
just want to confirm what @Crossquestion said: trying to circumvent the error results in "concurrent startListening received - ignoring this call" , which permanently disables the service for the appZootechnics
O
4

I have made a Service that bears an Audio to Speech Recognizer that simulates being continuous by restarting itself everytime there is an error or result. As you can see, my service listens to a Broadcast receiver in order to start/stop continuous ASR (it is battery expensive so I recommend you run this continuous ASR service only while your relevant UI is in the foreground). The results of the ASR are also broadcasted to the rest of the app. You can ignore the broadcasting, the service and the Recognizer Listener are the main idea. DONT forget the INTERNET permission and the manifest, and the service declaration:

<service android:name=".speechRecognitionService" />

SpeechRecognitionService:

    /**
     * Created by Josh on 22/07/15.
     *  This service bears an Audio to Speech recognizer (ASR), once this service is started,
     *  it listens a broadcast called "asrService".
     *  the Service starts ASR when it receives a "START-ASR" value inside the "message" parameter of its broadcast receiver
     *  the Service stopss ASR when it receives a  "STOP-ASR" value inside the "message" parameter of its broadcast receiver
     Example:
     Intent intent = new Intent("asrService");
     intent.putExtra("message", "STOP-ASR");
     LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
     Once the ASR Listener that this service bears is running, it will broadcast the results is gets.
     To catch ASR results, implement a Broadcast receiver that listens to app.asrResult="ASRresult", for example:

     private BroadcastReceiver ASRReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String message = intent.getStringExtra("message");
            if(message!=null) {
                app.logwhite("ASR says: "+message);
            }
        }
    };
     LocalBroadcastManager.getInstance(this).registerReceiver(ASRReceiver, new IntentFilter(app.asrResult));

     Unregister the broadcast receiver likewise:
     LocalBroadcastManager.getInstance(this).unregisterReceiver(ASRReceiver);
     */

    public class speechRecognitionService extends Service {

        private static speechRecognitionListenerJosh speechReconListener;
        private static SpeechRecognizer mSpeechRecognizer=null;
        private static Intent mSpeechRecognizerIntent;
        private static boolean mIslistening=false;


        //======== BROADCAST RECEIVERS
        // handler for received Intents for the "my-event" event
        private BroadcastReceiver startASRReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String message = intent.getStringExtra("message");
                if(message.equals("START-ASR")) {
                    if (mIslistening == false) {


                        if (mSpeechRecognizer != null) {
                            mSpeechRecognizer.destroy();
                            mSpeechRecognizer = null;
                        }
                        app.logy("==BROADCAST Rx: START_ASR");

                        mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                        mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en-US");
                        mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                        //mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
                        //mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE ,   this.getPackageName());
                        mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 5000);
                        mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 5000);
                        //mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
                        //mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);

                        mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
                        speechReconListener = new speechRecognitionListenerJosh();
                        mSpeechRecognizer.setRecognitionListener(speechReconListener);

                        mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
                    } else {
                        app.logy("==BROADCAST Rx: STOP_ASR");
                        mSpeechRecognizer.stopListening();
                        mSpeechRecognizer.destroy();
                        speechReconListener = null;
                    }
                }

                if(message.equals("STOP-ASR")){
                    app.logy("==BROADCAST Rx: STOP_ASR");
                    mSpeechRecognizer.stopListening();
                    mSpeechRecognizer.destroy();
                    speechReconListener = null;
                }
            }
        };


        @Override
        public void onCreate() {
            super.onCreate();

            mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en-US");
            mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL  ,   RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            //mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE ,   this.getPackageName());
            mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 4000);
            mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
            mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
            speechReconListener = new speechRecognitionListenerJosh();
            mSpeechRecognizer.setRecognitionListener(speechReconListener);

            LocalBroadcastManager.getInstance(this).registerReceiver(startASRReceiver, new IntentFilter("asrService"));
            app.toastlog("==ASR Service - CREATED");
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            LocalBroadcastManager.getInstance(this).unregisterReceiver(startASRReceiver);

            if (mSpeechRecognizer != null){
                mSpeechRecognizer.destroy();
                mSpeechRecognizer=null;
            }
            app.toastlog("==ASR Service - DESTROYED");
        }

        @Override
        public IBinder onBind(Intent intent) {
            return null;
        }

        @Override //rather not use, runs before onStart
        public int onStartCommand(Intent intent, int flags, int startId) {
            return super.onStartCommand(intent, flags, startId);
        }

        @Override
        public void onStart(Intent intent, int startId) {
            super.onStart(intent, startId);
            app.toastlog("==ASRservice - onStart");
        }



        private class speechRecognitionListenerJosh  implements RecognitionListener {

            @Override
            public void onBeginningOfSpeech() {
                mIslistening=true;
                app.loge("=ASRListener - onBeginingOfSpeech");
            }

            @Override
            public void onBufferReceived(byte[] buffer){

            }

            @Override
            public void onEndOfSpeech(){
                app.loge("=ASRListener - onEndOfSpeech");
            }

            @Override
            public void onError(int error) {
                mIslistening=false;
                String code= Integer.toString(error);

                if(error==SpeechRecognizer.ERROR_CLIENT){ // 5
                    code="ERROR_CLIENT";
                    mIslistening=false;
                    mSpeechRecognizer.destroy();
                    Intent intent = new Intent("asrService");
                    intent.putExtra("message", "START-ASR");
                    LocalBroadcastManager.getInstance(app.appContext).sendBroadcast(intent);
                }

                if(error==SpeechRecognizer.ERROR_SPEECH_TIMEOUT){ // 6
                    code="SPEECH_TIMEOUT";
                    mSpeechRecognizer.stopListening();
                    mIslistening=false;
                    Intent intent = new Intent("asrService");
                    intent.putExtra("message", "START-ASR");
                    LocalBroadcastManager.getInstance(app.appContext).sendBroadcast(intent);
                    //Usualy bounces back to ERROR_CLIENT.
                }
                if(error==SpeechRecognizer.ERROR_NO_MATCH){ // 7
                    code="ERROR_NO_MATCH";
                    mIslistening=false;
                    Intent intent = new Intent("asrService");
                    intent.putExtra("message", "START-ASR");
                    LocalBroadcastManager.getInstance(app.appContext).sendBroadcast(intent);
                    //Usually bounces back to ERROR_CLIENT.
                }

                app.loge("=ASRListener - ASR Error: "+code);
                /*
                // 1 = NETWORK_TIMEOUT
                // 2 = ERROR_NETWORK
                // 3 = ERROR_AUDIO
                // 4 = ERROR_SERVER
                // 5 = ERROR_CLIENT
                // 8 = ERROR_RECOGNIZER_BUSY
                // 9 = ERROR_INSUFFICIENT_PERMISSIONS
                */

            }

            @Override
            public void onEvent(int eventType, Bundle params){

            }

            @Override //Somehow doesn't trigger upon partial results
            public void onPartialResults(Bundle partialResults){
                ArrayList<String> results=partialResults.getStringArrayList("EXTRA_PARTIAL_RECOGNITION");
                if(results!=null) {
                    if (results.size() > 0) {
                        app.logwhite("=== ASR Partial Results: " + results);
                    }
                }
            }

            @Override
            public void onReadyForSpeech(Bundle params){
                app.loge("=ASRListener - onReadyForSpeech, LISTENING  (((( ");
            }

            @Override
            public void onResults(Bundle resultBundle){
                app.loge("=ASRListener - onResults");
                ArrayList<String> result = resultBundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                if(result!=null) {  //when speaking timeout happen, results is null

                    // matches are the return values of speech recognition engine

                    if (result.size() > 0) {
                        app.logwhite("=== ASR Results:");
                        app.logwhite(result.get(0));
                        //BC name, message
                        app.broadcast(app.asrResult,result.get(0)); //The result is broadcast to the entire app
                    }

                }

                mIslistening=false;
                Intent intent = new Intent("asrService");
                intent.putExtra("message", "START-ASR");
                LocalBroadcastManager.getInstance(app.appContext).sendBroadcast(intent);
            }

            @Override
            public void onRmsChanged(float rmsdB){
                //VOLUME VUmeter!!!!
            }
        }
    }
Outlander answered 27/7, 2015 at 15:48 Comment(3)
This was helpful to me. On restart I was not destroying the previous listener as you are doing but just calling startListening which didn't work after a speech timeout.Gassing
@Outlander How long does the voice recognizer work? I have it implemented in the same way, but there are times that it lasts longer and sometimes it lasts 4-5 voice recognitions and the system is dead I've tried to create a service that controls whether or not it works, but when I tell you that it stays silly, it stops working until that serviceHizar
@SergioAntonioSnchezCamarero It worked "forever" with me. Google App (the android app in charge of providing ASR to all other apps) changes its behavior slightly, after each update. My guess is that your app is reaching an execution point where sendBroadcast(intent) is not called. You must find this state, and add a send broadcast to it. The idea is that your app can relaunch the service on every situation. Check inside the onError, maybe I forgot, to include an error situation. A dirty fix could be to move the broadcast outside the "IF's", but still inside of onError.Outlander
S
3

You could try to supply the following RecognizerIntent extras:

  • EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
  • EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
  • EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS

although none of them really fits in this case. Android simply doesn't offer a "WAIT_UNTIL_I_START_SPEAKING" extra. It's not a bug (in Jelly Bean or where ever), it's simply a lack of a feature. And even if such an extra is added in a future version of Android there might not be a guarantee that the speech recognition app (such as Google Voice Search) actually implements this. The RecognizerIntent documentation contains plenty of extras with unspecified behavior.

Your best option might be to relaunch the recognizer as soon as you get onEndOfSpeech or onError.

Stedfast answered 2/1, 2013 at 23:16 Comment(11)
I am experiencing this problem, too, and there is no onEndOfSpeech or onError at this ridiculously short timeout, so the option to relaunch the recognizer as soon as you get one of them doesn't really exist.Fealty
srf is correct, this is definitely a bug and it is definitely new in Jellybean. Prior versions of the OS would in fact offer you onError notifications if the speech timed out. The problem is that Jellybean just silently dies. No warning, no error, no callback.Rhoea
@srf: actually there is an "onEndOfSpeech" Event (view Logs in my example). BUT: You both are right with the "onError" event, which doesn´t occur. AND: Even if the speech has finished (onEndOfSpeech is called), the recognizer seems to keep listening (the "onRmsChanged" callback is still called) and that makes no sense and hasn´t been this way on the Android versions before. So it´s definitely a bug!Rozalie
@Rozalie onRmsChanged after onEndOfSpeech makes sense because "sound level in the audio stream has changed" can happen after "the user stops speaking". The quotes come from the RecognitionListener documentation. Speaking and audio level are different things...Stedfast
@Kaarel: Could be, but if you start this code on android 4.0.3 there is no "onRmsChanged" after the "onEndOfSpeech". So it´s likely that it should work this way again. (Sure it could have changed with the new API, but I don´t think so, because it´s not possible to stop getting this onRmsChanged events in a nice way)Rozalie
There is already an open issue to a similar problem: code.google.com/p/android/issues/…Rozalie
@Rozalie : You will receive an onEndOfSpeech if the listener ever sent an onBeginningOfSpeech. You can prattle on and on for a minute or longer and it won't time out. It seems the key is to flip a switch inside of the onBeginningOfSpeech method that you can poll every few seconds to determine whether or not to automatically restart the service. BUT the service in Jellybean also has that irritating "bleep" sound on startup. That surely is not good user experience.Rhoea
I'm going to have to ask please NOT to upvote this answer. The fact that he's suggesting we listen for onEndOfSpeech or onError shows that he doesn't understand the problem, because those functions are never called after the service mysteriously dies in Jellybean. I've confirmed this on several devices, and across different OS versions. The service simply dies in Jellybean with no indication that such has happened. I would really hate to see this answer get a 100 point bounty.Rhoea
@Rhoea your call has resulted in 2 downvotes which I don't think this answer deserves :( in any case, the problem that you describe is not what the question currently describesStedfast
@Stedfast : unfortunately, the 2 upvotes you had before would have given you the bounty by default even though the answer doesn't correctly address the question either as it exists now or as it was before. His issue is this : "my problem is that the recognizer seems to stop without any errors or other messanges in the LogCat." That fact makes the proposed solution of using onEndOfSpeech or onError impossible to implement because those are never called after the service dies. Your solution would have worked pre-Jellybean, but no longer.Rhoea
@Rozalie After this bounty period expires I'd be happy to write up my workaround for this issue. I honestly don't feel like it deserves sgriffinusa's reputation because it's hacky and because it doesn't solve the unstated problem of what to do about the annoying "bleep" sound that happens when Google's new-to-Jellybean speech recognition kicks off. Without relying on a 3rd party non-Google speech API, I really have only this one imperfect solution.Rhoea
S
1

I was facing the same problem for a while and I could not find the correct working answer anywhere. To make the listening happen infinitely, post onError() or onResults() I was calling speechRecognizer.startListening(intent); again after re-instantiating the speechRecognizer and re-setting the intent object.

But as you mentioned it eventually used to go off after listening for a while.

Here is what I tried and it worked for me.

I just made sure that before recalling the speechRecognizer.startListening(intent); I would just call

speechRecognizer.stopListening();
speechRecognizer.destroy();

and go about doing things mentioned in the first para.

So far it has been working fine for me.

Stela answered 2/8, 2019 at 12:55 Comment(0)
F
0

I had the same issue with the Node.js library and here is the issue I submitted along with the response from the team. https://github.com/googleapis/nodejs-speech/issues/667

TLDR; Set your config as following (pay attention to use enhanced models)

 const config = {
        encoding: "LINEAR16",
        sampleRateHertz: 16000,
        languageCode: "en-US",
        metadata: recognitionMetadata,
        model: 'phone_call',
        useEnhanced: true}

The output that you will get is the following - pay attention to alternatives, it's tad misleading wording in my opinion but oh well :

[{"results":[{"alternatives":[{"words":[],"transcript":"I live in Boston","confidence":0.9128385782241821}],"channelTag":0,"languageCode":"en-us"},{"alternatives":[{"words":[],"transcript":" Boston is an amazing City","confidence":0.9128385186195374}],
Filomenafiloplume answered 6/11, 2020 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.