Add feedback_sound option [add-on: google_assistant] (#1356)

* Add feedback_sound option

* Revert exec command

* Use pulseaudio-utils and add volume option

* Update config.json

* Update feedback doc to a grouped

* Update changelog and version

Co-authored-by: Pascal Vizeli <pascal.vizeli@syshack.ch>
This commit is contained in:
Eric Matte
2020-06-01 06:01:11 -04:00
committed by GitHub
parent aced29d0e5
commit c41189e93d
8 changed files with 47 additions and 8 deletions

View File

@@ -2,7 +2,8 @@
import json
import sys
from pathlib import Path
import subprocess
import json
import google.oauth2.credentials
from google.assistant.library import Assistant
@@ -11,11 +12,23 @@ from google.assistant.library.device_helpers import register_device
DEVICE_CONFIG = "/data/device.json"
PACAT_MAX_VOLUME = 65536
feedback = json.loads(sys.argv[4])
feedback_volume = feedback.get("volume", 0) * PACAT_MAX_VOLUME // 100
def play_sound(sound_file):
if feedback["enable"] and feedback_volume > 0:
subprocess.Popen(["paplay", "--volume={v}".format(v=feedback_volume), "/usr/share/sounds/{f}".format(f=sound_file)])
def process_event(event):
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
play_sound("start_sound.wav")
print()
if event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
play_sound("end_sound.wav")
try:
print(event)
except UnicodeEncodeError as err:
@@ -29,8 +42,8 @@ if __name__ == '__main__':
cred_json = Path(sys.argv[1])
device_json = Path(DEVICE_CONFIG)
# open credentials
print("OAth with Google")
# Open credentials
print("OAuth with Google")
with cred_json.open('r') as data:
credentials = google.oauth2.credentials.Credentials(token=None, **json.load(data))
@@ -46,7 +59,7 @@ if __name__ == '__main__':
device_model_id = sys.argv[3]
last_device_id = None
# run assistant
# Run assistant
print("Run Google Assistant SDK")
with Assistant(credentials, device_model_id) as assistant:
events = assistant.start()