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?