Google-cloud-python: Intermittent gRPC error while streaming audio to Google Cloud Speech

Created on 13 Sep 2017  路  9Comments  路  Source: googleapis/google-cloud-python

  1. OS type and version
    Code run in NAO Robot with Gentoo OS but I can see the issue in my Ubuntu VM as well

  2. Python version and virtual environment information python --version
    2.7.3

  3. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
    google-cloud : 0.26.1
    google-cloud-speech : 0.27.0

  4. Stacktrace if available

File "/home/nao/.local/lib/python2.7/site-packages/grpc/_channel.py", line 351, in next
    return self._next()
  File "/home/nao/.local/lib/python2.7/site-packages/grpc/_channel.py", line 342, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.INVALID_ARGUMENT, Invalid audio content: too long.)>
  1. Steps to reproduce
    Unable to reproduce this since it happened randomly

  2. Code example
    I based my code using this example: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe_streaming_mic.py

I added few things and change the recording input to arecord (as I didn't manage get pyaudio to work in the robot). I also added a timeout for if user didn't speak for 10 seconds, it will end the recording (it will also end the recording when user finish talking).

def stream_audio(self):
        global LISTENING
        reccmd = ["arecord", "-f", "S16_LE", "-r", "16000", "-t", "raw"]
        p = subprocess.Popen(reccmd, stdout=subprocess.PIPE)
        timeStart = datetime.datetime.now()
        try:
            while LISTENING:
                if((datetime.datetime.now()-timeStart).total_seconds()<=10):
                    data = p.stdout.read(1024)
                    self._buff.put(data)
                else:
                   log.debug("User did not speak anything...")
                    LISTENING = False
                    self.closed = True
                    self._buff.put(None)
        except Exception, e:
            print "Error in streaming audio: "+str(e)
        p.kill()`

Full code is in attachment
sample code.txt

grpc speech

Most helpful comment

I have this same problem, and it's really frustrating. Also, @lukesneeringer - seriously? Do you think everyone who posts here is an idiot? OBVIOUSLY anyone who had this issue would start by checking that it wasn't too long. Mine are limited at 35 seconds and it fails... maybe 45% of the time. Please stop closing stuff because you lack human logic.

All 9 comments

Your problem is almost certainly exactly what the error message says it is: audio too long. The limit is one minute.

Yea but my audio is 10 second at most. If it exceed 10 seconds, the audio stream thread will be stopped instantly (or probably I didn't stop it properly?). BTW I'm very new to Python and I didn't fully understand how generator works

I have the same problem. It seems that dispite the streaming_recognize session is stopped after a few seconds, any subsequent call adds to the total elapsed time, ultil it encounters the limit.
I was not able to reset the elapsed time or the streaming session, except by restarting the whole process (very inconvenient).
Any hints?

I have this same problem, and it's really frustrating. Also, @lukesneeringer - seriously? Do you think everyone who posts here is an idiot? OBVIOUSLY anyone who had this issue would start by checking that it wasn't too long. Mine are limited at 35 seconds and it fails... maybe 45% of the time. Please stop closing stuff because you lack human logic.

@jaredwa, I would like to remind you to please adhere to the code of conduct for this project. Please do not personally attack anyone who participates in this project.

This issue has been closed for 7 months without the original reporter replying indicating that it is still an issue. If you are able to reproduce with the latest version of the client please file a new bug and we will investigate.

I have exactly the same problem with latest dialogflow Java library. Please advise ...


com.google.cloud
google-cloud-dialogflow

0.75.0-alpha

2019-01-07 03:35:14 [Gax-2] DEBUG c._.t.g.c.s.DialogflowIntentStream - AudioStream: Got error throwable:{}
com.google.api.gax.rpc.OutOfRangeException: io.grpc.StatusRuntimeException: OUT_OF_RANGE: While calling Cloud Speech API: Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.
at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:63)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
at com.google.api.gax.grpc.ExceptionResponseObserver.onErrorImpl(ExceptionResponseObserver.java:82)
at com.google.api.gax.rpc.StateCheckingResponseObserver.onError(StateCheckingResponseObserver.java:86)
at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149)
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:699)
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:397)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:459)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:546)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:467)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:584)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.grpc.StatusRuntimeException: OUT_OF_RANGE: While calling Cloud Speech API: Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.
at io.grpc.Status.asRuntimeException(Status.java:530)
... 23 common frames omitted

@zsliu This repository is for the Python client libraries for the Google Cloud APIs. Please use the Java repository to report issues with the Java client libraries.

I'm have the same problem in my code. Anyone solved this?

Return this for me:

google.api_core.exceptions.OutOfRange: 400 While calling Cloud Speech API: Audio Timeout Error: Long duration elapsed without audio. Audio should be sent  close to real time.

@keikomori Sorry you are having that bug. A couple of things:

  • This issue is ancient (closed almost three years ago), and was reported against a much older version of the google-cloud-speech library than you are likely using today (the current version is 1.3.2).
  • Your error message is actually different than the original one for this issue, so it is actually a new issue altogether.
  • The google-cloud-speech Python library is now maintained in its own repository. Please report your problem there.
Was this page helpful?
0 / 5 - 0 ratings