GoogleCloudPlatform / android-docs-samples

Apache License 2.0
375 stars 596 forks source link

How to add connect timeout to the streamingAPI call? #115

Open Kiran2shaw opened 4 years ago

Kiran2shaw commented 4 years ago

I have used two files of speech module namely SpeechService.java & VoiceRecorder.java.

And have used the streamingApi call as follows:

   `public void startRecognizing(int sampleRate) {
    if (mApi == null) {
        Log.w(TAG, "API not ready. Ignoring the request.");
        return;
    }
    System.out.println("calling api....");
    // Configure the API
    mRequestObserver = mApi.streamingRecognize(mResponseObserver);
    mRequestObserver.onNext(StreamingRecognizeRequest.newBuilder()
            .setStreamingConfig(StreamingRecognitionConfig.newBuilder()
                    .setConfig(RecognitionConfig.newBuilder()
                            .setLanguageCode(getDefaultLanguageCode())
                            .setEncoding(RecognitionConfig.AudioEncoding.LINEAR16)
                            .setSampleRateHertz(sampleRate)
                            .build())
                    .setInterimResults(true)
                    .setSingleUtterance(true)
                    .build())
            .build());
}`

I am showing a progress bar until the callbacks namely are called via the StreamObserver mResponseObserver`s onNext() or orError() or OnCompleted().

But due to no response the progress bar keeps shown indefinitely so Now I need to add a timeout for this API call. With the help of which I can disable the progress bar and reset the view i.e, make the mic(for voice recording) again visible for user to try recording speech further.