GoogleCloudPlatform / android-docs-samples

Apache License 2.0
375 stars 596 forks source link

Pausing the Speech Recognition Stream. #43

Open SzasznikaJanos opened 6 years ago

SzasznikaJanos commented 6 years ago

Im currently developing and Android app based on TextToSpeech and Voice Recognition, for Recognition i use Google Cloud Speech API all are working fine. But i have a problem on pausing the Speech Recognition. Im using the stopVoiceRecogonition method from their sample code provided by Google. The problem is that im shutting down the Speech Recognizer and that takes a bit time. But i need that instantly on button press. Because after the speech recognition is followed by TextToSpeech. and if the Speech Recognition is not shutdown in time it will start to recognize the TTS voice. If I start TTS when the Speech Recognizer is shutdown. It breaks the smoothness of the app. Searched everywhere. Also cant or there is not documentation about that either.

The problem is : The stopVoicerRecognition() Analyzed with TraceView., it`s random ,sometimes is runs fast sometimes takes way long. On the emulator is not that much frequent then real physical device.

  public void stop() {
    synchronized (mLock) {
    if (mThread != null) {
        mThread.interrupt();
        mThread = null;
    }

    dismiss();
    if (mAudioRecord != null) {
        mAudioRecord.stop();
    }

}
}`

This fuction if is running on Main Thread can skip 1000+ Frames . usually ~200

untitled

KajcsaErno commented 6 years ago

I have the same issue, anybody can help?

yaraki commented 6 years ago

This indicates that the other synchronized block is taking too long to finish. In the original sample, ProcessVoice#run contains the block. It always takes only about 40 milliseconds. Did you modify that part? For example, did you increase the size of the buffer?

SzasznikaJanos commented 6 years ago

No i did not modify the buffer on anything from Speech Sample Code. I moved just The StartVoiceRecorder() from MainActivity`s OnStart() and also the stopVoiceRecorder() from on Destroy , i got a work around solution : Removed the synchronized(mLock)


           if (mThread != null) {
            mThread.interrupt();
            mThread = null;
    }```
jnfran92 commented 6 years ago

I removed "synchronized(mLock)" from all code in "VoiceRecorder" class. It works for me.

fedoretskn commented 6 years ago

I used the original sample. And you can reproduce this issue if you add a stop button on activity which stops voiceRecorder. Launch the app only on Android 4th ver (I tested on 19 API ver), you can see that stop() works very slowly. about few seconds. On 5 and higher Android versions all is ok

SzasznikaJanos commented 5 years ago

Still getting the Stream was half close error.