-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice
More file actions
executable file
·79 lines (75 loc) · 2.87 KB
/
Copy pathvoice
File metadata and controls
executable file
·79 lines (75 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# voice: poke the let-there-be-voice daemon from any terminal.
# usage: voice status | wake | doctor | chill | repeat | slower | faster | brief | normal | shutup | unshutup | say "text"
set -u
ROOT="$(cd "$(dirname "$0")" && pwd)"
PY="$ROOT/.venv/bin/python"
BASE="http://127.0.0.1:7333"
KILL="$ROOT/.voice-disabled"
daemon_up() {
curl -sf -m 1 "$BASE/health" >/dev/null 2>&1
}
start_daemon() {
nohup "$PY" "$ROOT/daemon.py" >/dev/null 2>&1 &
for _ in $(seq 1 40); do
daemon_up && return 0
sleep 0.25
done
return 1
}
ensure_daemon() {
daemon_up || start_daemon
}
case "${1:-}" in
status)
if OUT=$(curl -sf -m 2 "$BASE/health"); then
echo "$OUT" | "$PY" -m json.tool
else
echo "daemon: down"
fi
[ -f "$KILL" ] && echo "kill switch: ON (.voice-disabled present)" || echo "kill switch: off"
;;
wake)
ensure_daemon && echo "daemon: up" || { echo "daemon: failed to start"; exit 1; }
;;
doctor)
ensure_daemon || { echo "daemon: failed to start"; exit 1; }
curl -sf -m 3 "$BASE/doctor" | "$PY" -c '
import json, sys
d = json.load(sys.stdin)
for check in d.get("checks", []):
mark = "ok" if check.get("ok") else ("warn" if not check.get("required") else "FAIL")
print(f"{check.get('"'"'name'"'"', '"'"'check'"'"'):<20} {mark:<4} {check.get('"'"'detail'"'"', '"'"''"'"')}")
git = d.get("git") or {}
print(f"{'"'"'git'"'"':<20} info {git.get('"'"'branch'"'"', '"'"'?'"'"')}{'"'"' · dirty'"'"' if git.get('"'"'dirty'"'"') else '"'"''"'"'}")
print(f"{'"'"'overall'"'"':<20} {'"'"'ready'"'"' if d.get('"'"'ok'"'"') else '"'"'attention needed'"'"'}")
' || { echo "doctor: daemon did not respond"; exit 1; }
command -v uv >/dev/null 2>&1 && echo "uv ok installed" || echo "uv FAIL missing"
;;
chill|stop)
curl -sf -m 2 -X POST "$BASE/stop" -d '{}' >/dev/null && echo "chilled" || echo "daemon down, nothing to chill"
;;
repeat|slower|faster|brief|normal|recap)
curl -sf -m 2 -X POST "$BASE/backchannel" -d "{\"command\": \"$1\"}" \
| "$PY" -c 'import json,sys; d=json.load(sys.stdin); print(d.get("result", "backchannel failed"))' \
|| echo "daemon down, backchannel unavailable"
;;
shutup|mute)
touch "$KILL" && echo "shut up on (.voice-disabled created)"
;;
unshutup|unmute)
rm -f "$KILL" && echo "shut up off"
;;
say)
shift
[ $# -ge 1 ] || { echo "usage: voice say \"text\""; exit 1; }
PAYLOAD=$(printf '%s' "$*" | "$PY" -c 'import json,sys; print(json.dumps({"text": sys.stdin.read()}))')
ensure_daemon || { echo "daemon failed to start"; exit 1; }
curl -sf -m 2 -X POST "$BASE/speak" -d "$PAYLOAD" >/dev/null 2>&1 || { echo "queue failed"; exit 1; }
echo "queued"
;;
*)
echo "usage: voice status|wake|doctor|chill|repeat|slower|faster|brief|normal|recap|shutup|unshutup|say \"text\""
exit 1
;;
esac