-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice_chat.sh
More file actions
executable file
·80 lines (64 loc) · 2.36 KB
/
Copy pathvoice_chat.sh
File metadata and controls
executable file
·80 lines (64 loc) · 2.36 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
80
#!/bin/bash
# Voice Chat — Whisper STT → RRR Inference → Piper TTS
# Runs on GPD Pocket 4, uses built-in mic + speakers
WHISPER_MODEL="$HOME/tools/whisper/ggml-base.en.bin"
PIPER_MODEL="$HOME/tools/piper/en_GB-jenny_dioco-medium.onnx"
ENGINE_DIR="$HOME/projects/recursive-routing-racer-rs"
TMPDIR="/tmp/voice_chat"
mkdir -p "$TMPDIR"
# Colors
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${GREEN}=== RRR Voice Chat ===${NC}"
echo -e "${CYAN}Engine: Phi-4 3.8B | Vulkan | 6.6 tok/s${NC}"
echo -e "${CYAN}STT: Whisper base.en | TTS: Piper Jenny${NC}"
echo ""
echo -e "${YELLOW}Press ENTER to speak, ENTER again to stop recording.${NC}"
echo -e "${YELLOW}Type 'quit' to exit.${NC}"
echo ""
# Build engine if needed
cd "$ENGINE_DIR"
if [ ! -f target/release/rrr ]; then
echo "Building engine..."
source ~/.cargo/env
cargo build --release 2>/dev/null
fi
while true; do
# Wait for user to press enter
echo -e "${GREEN}[READY]${NC} Press ENTER to speak..."
read -r input
if [ "$input" = "quit" ]; then
echo "Goodbye!"
break
fi
# Record audio until enter is pressed again
echo -e "${CYAN}[LISTENING]${NC} Recording... press ENTER to stop"
pw-record --format s16 --rate 16000 --channels 1 "$TMPDIR/input.wav" &
RECORD_PID=$!
read -r
kill $RECORD_PID 2>/dev/null
wait $RECORD_PID 2>/dev/null
# Transcribe with Whisper
echo -e "${CYAN}[THINKING]${NC} Transcribing..."
TRANSCRIPT=$(whisper-cpp -m "$WHISPER_MODEL" -f "$TMPDIR/input.wav" --no-timestamps -t 4 2>/dev/null | grep -v '^\[' | tr -d '\n' | sed 's/^ *//')
if [ -z "$TRANSCRIPT" ]; then
echo -e "${YELLOW}[EMPTY]${NC} Didn't catch that, try again."
continue
fi
echo -e "${CYAN}[HEARD]${NC} \"$TRANSCRIPT\""
# Run inference
echo -e "${CYAN}[GENERATING]${NC}"
source ~/.cargo/env
RESPONSE=$(echo "$TRANSCRIPT" | timeout 120 cargo run --release 2>/dev/null | grep -v '^\[' | grep -v '^===' | grep -v '^$' | head -20)
if [ -z "$RESPONSE" ]; then
RESPONSE="I didn't generate a response. Try again."
fi
echo -e "${GREEN}[RESPONSE]${NC} $RESPONSE"
# Speak with Piper
echo -e "${CYAN}[SPEAKING]${NC}"
echo "$RESPONSE" | piper --model "$PIPER_MODEL" --output_file "$TMPDIR/response.wav" 2>/dev/null
pw-play "$TMPDIR/response.wav" 2>/dev/null
echo ""
done