0

First: I already know there is a 65 second limit on continuous speech recognition streaming with this API. My goal is NOT to extend those 65 seconds. My app: It uses Google's streaming Speech Recognition, I based my code on this example: https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech The app works fairly well, I get ASR results and show them onscreen as the user speaks, Siri style.

The problem: My problem comes after tapping the ASR button on my app several, stopping and restarting the ASR SpeechService is a bit unreliable. Eventually, I get this error:

io.grpc.StatusRuntimeException: OUT_OF_RANGE: Exceeded maximum allowed stream duration of 65 seconds.

...as if the SpeechService was not shut down properly after several stop, restart cycles.

My code: I stop my code like this, I suspect the problem somewhere in the implementation of my StopStreamingASR method. I run it on a separate Thread because I believe it can improve performance (hoping I'm not wrong):

static void StopStreamingASR(){
    loge("stopGoogleASR_API");
    //stopMicGlow();

    //Run on separate thread to keep UI thread light.
    Thread thread = new Thread() {
        @Override
        public void run() {
            if(mSpeechService!=null) {
                mSpeechService.finishRecognizing(); 
                stopVoiceRecorder();
                // Stop Cloud Speech API
                if(mServiceConnection!=null) {
                    try {
                        app.loge("CAUTION, attempting to stop service");
                        try {
                         mSpeechService.removeListener(mSpeechServiceListener);
                            //original mActivity.unbindService(mServiceConnection);
                            app.ctx.unbindService(mServiceConnection);
                            mSpeechService = null;
                        }
                        catch(Exception e){
                            app.loge("Service Shutdown exception: "+e);
                        }
                    }
                    catch(Exception e){
                        app.loge("CAUTION, attempting to stop service FAILED: "+e.toString());
                    }
                }
            }
        }
    };
    thread.start();
}

private static void stopVoiceRecorder() {
        loge("stopVoiceRecorder");
        if (mVoiceRecorder != null) {
            mVoiceRecorder.stop();
            mVoiceRecorder = null;
        }
    }

Am I stopping the service properly in order to avoid the 65 Second Limit error? Any recommendations?

Josh
  • 6,251
  • 2
  • 46
  • 73
  • i am encountering the same issue. did you eventually find something? – Frank Oct 16 '17 at 18:30
  • @Frank Not yet! I am solving some easier bugs while I come up with some idea for this 65 sec problem. Let me know if you discover something, I will too! – Josh Oct 17 '17 at 07:30

1 Answers1

0

I manage to solve it by adding the finishRecognizing() inside the OnNext() method from the streamObserver:

public void onNext(StreamingRecognizeResponse response) {
            String text = null;
            boolean isFinal = false;
            if (response.getResultsCount() > 0) {
                final StreamingRecognitionResult result = response.getResults(0);
                isFinal = result.getIsFinal();
                if (result.getAlternativesCount() > 0) {
                    final SpeechRecognitionAlternative alternative = result.getAlternatives(0);
                    text = alternative.getTranscript();
                }
            }
            if (text != null) {
                for (Listener listener : mListeners) {
                    listener.onSpeechRecognized(text, isFinal);
                }
                if(isFinal)
                {
                    finishRecognizing();
                }
            }
        }
Frank
  • 3,073
  • 5
  • 40
  • 67