X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=google_assistant.py;fp=google_assistant.py;h=a50003c7eb2a41e8326714ad24e4eccd2ec6cc34;hb=4faa994d32223c8d560d9dad0ca90a3f7eb10d6a;hp=71301e4779c2736a4a908df84b7ec7e67ba02b3f;hpb=c79ecbf708a63a54a9c3e8d189b65d4794930082;p=python_utils.git diff --git a/google_assistant.py b/google_assistant.py index 71301e4..a50003c 100644 --- a/google_assistant.py +++ b/google_assistant.py @@ -79,10 +79,15 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse: sample_rate=24000, sample_width=2, ) - audio_transcription = recognizer.recognize_google( - speech, - ) - logger.debug(f"Transcription: '{audio_transcription}'") + try: + audio_transcription = recognizer.recognize_google( + speech, + ) + logger.debug(f"Transcription: '{audio_transcription}'") + except sr.UnknownValueError as e: + logger.exception(e) + logger.warning('Unable to parse Google assistant\'s response.') + audio_transcription = None else: logger.error( f'HTTP request to {url} with {payload} failed; code {r.status_code}'