From d8bbc59e959229c670de3b98206d43ba53ba12fe Mon Sep 17 00:00:00 2001 From: Tod Schmidt Date: Sat, 29 Dec 2018 06:58:12 -0500 Subject: [PATCH] 0.60.8 (#494) * 0.58.2 * 0.58.2 * rebase * rebase * 0.58.3 * 0.58.3 * cleanup * Updated to 0.60.8; Containers built from base images * update snips-entrypoint and build images * Removed asr-injection (not available) * Updated CHANGELOG with correct version; Updated to use BUILD_ARCH * Optimize size of container * Cleanup & standardize * Update Dockerfile --- snips/CHANGELOG.md | 4 + snips/Dockerfile | 23 ++- snips/build.json | 4 +- snips/config.json | 2 +- snips/run.sh | 10 +- snips/snips-entrypoint.sh | 406 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 438 insertions(+), 11 deletions(-) create mode 100755 snips/snips-entrypoint.sh diff --git a/snips/CHANGELOG.md b/snips/CHANGELOG.md index fd7eb03..c15654d 100644 --- a/snips/CHANGELOG.md +++ b/snips/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 5.1 +- Updated to snips 0.60.8 +- Containers built from base images + ## 5.0 - Updated to snips 0.60.1 diff --git a/snips/Dockerfile b/snips/Dockerfile index 35bfbc2..c99ef0f 100644 --- a/snips/Dockerfile +++ b/snips/Dockerfile @@ -5,12 +5,27 @@ FROM $BUILD_FROM COPY run.sh / COPY mosquitto.conf /etc/ COPY customtts.sh /usr/bin +COPY snips-entrypoint.sh / -RUN chmod a+x /run.sh \ +ARG BUILD_ARCH + +RUN apt-get update \ + && apt-get install -y dirmngr apt-utils apt-transport-https jq unzip supervisor mpg123 curl tzdata \ + && rm -rf /var/lib/apt/lists/* \ + && if [ "$BUILD_ARCH" = "amd64" ]; \ + then \ + bash -c 'echo "deb https://debian.snips.ai/stretch stable main" > /etc/apt/sources.list.d/snips.list' \ + && apt-key adv --keyserver pgp.surfnet.nl --recv-keys F727C778CCB0A455; \ + else \ + bash -c 'echo "deb https://raspbian.snips.ai/stretch stable main" > /etc/apt/sources.list.d/snips.list' \ + && apt-key adv --keyserver pgp.surfnet.nl --recv-keys D4F50CDCA10A2849; \ + fi + +RUN apt-get update \ + && apt-get install -y snips-platform-voice snips-asr snips-watch \ + && chmod a+x /run.sh \ && chmod a+x /usr/bin/customtts.sh \ - && apt-get update \ - && apt-get install -y mpg123 curl tzdata \ - && apt-get install -y snips-asr-injection || true \ + && chmod a+x /snips-entrypoint.sh \ && rm -rf /var/lib/apt/lists/* \ && curl -L -o /assistant_Hass_de.zip https://s3.amazonaws.com/hassio-addons-data/assistant_Hass_de.zip \ && curl -L -o /assistant_Hass_en.zip https://s3.amazonaws.com/hassio-addons-data/assistant_Hass_en.zip \ diff --git a/snips/build.json b/snips/build.json index e6b1e9f..d9bc8b7 100644 --- a/snips/build.json +++ b/snips/build.json @@ -1,6 +1,6 @@ { "build_from": { - "armhf": "tschmidty/armhf-addon-snips:5", - "amd64": "tschmidty/amd64-addon-snips:5" + "armhf": "raspbian/stretch", + "amd64": "homeassistant/amd64-base-ubuntu:16.04" } } diff --git a/snips/config.json b/snips/config.json index 94bcb6b..c659a4b 100644 --- a/snips/config.json +++ b/snips/config.json @@ -1,6 +1,6 @@ { "name": "Snips.AI", - "version": "5.0", + "version": "5.1", "slug": "snips", "description": "Local voice control platform", "url": "https://home-assistant.io/addons/snips/", diff --git a/snips/run.sh b/snips/run.sh index e128fb9..7dda038 100644 --- a/snips/run.sh +++ b/snips/run.sh @@ -66,7 +66,6 @@ if MQTT_CONFIG="$(curl -s -f -H "X-Hassio-Key: ${HASSIO_TOKEN}" http://hassio/se ) >> /etc/mosquitto.conf else echo "[ERROR] No Hass.io mqtt service found!" - exit 1 fi echo "[INFO] Start internal mqtt broker" @@ -94,7 +93,10 @@ fi echo "[INFO] Starting snips-watch" ( sleep 2; /usr/bin/snips-watch -vvv --no_color ) & -echo "[INFO] Starting snips-asr-injection" -( sleep 2; /usr/bin/snips-asr-injection -v --no_color ) & +/usr/bin/snips-asr --version +/usr/bin/snips-audio-server --version +/usr/bin/snips-dialogue --version +/usr/bin/snips-hotword --version +/usr/bin/snips-nlu --version -/opt/snips/snips-entrypoint.sh --mqtt localhost:1883 +/snips-entrypoint.sh --mqtt localhost:1883 diff --git a/snips/snips-entrypoint.sh b/snips/snips-entrypoint.sh new file mode 100755 index 0000000..da4a9f7 --- /dev/null +++ b/snips/snips-entrypoint.sh @@ -0,0 +1,406 @@ +#!/bin/bash +# Execute cli if requested +if [ "$1" = "snips" ] +then + shift + exec snips "$@" +fi + + +ASSISTANT_FILE=/usr/share/snips/assistant/assistant.json +if [ ! -f "$ASSISTANT_FILE" ] +then + echo "Couldn't find any assistant" + exit 1 +fi + +SUPERVISORD_CONF_FILE="/etc/supervisor/conf.d/supervisord.conf" +ASR_TYPE=$(jq --raw-output '.asr.type' $ASSISTANT_FILE) +ANALYTICS_ENABLED=$(jq --raw-output '.analyticsEnabled' $ASSISTANT_FILE) +SNIPS_MOSQUITTO_FLAG="-h localhost -p 1883" + + +if [ -z "$SNIPS_AUDIO_SERVER_MQTT_ARGS" ] +then + SNIPS_AUDIO_SERVER_MQTT_ARGS="--frame=256" +fi + +if [ -d "/opt/snips/asr" ] +then + SNIPS_ASR_MODEL="" +else + SNIPS_ASR_MODEL="" +fi +if [ -z "$SNIPS_ASR_ARGS" ] +then + SNIPS_ASR_ARGS="$SNIPS_ASR_MODEL --beam_size=8" +fi + +if [ -z "$SNIPS_ASR_MQTT_ARGS" ] +then + SNIPS_ASR_MQTT_ARGS="" +fi + +if [ -z "$SNIPS_DIALOGUE_MQTT_ARGS" ] +then + SNIPS_DIALOGUE_MQTT_ARGS="" +fi + +if [ -z "$SNIPS_ASR_GOOGLE_MQTT_ARGS" ] +then + SNIPS_ASR_GOOGLE_MQTT_ARGS="" +fi + +if [ -z "$SNIPS_HOTWORD_ARGS" ] +then + SNIPS_HOTWORD_ARGS="" +fi +if [ -z "$SNIPS_HOTWORD_MQTT_ARGS" ] +then + SNIPS_HOTWORD_MQTT_ARGS="" +fi + +if [ -z "$SNIPS_ANALYTICS_MQTT_ARGS" ] +then + SNIPS_ANALYTICS_MQTT_ARGS="" +fi + +if [ -z "$SNIPS_QUERIES_MQTT_ARGS" ] +then + SNIPS_QUERIES_MQTT_ARGS="" +fi + + +# Read "global" arguments +USE_INTERNAL_MQTT=true +ALL_SNIPS_COMPONENTS=("snips-asr-google" "snips-asr" "snips-audio-server" "snips-tts" "snips-hotword" "snips-nlu" "snips-dialogue" "snips-analytics" "snips-debug") +declare -A SNIPS_COMPONENTS +for c in "${ALL_SNIPS_COMPONENTS[@]}" +do + SNIPS_COMPONENTS[$c]=true +done + +if [ "$ASR_TYPE" != "google" ] +then + SNIPS_COMPONENTS["snips-asr-google"]=false +elif [ "$ASR_TYPE" != "snips" ] +then + SNIPS_COMPONENTS["snips-asr"]=false +fi + +if [ "$ANALYTICS_ENABLED" != "true" ] +then + SNIPS_COMPONENTS["snips-analytics"]=false +fi + + +for i in $(seq 1 $#) +do + j=$((i+1)) + TYPE_ARG="${!i}" + VALUE_ARG="${!j}" + if [[ "$TYPE_ARG" = "--verbose" || "$TYPE_ARG" = "-v" ]] + then + SNIPS_DEBUG=true + fi +done + +if [ "${SNIPS_DEBUG}" == true ] +then + echo "Execution env:" + env + LOGLEVEL="-v" + SNIPS_COMPONENTS["snips-debug"]=true +else + LOGLEVEL="" + SNIPS_COMPONENTS["snips-debug"]=false +fi + +USE_INCLUDE=false +USE_EXCLUDE=false + +for i in $(seq 1 $#) +do + j=$((i+1)) + TYPE_ARG="${!i}" + VALUE_ARG="${!j}" + if [ "$TYPE_ARG" = "--exclude-components" ] + then + USE_EXCLUDE=true + if [ "$USE_INCLUDE" = true ] + then + echo "Cannot use --include-components and --exclude-components simultaneously" + exit 1 + fi + + for j in $(echo $VALUE_ARG|tr ',' ' ') + do + if [ -z ${SNIPS_COMPONENTS[$i]} ] + then + echo "Unknown snips component $j. Must be one of ${ALL_SNIPS_COMPONENTS[*]}." + exit 1 + fi + unset SNIPS_COMPONENTS["$i"] + done + elif [ "$TYPE_ARG" = "--include-components" ] + then + USE_INCLUDE=true + if [ "$USE_EXCLUDE" = true ] + then + echo "Cannot use --include-components and --exclude-components simultaneously" + exit 1 + elif [ -z "$VALUE_ARG" ] + then + echo "--include-components must be followed by a command-line list of components to include ${ALL_SNIPS_COMPONENTS[*]}" + exit 1 + fi + + for c in "${ALL_SNIPS_COMPONENTS[@]}" + do + SNIPS_COMPONENTS[$c]=false + done + for j in $(echo $VALUE_ARG|tr ',' ' ') + do + if [[ -z "${SNIPS_COMPONENTS[$i]}" && $j != "none" ]] + then + echo "Unknown snips component $j. Must be one of ${ALL_SNIPS_COMPONENTS[*]}." + exit 1 + fi + SNIPS_COMPONENTS["$i"]=true + done + elif [ "$TYPE_ARG" = "--mqtt" ] + then + if [ -z "$VALUE_ARG" ] + then + echo "':' must be specified when using --mqtt" + exit 1 + elif [ "$(echo "$VALUE_ARG" | tr -cd ':' | wc -c)" != 1 ] + then + echo "--mqtt value must follow the pattern ':' with server and port separated by a single ':'" + exit 1 + elif [ "$(echo "$VALUE_ARG" | tr -cd '#' | wc -c)" != 0 ] + then + echo "--mqtt value must follow the pattern ':'. '#' character is not allowed." + exit 1 + fi + + SNIPS_MQTT_HOST=$(echo "$VALUE_ARG"| cut -d : -f 1) + if [ -z "$SNIPS_MQTT_HOST" ] + then + echo "Must specify a server when using --mqtt" + exit 1 + fi + + SNIPS_MQTT_PORT=$(echo "$VALUE_ARG"| cut -d : -f 2) + case "$SNIPS_MQTT_PORT" in + ''|*[!0-9]*) + echo "Must specify a numeric value for port when using --mqtt" + exit 1 ;; + *) ;; + esac + + USE_INTERNAL_MQTT=false + SNIPS_MQTT_FLAG="--mqtt '$SNIPS_MQTT_HOST:$SNIPS_MQTT_PORT'" + SNIPS_MOSQUITTO_FLAG="-h $SNIPS_MQTT_HOST -p $SNIPS_MQTT_PORT" + fi +done + +# Generate global configuration +cat < $SUPERVISORD_CONF_FILE +[supervisord] +nodaemon=true + +EOT + + +# Generate snips-asr-google +if [ "${SNIPS_COMPONENTS['snips-asr-google']}" = true ] +then + echo "Spawning /usr/bin/snips-asr-google $LOGLEVEL $SNIPS_ASR_GOOGLE_ARGS $SNIPS_MQTT_FLAG $SNIPS_ASR_GOOGLE_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE + +[program:snips-asr-google] +command=/usr/bin/snips-asr-google $LOGLEVEL $SNIPS_ASR_GOOGLE_ARGS $SNIPS_MQTT_FLAG $SNIPS_ASR_GOOGLE_MQTT_ARGS +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-asr-google is disabled" +fi + + +# Generate snips-asr +if [ "${SNIPS_COMPONENTS['snips-asr']}" = true ] +then + echo "Spawning /usr/bin/snips-asr $LOGLEVEL $SNIPS_ASR_ARGS $SNIPS_MQTT_FLAG $SNIPS_ASR_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE + +[program:snips-asr] +command=/usr/bin/snips-asr $LOGLEVEL $SNIPS_ASR_ARGS $SNIPS_MQTT_FLAG $SNIPS_ASR_MQTT_ARGS +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-asr is disabled" +fi + + +# Generate snips-audio-server +if [ "${SNIPS_COMPONENTS['snips-audio-server']}" = true ] +then + echo "Spawning /usr/bin/snips-audio-server $LOGLEVEL $SNIPS_AUDIO_SERVER_ARGS $SNIPS_MQTT_FLAG $SNIPS_AUDIO_SERVER_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE + +[program:snips-audio-server] +command=/usr/bin/snips-audio-server $LOGLEVEL $SNIPS_AUDIO_SERVER_ARGS $SNIPS_MQTT_FLAG $SNIPS_AUDIO_SERVER_MQTT_ARGS +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-audio-server is disabled" +fi + + +# Generate snips-tts +if [ "${SNIPS_COMPONENTS['snips-tts']}" = true ] +then + echo "Spawning /usr/bin/snips-tts $LOGLEVEL $SNIPS_TTS_ARGS $SNIPS_MQTT_FLAG $SNIPS_TTS_MQTT_FLAG" + cat <> $SUPERVISORD_CONF_FILE +[program:snips-tts] +command=/usr/bin/snips-tts $LOGLEVEL $SNIPS_TTS_ARGS $SNIPS_MQTT_FLAG $SNIPS_TTS_MQTT_FLAG +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-tts is disabled" +fi + + +# Generate snips-hotword +if [ "${SNIPS_COMPONENTS['snips-hotword']}" = true ] +then + echo "Spawning /usr/bin/snips-hotword $SNIPS_HOTWORD_ARGS $LOGLEVEL $SNIPS_MQTT_FLAG $SNIPS_HOTWORD_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE +[program:snips-hotword] +command=/usr/bin/snips-hotword $SNIPS_HOTWORD_ARGS $LOGLEVEL $SNIPS_MQTT_FLAG $SNIPS_HOTWORD_MQTT_ARGS +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-hotword is disabled" +fi + + +# Generate snips-nlu +if [ "${SNIPS_COMPONENTS['snips-nlu']}" = true ] +then + echo "Spawning /usr/bin/snips-nlu $LOGLEVEL $SNIPS_MQTT_FLAG $SNIPS_QUERIES_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE +[program:snips-nlu] +command=/usr/bin/snips-nlu $LOGLEVEL $SNIPS_MQTT_FLAG $SNIPS_QUERIES_MQTT_ARGS +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-nlu is disabled" +fi + + +# Generate snips-dialogue +if [ "${SNIPS_COMPONENTS['snips-dialogue']}" = true ] +then + echo "Spawning /usr/bin/snips-dialogue $LOGLEVEL $SNIPS_DIALOGUE_ARGS $SNIPS_MQTT_FLAG $SNIPS_DIALOGUE_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE +[program:snips-dialogue] +command=/usr/bin/snips-dialogue $LOGLEVEL $SNIPS_DIALOGUE_ARGS $SNIPS_MQTT_FLAG $SNIPS_DIALOGUE_MQTT_ARGS +autorestart=true +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-dialogue is disabled" +fi + + +# Generate snips-analytics +if [ "${SNIPS_COMPONENTS['snips-analytics']}" = true ] +then + echo "Spawning /usr/bin/snips-analytics $LOGLEVEL $SNIPS_MQTT_FLAG $SNIPS_ANALYTICS_MQTT_ARGS" + cat <> $SUPERVISORD_CONF_FILE +[program:snips-analytics] +command=/usr/bin/snips-analytics $LOGLEVEL $SNIPS_MQTT_FLAG $SNIPS_ANALYTICS_MQTT_ARGS +autorestart=unexpected +directory=/root +environment=RUMQTT_READ_TIMEOUT_MS="50" +exitcodes=0 +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-analytics is disabled" +fi + + +# Generate snips-debug +if [ "${SNIPS_COMPONENTS['snips-debug']}" = true ] +then + echo Spawning snips-debug + cat <> $SUPERVISORD_CONF_FILE +[program:snips-debug] +command=mosquitto_sub -v $SNIPS_MOSQUITTO_FLAG -t "hermes/#" -T "hermes/audioServer/+/audioFrame" +autorestart=true +directory=/root +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +EOT +else + echo "snips-debug is disabled" +fi + + +if [ "${USE_INTERNAL_MQTT}" = true ] +then + service mosquitto start + sleep 2 +fi + +export RUMQTT_READ_TIMEOUT_MS=50 +/usr/bin/supervisord -c $SUPERVISORD_CONF_FILE