diff --git a/snips/Dockerfile b/snips/Dockerfile new file mode 100644 index 0000000..592f228 --- /dev/null +++ b/snips/Dockerfile @@ -0,0 +1,11 @@ +#armhf:FROM snipsdocker/platform:arm-0.4.3 +#amd64:FROM snipsdocker/platform:x86-0.4.3 + +# Copy data +COPY run.sh / +COPY mosquitto.conf /etc/ +COPY asoundrc /root/.asoundrc + +RUN chmod a+x /run.sh + +ENTRYPOINT [ "/run.sh" ] diff --git a/snips/asoundrc b/snips/asoundrc new file mode 100644 index 0000000..21e0a3f --- /dev/null +++ b/snips/asoundrc @@ -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%%" + } +} diff --git a/snips/config.json b/snips/config.json new file mode 100644 index 0000000..215fb35 --- /dev/null +++ b/snips/config.json @@ -0,0 +1,40 @@ +{ + "name": "Snips.AI", + "version": "0.4.3", + "slug": "snips", + "description": "The first on-device voice platform", + "url": "https://home-assistant.io/addons/snips/", + "startup": "application", + "boot": "auto", + "arch": ["armhf", "amd64"], + "ports": { + "1883/tcp": 9898 + }, + "map": ["share"], + "devices": ["/dev/snd:/dev/snd:rwm"], + "options": { + "mqtt_bridge": { + "active": true, + "host": "172.17.0.1", + "port": 1883, + "user": "", + "password": "" + }, + "mic": "0,0", + "speaker": "1,0", + "assistant": "assistant.zip" + }, + "schema": { + "mqtt_bridge": { + "active": "bool", + "host": "str", + "port": "port", + "user": "str", + "password": "str" + }, + "mic": "str", + "speaker": "str", + "assistant": "str" + }, + "image": "homeassistant/{arch}-addon-snips" +} diff --git a/snips/mosquitto.conf b/snips/mosquitto.conf new file mode 100644 index 0000000..b37233d --- /dev/null +++ b/snips/mosquitto.conf @@ -0,0 +1,13 @@ +## +# defaults +listener 1883 +user root + +## +# logging +log_dest stdout + +## +# datastore +persistence true +persistence_location /data/ diff --git a/snips/run.sh b/snips/run.sh new file mode 100644 index 0000000..057f8bc --- /dev/null +++ b/snips/run.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -e + +CONFIG_PATH=/data/options.json +SNIPS_CONFIG=/data/config + +MQTT_BRIDGE=$(jq --raw-output '.mqtt_bridge.active' $CONFIG_PATH) +ASSISTANT=$(jq --raw-output '.assistant' $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 + +# mqtt bridge +if [ "$MQTT_BRIDGE" == "true" ]; then + HOST=$(jq --raw-output '.mqtt_bridge.host' $CONFIG_PATH) + PORT=$(jq --raw-output '.mqtt_bridge.port' $CONFIG_PATH) + USER=$(jq --raw-output '.mqtt_bridge.user' $CONFIG_PATH) + PASSWORD=$(jq --raw-output '.mqtt_bridge.password' $CONFIG_PATH) + + echo "[Info] Setup internal mqtt bridge" + + { + echo "connection main-mqtt" + echo "address $HOST:$PORT" + } >> /etc/mosquitto.conf + + if [ ! -z "$USER" ]; then + { + echo "username $USER" + echo "password $PASSWORD" + } >> /etc/mosquitto.conf + fi + + echo "topic # OUT" >> /etc/mosquitto.conf +fi + +echo "[Info] Start internal mqtt broaker" +mosquitto -c /etc/mosquitto.conf & + +# init snips config +mkdir -p "$SNIPS_CONFIG" +ln -s "$SNIPS_CONFIG/" "/opt/snips/config" + +# check if a new assistant file exists +if [ -f "/share/$ASSISTANT" ]; then + echo "[Info] Install/Update snips assistant" + unzip -u "/share/$ASSISTANT" -d "$SNIPS_CONFIG" +fi + +/opt/snips/snips-entrypoint.sh --mqtt localhost:1883