While implementing the code directly from https://cloud.google.com/speech-to-text/docs/streaming-recognize, under 'Streaming from a local file'
Have converted audio file into flac with 44100 sample rate
Here is the stack trace:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 79, in next
return six.next(self._wrapped)
File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 392, in __next__
return self._next()
File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 544, in _next
raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.OUT_OF_RANGE
details = "Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time."
debug_error_string = "{"created":"@1573394438.010189000","description":"Error received from peer ipv4:172.217.167.10:443","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.","grpc_status":11}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "gcloud_speech2text_streamfile.py", line 41, in <module>
transcribe_streaming('sample.flac')
File "gcloud_speech2text_streamfile.py", line 28, in transcribe_streaming
for response in responses:
File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 81, in next
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.OutOfRange: 400 Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.
Have tried updating grpcio libraries in case of dependency issues, trying multiple file formats, but the error didn't go away. Please help!
@tusharkgerg Would you mind providing more details, a reproducible code sample, if possible? as per my primary investigation as you are using *.flac file, for that need to change AudioEncoding from enums.RecognitionConfig.AudioEncoding.LINEAR16 to enums.RecognitionConfig.AudioEncoding.FLAC.
That sample may be broken or flaky. Please not the description from the "Performing streaming speech recognition on a local file" docs page.
Streaming speech recognition allows you to stream audio to Cloud Speech-to-Text and receive a stream speech recognition results in real time as the audio is processed.
(contrived example sending local file as a single chunk in a stream)
While you can stream a local audio file to the Speech-to-Text API, it is recommended that you perform synchronous or asynchronous audio recognition for batch mode results.
I recommend that you look at the non-streaming samples for this usecase.
@HemangChothani, tried that but gave the same error.
Here is the code sample:
`import io
def transcribe_streaming(stream_file):
"""Streams transcription of the given audio file."""
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
client = speech.SpeechClient()
with io.open(stream_file, 'rb') as audio_file:
content = audio_file.read()
# In practice, stream should be a generator yielding chunks of audio data.
stream = [content]
requests = (types.StreamingRecognizeRequest(audio_content=chunk)
for chunk in stream)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=44100,
language_code='en-US')
streaming_config = types.StreamingRecognitionConfig(config=config)
# streaming_recognize returns a generator.
responses = client.streaming_recognize(streaming_config, requests)
for response in responses:
# Once the transcription has settled, the first result will contain the
# is_final result. The other results will be for subsequent portions of
# the audio.
for result in response.results:
print('Finished: {}'.format(result.is_final))
print('Stability: {}'.format(result.stability))
alternatives = result.alternatives
# The alternatives are ordered from most likely to least.
for alternative in alternatives:
print('Confidence: {}'.format(alternative.confidence))
print(u'Transcript: {}'.format(alternative.transcript))
transcribe_streaming('sample.flac')
`
Error is:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 79, in next
return six.next(self._wrapped)
File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 392, in __next__
return self._next()
File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 561, in _next
raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.OUT_OF_RANGE
details = "Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time."
debug_error_string = "{"created":"@1573499856.914183000","description":"Error received from peer ipv4:216.58.200.170:443","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.","grpc_status":11}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "gcloud_speech2text_streamfile.py", line 41, in
transcribe_streaming('sample.flac')
File "gcloud_speech2text_streamfile.py", line 28, in transcribe_streaming
for response in responses:
File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 81, in next
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "
google.api_core.exceptions.OutOfRange: 400 Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.
@tseaver, I am basically trying to use gcloud speech to text to ingest streaming audio through a url. I was first trying to test the streaming example on a local file.
@tusharkgerg tried with your code and it's working fine, there might be a problem with the sample.flac file.Can you please try with the other files?
Thanks @HemangChothani for verifying. I got the microphone streaming example from gcloud samples working, which is closer to the eventual goal. Now I'm onto passing in a url stream for speech to text.
Also, it would be great to connect with you @HemangChothani, found some inefficiencies in the speech to text results and wanted to brainstorm possibilities if possible.
Thanks!
I'm having the exact same issue. Current solution: restart the function every time I get the error.
The trouble is that this operation is lossy (data being lost in between restarts) - is there an up to date example of continuous streaming that works?
This error (google.api_core.exceptions.OutOfRange: 400 Audio Timeout Error: Long duration elapsed without audio. Audio should be sent close to real time.) shows up when I try to pause sending audio data to google momentarily. Is there a way to pause and send it later programmatically? Otherwise I have to turn on and off the microphone every time which takes a little time to take effect. I want to avoid turning mic on and off and instead pause sending the mic data to Google.
The google-cloud-speech client library is no longer being maintained in this repository. Please use the new repo's issue tracker instead.