#!/bin/sh # smoke.sh BIN MODEL VOICE PORT PHRASE: a speech round trip, by way of a real server and clients. # Starts BIN/speech-server on localhost with a throwaway key, has it speak PHRASE # with piper's noise off, so the same words come out the same way every time, # then hear the WAV back, and compares the words, ignoring case and punctuation. set -eu bin=$1 model=$2 voice=$3 port=$4 phrase=$5 tmp=$(mktemp -d) pid= trap '[ -n "$pid" ] && kill "$pid" 2>/dev/null; rm -rf "$tmp"' EXIT umask 077 head -c 20 /dev/urandom | base32 > "$tmp/speech-key" export CREDENTIALS_DIRECTORY="$tmp" "$bin/speech-server" 127.0.0.1 "$port" "$model" "$voice" --noise-scale 0 --noise-w-scale 0 > "$tmp/server.log" 2>&1 & pid=$! tries=0 until grep -q listening "$tmp/server.log"; do tries=$((tries + 1)) [ "$tries" -le 50 ] || { cat "$tmp/server.log" >&2; exit 1; } sleep 0.2 done url=ws://127.0.0.1:$port/ printf '%s\n' "$phrase" | "$bin/speak-client" "$url" > "$tmp/said.wav" heard=$("$bin/hear-client" "$url" < "$tmp/said.wav") cat "$tmp/server.log" words() { printf '%s' "$1" | tr -cd 'A-Za-z' | tr A-Z a-z; } echo "said: $phrase" echo "heard: $heard" [ "$(words "$phrase")" = "$(words "$heard")" ] || { echo "smoke: they differ" >&2; exit 1; } echo "smoke: same words"