mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 05:04:21 +01:00
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:
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.5.0
|
||||||
|
|
||||||
|
- Add an option to enable feedback sounds
|
||||||
|
|
||||||
## 2.4.0
|
## 2.4.0
|
||||||
|
|
||||||
- Improve OAuth connection process UI
|
- Improve OAuth connection process UI
|
||||||
|
|||||||
@@ -33,6 +33,18 @@ The ID of the model you've registered at Google for this add-on.
|
|||||||
|
|
||||||
The model id can also be found under the "Develop - Device registration" tab in the [Google Actions Console][google-actions-console].
|
The model id can also be found under the "Develop - Device registration" tab in the [Google Actions Console][google-actions-console].
|
||||||
|
|
||||||
|
### Option group: `feedback`
|
||||||
|
|
||||||
|
The following options are for the option group: `feedback`.
|
||||||
|
|
||||||
|
#### Option: `feedback.enabled`
|
||||||
|
|
||||||
|
Set to `true` if you want to hear feedback sounds when Google Assistant starts and stops listening to your command.
|
||||||
|
|
||||||
|
#### Option: `feedback.volume`
|
||||||
|
|
||||||
|
The percentage of volume to use for feedback sounds.
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
You first need to enable access to the Google Assistant API.
|
You first need to enable access to the Google Assistant API.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ RUN apt-get update \
|
|||||||
&& apt-get install -y --no-install-recommends \
|
&& apt-get install -y --no-install-recommends \
|
||||||
libportaudio2 \
|
libportaudio2 \
|
||||||
libasound2-plugins \
|
libasound2-plugins \
|
||||||
|
pulseaudio-utils \
|
||||||
python3 \
|
python3 \
|
||||||
python3-dev \
|
python3-dev \
|
||||||
build-essential \
|
build-essential \
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Google Assistant SDK",
|
"name": "Google Assistant SDK",
|
||||||
"version": "2.4.0",
|
"version": "2.5.0",
|
||||||
"slug": "google_assistant",
|
"slug": "google_assistant",
|
||||||
"description": "A virtual personal assistant developed by Google",
|
"description": "A virtual personal assistant developed by Google",
|
||||||
"url": "https://github.com/home-assistant/hassio-addons/tree/master/google_assistant",
|
"url": "https://github.com/home-assistant/hassio-addons/tree/master/google_assistant",
|
||||||
@@ -19,12 +19,20 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"client_secrets": "google_assistant.json",
|
"client_secrets": "google_assistant.json",
|
||||||
"project_id": null,
|
"project_id": null,
|
||||||
"model_id": null
|
"model_id": null,
|
||||||
|
"feedback": {
|
||||||
|
"enable": false,
|
||||||
|
"volume": 80
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"schema": {
|
"schema": {
|
||||||
"client_secrets": "str",
|
"client_secrets": "str",
|
||||||
"project_id": "str",
|
"project_id": "str",
|
||||||
"model_id": "str"
|
"model_id": "str",
|
||||||
|
"feedback": {
|
||||||
|
"enable": "bool",
|
||||||
|
"volume": "int(0,100)"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"image": "homeassistant/{arch}-addon-google_assistant"
|
"image": "homeassistant/{arch}-addon-google_assistant"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ CRED_JSON=/data/cred.json
|
|||||||
CLIENT_SECRETS=$(bashio::config 'client_secrets')
|
CLIENT_SECRETS=$(bashio::config 'client_secrets')
|
||||||
MODEL_ID=$(bashio::config 'model_id')
|
MODEL_ID=$(bashio::config 'model_id')
|
||||||
PROJECT_ID=$(bashio::config 'project_id')
|
PROJECT_ID=$(bashio::config 'project_id')
|
||||||
|
FEEDBACK=$(bashio::config 'feedback')
|
||||||
|
|
||||||
# check if a new assistant file exists
|
# check if a new assistant file exists
|
||||||
if bashio::fs.file_exists "/share/${CLIENT_SECRETS}"; then
|
if bashio::fs.file_exists "/share/${CLIENT_SECRETS}"; then
|
||||||
@@ -24,4 +25,4 @@ fi
|
|||||||
|
|
||||||
bashio::log.info "Starting Home Assistant GAssisant SDK..."
|
bashio::log.info "Starting Home Assistant GAssisant SDK..."
|
||||||
exec python3 /usr/bin/hassio_gassistant.py \
|
exec python3 /usr/bin/hassio_gassistant.py \
|
||||||
"${CRED_JSON}" "${PROJECT_ID}" "${MODEL_ID}"
|
"${CRED_JSON}" "${PROJECT_ID}" "${MODEL_ID}" "${FEEDBACK}"
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import json
|
||||||
import google.oauth2.credentials
|
import google.oauth2.credentials
|
||||||
|
|
||||||
from google.assistant.library import Assistant
|
from google.assistant.library import Assistant
|
||||||
@@ -11,11 +12,23 @@ from google.assistant.library.device_helpers import register_device
|
|||||||
|
|
||||||
DEVICE_CONFIG = "/data/device.json"
|
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):
|
def process_event(event):
|
||||||
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
|
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
|
||||||
|
play_sound("start_sound.wav")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
if event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
|
||||||
|
play_sound("end_sound.wav")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(event)
|
print(event)
|
||||||
except UnicodeEncodeError as err:
|
except UnicodeEncodeError as err:
|
||||||
@@ -29,8 +42,8 @@ if __name__ == '__main__':
|
|||||||
cred_json = Path(sys.argv[1])
|
cred_json = Path(sys.argv[1])
|
||||||
device_json = Path(DEVICE_CONFIG)
|
device_json = Path(DEVICE_CONFIG)
|
||||||
|
|
||||||
# open credentials
|
# Open credentials
|
||||||
print("OAth with Google")
|
print("OAuth with Google")
|
||||||
with cred_json.open('r') as data:
|
with cred_json.open('r') as data:
|
||||||
credentials = google.oauth2.credentials.Credentials(token=None, **json.load(data))
|
credentials = google.oauth2.credentials.Credentials(token=None, **json.load(data))
|
||||||
|
|
||||||
@@ -46,7 +59,7 @@ if __name__ == '__main__':
|
|||||||
device_model_id = sys.argv[3]
|
device_model_id = sys.argv[3]
|
||||||
last_device_id = None
|
last_device_id = None
|
||||||
|
|
||||||
# run assistant
|
# Run assistant
|
||||||
print("Run Google Assistant SDK")
|
print("Run Google Assistant SDK")
|
||||||
with Assistant(credentials, device_model_id) as assistant:
|
with Assistant(credentials, device_model_id) as assistant:
|
||||||
events = assistant.start()
|
events = assistant.start()
|
||||||
|
|||||||
BIN
google_assistant/rootfs/usr/share/sounds/end_sound.wav
Executable file
BIN
google_assistant/rootfs/usr/share/sounds/end_sound.wav
Executable file
Binary file not shown.
BIN
google_assistant/rootfs/usr/share/sounds/start_sound.wav
Executable file
BIN
google_assistant/rootfs/usr/share/sounds/start_sound.wav
Executable file
Binary file not shown.
Reference in New Issue
Block a user