mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 21:24:20 +01:00
20
google_assistant/Dockerfile
Normal file
20
google_assistant/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#armhf:FROM multiarch/debian-debootstrap:armhf-stretch
|
||||||
|
#amd64:FROM multiarch/debian-debootstrap:amd64-stretch
|
||||||
|
|
||||||
|
# Install packages
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y python3 python3-dev python3-pip \
|
||||||
|
python3-six python3-pyasn1 libportaudio2 \
|
||||||
|
&& pip3 install google-assistant-library google-auth \
|
||||||
|
&& apt-get remove -y --purge python3-pip python3-dev \
|
||||||
|
&& apt autoremove -y \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Copy data
|
||||||
|
COPY run.sh /
|
||||||
|
COPY hassio_gassistant.py /
|
||||||
|
COPY asoundrc /root/.asoundrc
|
||||||
|
|
||||||
|
RUN chmod a+x /run.sh
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/run.sh" ]
|
||||||
17
google_assistant/asoundrc
Normal file
17
google_assistant/asoundrc
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
pcm.!default {
|
||||||
|
type asym
|
||||||
|
capture.pcm "mic"
|
||||||
|
playback.pcm "speaker"
|
||||||
|
}
|
||||||
|
pcm.mic {
|
||||||
|
type plug
|
||||||
|
slave {
|
||||||
|
pcm "hw:%%MIC%%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pcm.speaker {
|
||||||
|
type plug
|
||||||
|
slave {
|
||||||
|
pcm "hw:%%SPEAKER%%"
|
||||||
|
}
|
||||||
|
}
|
||||||
23
google_assistant/config.json
Normal file
23
google_assistant/config.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "Google Assistant",
|
||||||
|
"version": "0.0.3",
|
||||||
|
"slug": "google_assistant",
|
||||||
|
"description": "A virtual personal assistant developed by Google",
|
||||||
|
"url": "https://home-assistant.io/addons/google_assistant/",
|
||||||
|
"startup": "application",
|
||||||
|
"boot": "auto",
|
||||||
|
"arch": ["armhf", "amd64"],
|
||||||
|
"map": ["share"],
|
||||||
|
"devices": ["/dev/snd:/dev/snd:rwm"],
|
||||||
|
"options": {
|
||||||
|
"mic": "0,0",
|
||||||
|
"speaker": "1,0",
|
||||||
|
"service_account": "service_account.json"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"mic": "str",
|
||||||
|
"speaker": "str",
|
||||||
|
"service_account": "str"
|
||||||
|
},
|
||||||
|
"image": "homeassistant/{arch}-addon-google_assistant"
|
||||||
|
}
|
||||||
26
google_assistant/hassio_gassistant.py
Normal file
26
google_assistant/hassio_gassistant.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
"""Hass.IO Google Assistant."""
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from google.assistant.library import Assistant
|
||||||
|
from google.assistant.library.event import EventType
|
||||||
|
|
||||||
|
from google.oauth2 import service_account
|
||||||
|
|
||||||
|
|
||||||
|
def process_event(event):
|
||||||
|
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
|
||||||
|
print()
|
||||||
|
|
||||||
|
print(event)
|
||||||
|
|
||||||
|
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and event.args and not event.args['with_follow_on_turn']):
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
credentials = service_account.Credentials.from_service_account_file(sys.argv[1])
|
||||||
|
scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/assistant-sdk-prototype'])
|
||||||
|
|
||||||
|
with Assistant(scoped_credentials) as assistant:
|
||||||
|
for event in assistant.start():
|
||||||
|
process_event(event)
|
||||||
24
google_assistant/run.sh
Normal file
24
google_assistant/run.sh
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CONFIG_PATH=/data/options.json
|
||||||
|
OAUTH_JSON=/data/auth.json
|
||||||
|
|
||||||
|
SERVICE_ACCOUNT=$(jq --raw-output '.service_account' $CONFIG_PATH)
|
||||||
|
SPEAKER=$(jq --raw-output '.speaker' $CONFIG_PATH)
|
||||||
|
MIC=$(jq --raw-output '.mic' $CONFIG_PATH)
|
||||||
|
|
||||||
|
echo "[Info] Show audio device"
|
||||||
|
aplay -l
|
||||||
|
|
||||||
|
echo "[Info] Setup audio device"
|
||||||
|
sed -i "s/%%SPEAKER%%/$SPEAKER/g" /root/.asoundrc
|
||||||
|
sed -i "s/%%MIC%%/$MIC/g" /root/.asoundrc
|
||||||
|
|
||||||
|
# check if a new assistant file exists
|
||||||
|
if [ -f "/share/$SERVICE_ACCOUNT" ]; then
|
||||||
|
echo "[Info] Install/Update service account key file"
|
||||||
|
cp -f "/share/$SERVICE_ACCOUNT" "$OAUTH_JSON"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec python3 /hassio_gassistant.py "$OAUTH_JSON" < /dev/null
|
||||||
Reference in New Issue
Block a user