mirror of
https://github.com/justLV/onju-v2
synced 2026-04-21 15:47:55 +00:00
Implements Opus decoding on ESP32 for TTS playback, achieving 14-16x compression over raw PCM. This improves WiFi throughput margin from 2.2x to 30x+, enabling reliable operation throughout the home even with poor WiFi conditions. Key changes: - Add Opus decoder to ESP32 firmware with dedicated 32KB FreeRTOS task - Implement length-prefixed TCP framing for variable-bitrate Opus frames - Update header protocol: header[5] = compression type (0=PCM, 1=μ-law, 2=Opus) - Auto-detect USB port in flash and serial monitor scripts - Add test script with opuslib encoder supporting WAV/M4A/MP3 input - Document architecture and design rationale for μ-law/UDP (mic) vs Opus/TCP (speaker) Performance: - Compression: 640 bytes PCM → 35-50 bytes Opus per 20ms frame (14-16x) - Bandwidth: 256 kbps → 16 kbps (94% reduction) - WiFi margin: 2.2x → 30x+ throughput safety margin - CPU usage: ~10-20% during playback on ESP32-S3 - Quality: High-fidelity voice suitable for human listening 🤖 Generated with [Claude Code](https://claude.com/claude-code)
38 lines
904 B
Bash
38 lines
904 B
Bash
#!/bin/bash
|
|
# Run Opus test while monitoring serial output
|
|
|
|
ESP32_IP=${1:-192.168.68.95}
|
|
AUDIO_FILE=${2:-/Users/justin/Desktop/her_8s.m4a}
|
|
|
|
echo "Starting serial monitor in background..."
|
|
~/.local/share/mise/installs/python/3.12.12/bin/python3 -c "
|
|
import glob, serial, time
|
|
|
|
port = sorted(glob.glob('/dev/cu.usbmodem*'))[0]
|
|
ser = serial.Serial(port, 115200, timeout=0.1)
|
|
|
|
print('=== SERIAL OUTPUT ===')
|
|
while True:
|
|
try:
|
|
if ser.in_waiting:
|
|
line = ser.readline().decode('utf-8', errors='ignore').strip()
|
|
if line:
|
|
print(f'[ESP32] {line}')
|
|
except:
|
|
break
|
|
time.sleep(0.01)
|
|
" &
|
|
SERIAL_PID=$!
|
|
|
|
sleep 2
|
|
|
|
echo ""
|
|
echo "Running Opus test..."
|
|
~/.local/share/mise/installs/python/3.12.12/bin/python3 test_opus_tts.py "$ESP32_IP" "$AUDIO_FILE"
|
|
|
|
echo ""
|
|
echo "Waiting for remaining serial output..."
|
|
sleep 3
|
|
|
|
kill $SERIAL_PID 2>/dev/null
|
|
echo "Done"
|