hex/scripts/capture-dictation-fixtures.sh
Dax 3434eb5f35
Rename voice-control to hex everywhere, without migrations (#293)
* Rename voice-control to hex everywhere, without migrations

The Cargo package and binary are now hex, every OS keeps its data in a
hex folder, and VOICE_CONTROL_* variables are HEX_*. Hex is a fresh
app: the macOS voice-control rename, its symlink, and the Windows and
Linux beta settings imports are gone. The Windows installer gets a new
AppId so it never takes over an old voice-control install's entry.

* Format

* Drop the Windows paste-last default only the beta import used
2026-10-28 13:08:44 -04:00

97 lines
2.4 KiB
Shell
Executable file

#!/usr/bin/env bash
set -euo pipefail
support="$HOME/Library/Application Support/hex"
destination="${1:-$support/test-fixtures/dictation-protocol}"
recording_pid=""
names=(
period-stop
question-stop
exclamation-send
comma-stop
)
prompts=(
"Say, I don't understand this. Say stop."
"Say, is this working? Say stop."
"Say, ship it! Say send."
"Say, meet me at five, say stop."
)
cleanup() {
if [[ -n "$recording_pid" ]] && kill -0 "$recording_pid" 2>/dev/null; then
kill -INT "$recording_pid" 2>/dev/null || true
wait "$recording_pid" 2>/dev/null || true
fi
}
confirm() {
local prompt="$1"
local default="${2:-yes}"
local reply
if [[ "$default" == "yes" ]]; then
read -r -p "$prompt [Y/n] " reply
[[ ! "$reply" =~ ^[Nn]$ ]]
else
read -r -p "$prompt [y/N] " reply
[[ "$reply" =~ ^[Yy]$ ]]
fi
}
trap cleanup EXIT INT TERM
for command in rec play soxi; do
if ! command -v "$command" >/dev/null 2>&1; then
printf 'Missing %s. Install SoX before recording fixtures.\n' "$command" >&2
exit 1
fi
done
mkdir -p "$destination"
printf '\nHEX dictation protocol fixture recorder\n'
printf 'Audio stays local in:\n %s\n\n' "$destination"
printf 'Use a normal speaking pace. Leave a short pause before the final control.\n'
for index in "${!names[@]}"; do
name="${names[$index]}"
prompt="${prompts[$index]}"
output="$destination/$name.wav"
while true; do
printf '\n[%s/%s] %s\n' "$((index + 1))" "${#names[@]}" "$name"
printf 'Say exactly:\n %s\n' "$prompt"
read -r -p 'Press Enter to start recording. '
printf '\aRecording. Press Enter when you finish speaking.\n'
rm -f "$output"
rec -q -c 1 -r 16000 -e floating-point -b 32 "$output" &
recording_pid=$!
read -r
if kill -0 "$recording_pid" 2>/dev/null; then
kill -INT "$recording_pid" 2>/dev/null || true
fi
wait "$recording_pid" 2>/dev/null || true
recording_pid=""
if [[ ! -s "$output" ]]; then
printf 'Recording failed; no audio was written.\n' >&2
continue
fi
duration="$(soxi -D "$output")"
printf 'Recorded %s seconds.\n' "$duration"
if confirm 'Play it back?'; then
play -q "$output"
fi
if confirm 'Keep this recording?'; then
break
fi
done
done
printf '\nCaptured %s fixtures.\n' "${#names[@]}"
printf 'Run the fixture test with:\n\n'
printf ' HEX_DICTATION_FIXTURE_DIR=%q cargo test dictation_protocol_audio -- --ignored --nocapture\n' "$destination"