diff --git a/snips/CHANGELOG.md b/snips/CHANGELOG.md index ced938c..c2d9c68 100644 --- a/snips/CHANGELOG.md +++ b/snips/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.0 +- Updated to snips version 0.55.2 +- Updated default assistant with additional languages +- Added custom tts which use HA TTS platforms + ## 2.0 - Use new Supervisor Audio backend - Update preinstalled assistant for Home-Assistant diff --git a/snips/Dockerfile b/snips/Dockerfile index 116aba2..790a381 100644 --- a/snips/Dockerfile +++ b/snips/Dockerfile @@ -4,8 +4,13 @@ FROM $BUILD_FROM # Copy data COPY run.sh / COPY mosquitto.conf /etc/ -COPY assistant.zip /assistant-default.zip +COPY customtts.sh /usr/bin +COPY assistant_* / -RUN chmod a+x /run.sh +RUN chmod a+x /run.sh \ + && chmod a+x /usr/bin/customtts.sh \ + && apt-get update \ + && apt-get install -y mpg123 \ + && apt-get clean all ENTRYPOINT [ "/run.sh" ] diff --git a/snips/assistant.zip b/snips/assistant.zip deleted file mode 100644 index a1ceb27..0000000 Binary files a/snips/assistant.zip and /dev/null differ diff --git a/snips/assistant_Hass_de.zip b/snips/assistant_Hass_de.zip new file mode 100755 index 0000000..e56c67c Binary files /dev/null and b/snips/assistant_Hass_de.zip differ diff --git a/snips/assistant_Hass_en.zip b/snips/assistant_Hass_en.zip new file mode 100755 index 0000000..1f412ba Binary files /dev/null and b/snips/assistant_Hass_en.zip differ diff --git a/snips/assistant_Hass_fr.zip b/snips/assistant_Hass_fr.zip new file mode 100755 index 0000000..fc812f9 Binary files /dev/null and b/snips/assistant_Hass_fr.zip differ diff --git a/snips/build.json b/snips/build.json index accdc96..e47624b 100644 --- a/snips/build.json +++ b/snips/build.json @@ -1,6 +1,6 @@ { "build_from": { - "armhf": "snipsdocker/platform:arm-0.53.17", - "amd64": "snipsdocker/platform:x86-0.53.17" + "armhf": "snipsdocker/platform:arm-0.55.2", + "amd64": "snipsdocker/platform:x86-0.55.2" } } diff --git a/snips/config.json b/snips/config.json index ef5e72a..16cb9be 100644 --- a/snips/config.json +++ b/snips/config.json @@ -1,6 +1,6 @@ { "name": "Snips.AI", - "version": "2.0", + "version": "3.0", "slug": "snips", "description": "Local voice control platform", "url": "https://home-assistant.io/addons/snips/", @@ -11,7 +11,9 @@ "1883/tcp": 9898 }, "map": ["share"], + "tmpfs": "size=10m", "audio": true, + "homeassistant_api": true, "options": { "mqtt_bridge": { "active": true, @@ -20,7 +22,12 @@ "user": "", "password": "" }, - "assistant": "assistant.zip" + "assistant": "assistant.zip", + "language": "en", + "custom_tts": { + "active": false, + "platform": "amazon_polly" + } }, "schema": { "mqtt_bridge": { @@ -30,7 +37,12 @@ "user": "str", "password": "str" }, - "assistant": "str" + "assistant": "str", + "language": "match((?:en|de|fr))", + "custom_tts": { + "active": "bool", + "platform": "string" + } }, "image": "homeassistant/{arch}-addon-snips" } diff --git a/snips/customtts.sh b/snips/customtts.sh new file mode 100644 index 0000000..3f69129 --- /dev/null +++ b/snips/customtts.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +#set -x +API_KEY=$HASSIO_TOKEN +PLATFORM=$1 +FILE=$2 +LANG=$3 +TEXT=$4 + +MESSAGE="\"{\\\"message\\\": \\\"$TEXT\\\", \\\"platform\\\": \\\"$PLATFORM\\\"}\"" +echo "$MESSAGE" + +RESPONSE=$(eval curl -s -H \"x-ha-access: "$API_KEY"\" -H \"Type: application/json\" http://hassio/homeassistant/api/tts_get_url -d "$MESSAGE") +if [ "$RESPONSE" = "" ]; then + exit 1 +fi +echo "$RESPONSE" + +URL=$(echo "$RESPONSE" | jq --raw-output '.url') +if [ "$URL" = "" ]; then + exit 1 +fi + +rm /tmpfs/temp.mp3 +curl -s -H "x-ha-access: $API_KEY" "$URL" -o /tmpfs/temp.mp3 +if [ -f /tmpfs/temp.mp3 ]; then + /usr/bin/mpg123 -w "$FILE" /tmpfs/temp.mp3 +fi +rm /tmpfs/temp.mp3 + diff --git a/snips/run.sh b/snips/run.sh index cae7365..144a87e 100644 --- a/snips/run.sh +++ b/snips/run.sh @@ -5,13 +5,30 @@ CONFIG_PATH=/data/options.json MQTT_BRIDGE=$(jq --raw-output '.mqtt_bridge.active' $CONFIG_PATH) ASSISTANT=$(jq --raw-output '.assistant' $CONFIG_PATH) +LANG=$(jq --raw-output '.language // "en"' $CONFIG_PATH) +CUSTOMTTS=$(jq --raw-output '.custom_tts.active' $CONFIG_PATH) +PLATFORM=$(jq --raw-output '.custom_tts.platform' $CONFIG_PATH) + +echo "[INFO] LANG: $LANG" echo "[INFO] Checking for /share/snips.toml" if [ -f "/share/snips.toml" ]; then - echo "[INFO] Installing /share/snips.toml" + echo "[INFO] - Installing /share/snips.toml" cp -v /share/snips.toml /etc/ fi +if [ "$CUSTOMTTS" == "true" ]; then + if [ -z "$PLATFORM" ]; then + echo "[ERROR] - platform must be set to use custom tts!" + else + echo "[INFO] - Using custom tts" + echo "provider = \"customtts\"" >> /etc/snips.toml + echo "customtts = { command = [\"/usr/bin/customtts.sh\", \"$PLATFORM\", \"%%OUTPUT_FILE%%\", \"$LANG\", \"%%TEXT%%\"] }" >> /etc/snips.toml + fi +else + echo "[INFO] - Using default tts (picotts)" +fi + # mqtt bridge if [ "$MQTT_BRIDGE" == "true" ]; then HOST=$(jq --raw-output '.mqtt_bridge.host' $CONFIG_PATH) @@ -40,6 +57,8 @@ if [ "$MQTT_BRIDGE" == "true" ]; then echo "topic hermes/asr/stopListening out" echo "topic hermes/asr/startListening out" echo "topic hermes/nlu/intentNotParsed out" + echo "topic hermes/audioServer/+/playBytes/# out" + echo "topic hermes/audioServer/+/playFinished out" echo "topic # IN hermes/" } >> /etc/mosquitto.conf fi @@ -52,11 +71,18 @@ echo "[INFO] Checking for updated $ASSISTANT in /share" # check if a new assistant file exists if [ -f "/share/$ASSISTANT" ]; then echo "[INFO] Install/Update snips assistant" + rm -rf /usr/share/snips/assistant unzip -o -u "/share/$ASSISTANT" -d /usr/share/snips -# otherwise use the default -elif [ -f "/assistant-default.zip" ]; then - echo "[INFO] Using default snips assistant" - unzip -o -u "/assistant-default.zip" -d /usr/share/snips +# otherwise use the default +else + echo "[INFO] Checking for /assistant_Hass_$LANG.zip" + if [ -f "/assistant_Hass_$LANG.zip" ]; then + echo "[INFO] - Using default assistant_Hass_$LANG.zip" + rm -rf /usr/share/snips/assistant + unzip -o -u "/assistant_Hass_$LANG.zip" -d /usr/share/snips + else + echo "[ERROR] Could not find assistant!" + fi fi echo "[INFO] Starting snips-watch"