feat(speech): the speech capability over Cap'n Web, behind a gate
check / check (push) Canceled after 0s

The agent's ears and voice: a server on the home server transcribes
a clip (sox, whisper.cpp) and speaks text (piper), one job at a time.
A gate hands the capability to whoever presents its key; the key comes
from systemd's credentials, not argv.

make test runs the unit tests in Nix's sandbox; make smoke starts a
real server on localhost, speaks a phrase, and hears it back.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-02 15:46:58 -06:00
1 parent 4036bfc936
commit 66e084afc7
20 files changed
+621

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#!/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"