summaryrefslogtreecommitdiff
path: root/google_assistant.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-02-08 17:46:56 -0800
committerScott Gasch <[email protected]>2022-02-08 17:46:56 -0800
commite8fbbb7306430478dec55d2c963eed116d8330cc (patch)
tree28c61b43d11df95b0d70d7f12eba139e02a3942e /google_assistant.py
parent0d63d44ac89aab38fe95f36497adaf95110ab949 (diff)
More cleanup, yey!
Diffstat (limited to 'google_assistant.py')
-rw-r--r--google_assistant.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/google_assistant.py b/google_assistant.py
index b0aabf3..4a3a58f 100644
--- a/google_assistant.py
+++ b/google_assistant.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python3
+"""A module to serve as a local client library around HTTP calls to
+the Google Assistant via a local gateway."""
+
import logging
-import sys
import warnings
from typing import NamedTuple, Optional
@@ -33,6 +35,8 @@ parser.add_argument(
class GoogleResponse(NamedTuple):
+ """A response wrapper."""
+
success: bool
response: str
audio_url: str
@@ -57,7 +61,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
is True, perform speech recognition on the audio response from Google so as
to translate it into text (best effort, YMMV).
"""
- logging.debug(f"Asking google: '{cmd}'")
+ logging.debug("Asking google: '%s'", cmd)
payload = {
"command": cmd,
"user": config.config['google_assistant_username'],
@@ -76,7 +80,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
if success:
logger.debug('Google request succeeded.')
if len(response) > 0:
- logger.debug(f"Google said: '{response}'")
+ logger.debug("Google said: '%s'", response)
audio = f"{config.config['google_assistant_bridge']}{j['audio']}"
if recognize_speech:
recognizer = sr.Recognizer()
@@ -92,7 +96,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
audio_transcription = recognizer.recognize_google(
speech,
)
- logger.debug(f"Transcription: '{audio_transcription}'")
+ logger.debug("Transcription: '%s'", audio_transcription)
except sr.UnknownValueError as e:
logger.exception(e)
msg = 'Unable to parse Google assistant\'s response.'
@@ -114,4 +118,3 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
audio_url=audio,
audio_transcription=audio_transcription,
)
- sys.exit(-1)