#!/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
class GoogleResponse(NamedTuple):
+ """A response wrapper."""
+
success: bool
response: str
audio_url: str
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'],
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()
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.'
audio_url=audio,
audio_transcription=audio_transcription,
)
- sys.exit(-1)