mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
* 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
73 lines
2.2 KiB
Shell
Executable file
73 lines
2.2 KiB
Shell
Executable file
#!/bin/sh
|
|
set -eu
|
|
|
|
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
support="$HOME/Library/Application Support/hex"
|
|
discovery="$support/local-api.json"
|
|
model=${HEX_SMOKE_MODEL:-parakeet_unified_en}
|
|
audio="${TMPDIR:-/tmp}/hex-transcription-smoke.wav"
|
|
events="${TMPDIR:-/tmp}/hex-transcription-prepare.ndjson"
|
|
service_pid=
|
|
|
|
cleanup() {
|
|
if [ -n "$service_pid" ] && kill -0 "$service_pid" 2>/dev/null; then
|
|
kill -INT "$service_pid" 2>/dev/null || true
|
|
shutdown_attempts=100
|
|
while kill -0 "$service_pid" 2>/dev/null && [ "$shutdown_attempts" -gt 0 ]; do
|
|
shutdown_attempts=$((shutdown_attempts - 1))
|
|
sleep 0.05
|
|
done
|
|
if kill -0 "$service_pid" 2>/dev/null; then
|
|
kill -TERM "$service_pid" 2>/dev/null || true
|
|
sleep 0.1
|
|
fi
|
|
if kill -0 "$service_pid" 2>/dev/null; then
|
|
kill -KILL "$service_pid" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
if [ -n "$service_pid" ]; then
|
|
wait "$service_pid" 2>/dev/null || true
|
|
fi
|
|
rm -f "$audio" "$audio.aiff" "$events"
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
if [ -e "$discovery" ]; then
|
|
echo "Refusing to replace an existing local API discovery file: $discovery" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cargo build --manifest-path "$root/Cargo.toml"
|
|
"$root/target/debug/hex" service >/dev/null 2>&1 &
|
|
service_pid=$!
|
|
|
|
attempts=100
|
|
while [ ! -f "$discovery" ]; do
|
|
attempts=$((attempts - 1))
|
|
if [ "$attempts" -eq 0 ]; then
|
|
echo "Timed out waiting for local API discovery." >&2
|
|
exit 1
|
|
fi
|
|
sleep 0.05
|
|
done
|
|
port=$(jq -r .port "$discovery")
|
|
token=$(jq -r .token "$discovery")
|
|
|
|
curl --fail --silent --show-error --no-buffer \
|
|
-X POST \
|
|
-H "Authorization: Bearer $token" \
|
|
"http://127.0.0.1:$port/models/$model/prepare" > "$events"
|
|
grep -Fq '"type":"ok"' "$events"
|
|
|
|
/usr/bin/say "Hello from the local Hex transcription service." -o "$audio.aiff"
|
|
/usr/bin/afconvert -f WAVE -d LEI16@16000 "$audio.aiff" "$audio"
|
|
rm -f "$audio.aiff"
|
|
|
|
result=$(curl --fail --silent --show-error \
|
|
-X POST \
|
|
-H "Authorization: Bearer $token" \
|
|
-H "Content-Type: audio/wav" \
|
|
--data-binary "@$audio" \
|
|
"http://127.0.0.1:$port/transcriptions?model=$model&language=en")
|
|
printf '%s\n' "$result" | jq -e '.transcript | length > 0' >/dev/null
|
|
printf '%s\n' "$result" | jq .
|