In a Python program performing streaming speech recognition to Google's Speech API (essentially as detailed here), I'm trying to capture the following exception:
google.api_core.exceptions.InvalidArgument: 400 Client GRPC deadline too short. Should be at least: 3 * audio-duration + 5 seconds. Current deadline is: 189.99934293236583 second(s). Required at least: 196 second(s).
The relevant code block:
with self.MicrophoneStream(self.RATE, self.CHUNK) as stream:
while True:
audio_generator = stream.generator()
requests = (types.StreamingRecognizeRequest(audio_content=content)
for content in audio_generator)
responses = client.streaming_recognize(streaming_config, requests)
try:
self.listen_print_loop(responses, self.callback)
break
except:
self.start()
break
Not labeling the exception is functional, except that it makes the program hard to debug, since it causes any exception anywhere to trigger self.start()
.
I've tried:
- except StatusCode.INVALID_ARGUMENT # NameError: name 'StatusCode' is not defined
- except google.api_core.exceptions.InvalidArgument # NameError: name 'google' is not defined
- except grpc.RpcError # no error, just the usual exception above