#! /bin/bash echo https://github.com/seasalt-ai/snowboy cd "$(dirname "$(realpath "$BASH_SOURCE")")" set -e set -o pipefail if [ ! -d ./snowboy.git.d ]; then git clone https://github.com/seasalt-ai/snowboy snowboy.git.d fi timeout 2 docker version &> /dev/null if ! docker images | grep snowboy-pmdl.*latest &> /dev/null; then pushd snowboy.git.d docker build -t snowboy-pmdl:latest . popd fi export HOTWORD="${HOTWORD:-${TRAIN:-default_hotword}}" if [ -n "$TRAIN" ] || [ ! -d ./model ] || [ ! -f ./model/$HOTWORD.pmdl ]; then mkdir -p model pushd model rm -f ./record{1,2,3}.wav || true echo "record 3 instances of '$HOTWORD'" >&2 for i in 1 2 3; do read -p "[$i/3] ready? you get 3 seconds." ( timeout 3 rec \ -r 16000 \ -c 1 \ -b 16 \ -e signed-integer \ -t wav \ record$i.wav ) || true ls record$i.wav done popd docker run \ --rm \ -it \ -v "$(realpath ./model)":/snowboy-master/examples/Python/model \ snowboy-pmdl:latest mv ./model/hotword.pmdl ./model/$HOTWORD.pmdl if [ -n "$TRAIN" ]; then exit 0 fi fi if false; then if ! which swig; then brew install swig fi pip3 install pyaudio pushd snowboy.git.d/swig/Python3/ make popd cd snowboy.git.d/examples/Python3/ echo ' import snowboydecoder import datetime detected_callback = lambda *args: print(datetime.datetime.now(), "GOTCHA") d = snowboydecoder.HotwordDetector("../../../model/'"$HOTWORD"'.pmdl", sensitivity=0.5, audio_gain=1) d.start(detected_callback) ' > breel.py echo GO cleanup() { echo OK IM DONE NOW } trap cleanup EXIT python3 ./breel.py else resources="$(realpath snowboy.git.d/resources/common.res)" hotword="$(realpath ./model/$HOTWORD.pmdl)" GOPROXY= go build -o snowboy if [ -z "$PUSH" ]; then ./snowboy \ -ms "$hotword/$HOTWORD" \ -r "$resources" \ -s 0.5 \ "$@" else echo ' FROM registry-app.eng.qops.net:5001/imported/alpine:3.16 WORKDIR /main/ COPY ./snowboy.git.d/resources/common.res ./ COPY ./model/hotword.pmdl ./ COPY ./snowboy ./ ENTRYPOINT ["sh", "-c", "true; echo copying /main/ to /mnt/; cp /main/* /mnt/"] CMD [] ' > Dockerfile docker build -t registry-app.eng.qops.net:5001/breel/snowboy:latest . docker push registry-app.eng.qops.net:5001/breel/snowboy:latest fi fi