AUDIO
Listen to this page
Chapters
Smart speaker — Raspberry Pi + ReSpeaker
speaker/ — an always-on LAN voice terminal for the holai core. It turns a
Raspberry Pi with a ReSpeaker 2-Mic HAT into a smart speaker: it listens for a
wake word locally, records the spoken command, sends it through the same
voice pipeline as the Flutter client (POST /voice), and plays back the
spoken answer. No cloud, no extra accounts — the whole conversation stays
inside the home LAN.
How it works
The bridge is a single Python process running this loop:
| State | LEDs | What happens |
|---|---|---|
| Idle | off (dim) | the mic stream feeds the openWakeWord model |
| Wake detected | blue | the confirmation cue plays — a short guard drops its tail so it cannot end the capture early — then recording starts |
| Recording | blue | energy-based VAD ends the capture after silence (silence_ms) or at max_ms; a pause right after a SHORT speech burst (the wake-word tail, a false onset) does not end it — the real command may follow after a breath (max_gap_ms) |
| Dictating | violet | long dictation — DATA, not a command: wav segments upload in the background while you keep talking; the wake word ends it |
| Thinking | amber | the wav goes to POST /voice (multipart audio field, Bearer JWT) |
| Speaking | green | the reply plays: audioId from the response is fetched via GET /audio/:id and played on the HAT's line-out |
| Follow-up window | dim green | for followup.window_ms (default 10 s) any speech starts a new command without the wake word — a natural conversation; for followup.echo_ms right after a played answer the onsets are ignored, so the reply's reverb cannot start a phantom capture |
| Error | red | network / auth / STT-TTS failure — the state clears after a few seconds and the loop returns to idle |
Volume by voice. Volume commands never reach the core: the bridge matches
them on the returned transcript and adjusts its own ALSA mixer directly, then
confirms the new level through the core's /tts. "louder" / "quieter" step ±10 percentage points from the CURRENT level (capped
at 100 / 0), "max volume" / "min volume" jump to the edges, and an absolute
percent sets the level exactly: "volume 30" — bare or with "to", values above 100 clamp to 100.
Dictation mode. Say the wake word and then "dictation" (add "to my document" or "to a note" for the
docs/obsidian targets): the LED turns violet and the speaker records for
MINUTES or HOURS — this is data (a voice message / document text), not an
AI command. The recording streams to the core in ~dictation.chunk_seconds
wav segments that upload while you keep talking (the server transcribes
each segment right away); nothing is played back and no VAD cuts you off.
Say the wake word again to END the dictation: the last partial segment
goes out as the final chunk, the core delivers the transcript — a feed
card with the full recording, an appended Google Doc or an appended
Obsidian note — and the speaker plays the spoken confirmation. The core
auto-finalizes at a 2-hour cap.
Both the command and the answer are plain POST /voice semantics: multipart
audio (wav 16 kHz mono PCM) in, JSON + audioId out. There is no speaker-
specific server code — the bridge is exactly another voice client, so every
pipeline feature (language commands, dynamic provider commands, tools, second
chance) works from the speaker automatically.
Hardware & system requirements
- Raspberry Pi (Zero 2 W / 3 / 4 / 5 — Pi Zero 2 W is enough; openWakeWord is the heaviest part)
- ReSpeaker 2-Mic HAT (SEEED, wm8960 codec) — mic array and line-out for the reply audio; its 3 onboard APA102 LEDs are used for status
- Speakers or headphones plugged into the HAT's 3.5 mm jack
- SPI enabled on the Pi (
dtparam=spi=on), the Seeed wm8960 driver installed (see Getting started on the HAT) - A holai core reachable on the LAN (default port
:8080)
Auth
Create a dedicated user for the speaker in the admin dashboard (e.g.
username speaker, role user — the speaker needs no admin rights) and put
the credentials into config.yaml. The bridge logs in with POST /auth/login
and transparently re-logs-in on a 401, so token expiry never needs manual
action.
Configuration
Copy speaker/config.example.yaml to speaker/config.yaml and edit:
| Key | Default | Meaning |
|---|---|---|
core.url |
http://holai.local:8080 |
the core's base URL (LAN) |
core.username / core.password |
— | the dedicated speaker user |
audio.mic_device |
plughw:CARD=aic3104soundcar,DEV=0 |
ALSA capture device (see arecord -l; install.sh auto-detects and repairs it) |
audio.play_device |
default |
ALSA playback device for replies |
audio.channels |
2 |
the HAT captures stereo; channels are downmixed to mono |
audio.sample_rate |
16000 |
fixed 16 kHz (pipeline contract) |
audio.cue |
true |
short two-tone beep after the wake word so you know recording started |
audio.debug_dump |
false |
save every command to /tmp/holai-last-command.wav for quality inspection |
wake.model |
hey_jarvis |
openWakeWord model — a bundled name, a path, or a bare filename of a custom .onnx/.tflite placed next to config.yaml (an explicit .tflite needs tflite-runtime, unavailable on Python ≥ 3.13) |
wake.threshold |
0.5 |
detection score at which the wake word fires |
record.silence_ms |
900 |
trailing silence that ends a command |
record.min_ms |
400 |
shorter captures are discarded (bumps / clicks) |
record.max_ms |
12000 |
hard cap for one command |
record.energy_threshold |
600 |
RMS above this counts as speech (raise it near a TV) |
record.min_level |
600 |
captures whose average RMS is lower are dropped before STT (they only produce whisper hallucinations) |
record.min_speech_ms |
1000 |
speech shorter than this is a wake-word tail / false onset — the first silence after it does NOT end the capture, the command may follow after a pause |
record.max_gap_ms |
2500 |
give-up gap after a short speech burst: nothing followed, so the capture is discarded (a lone wake word is never sent as a question) |
record.no_speech_ms |
2500 |
give-up limit for a capture with no counted speech at all |
followup.window_ms |
10000 |
how long after an answer the next speech skips the wake word (0 = off) |
followup.energy_threshold |
800 |
separate (higher) speech onset threshold inside the follow-up window |
followup.echo_ms |
500 |
right after a played answer the follow-up window ignores speech onsets for this long (reverb guard) |
dictation.chunk_seconds |
120 |
segment length uploaded during a long dictation (see Dictation mode above) |
alarms.enabled |
true |
the alarm watcher polls the core for dangerous events (priority rules in the dashboard) and SPEAKS every ALARM-priority event the moment it is published |
alarms.poll_seconds |
5 |
how often the watcher polls GET /events/alarms (it is a plain REST poller — no websocket kept open) |
speaker.name |
(empty) | this device's own name — a targeted alarm/timer ("timer in the kitchen") announces ONLY on the matching speaker; empty = this device plays broadcast events (danger alarms + untargeted alarms/timers). The name is also the default playback target for voice play commands ("play some jazz" said here plays here) |
leds.enabled |
true |
APA102 status feedback (auto-disables if SPI is unavailable) |
leds.spi_bus / leds.spi_dev |
0 / 1 |
the 2-Mic HAT exposes its LEDs on /dev/spidev0.1 (0.0 is taken by the codec) |
leds.count / leds.brightness |
3 / 31 |
LED count (0–31 brightness scale) |
Every key is optional except core.url + credentials — sensible defaults
cover the stock 2-Mic HAT setup.
Alarms
The core tags every published event with a priority — rules are defined
manually in the dashboard (events only happen in the future):
moderate = a notification on the phones, alarm = immediate reaction.
The bridge runs a small watcher thread (requests-only polling, no extra
dependencies): every alarms.poll_seconds it reads GET /events/alarms?since=…
and, for each alarm event, synthesizes "Alarm! POST /tts and plays it on the line-out immediately. Orbit alarms and
timers set by voice carry a speaker target and a speak flag: they are
spoken WITHOUT the "Alarm! " prefix and only on the matching device
(substring match against speaker.name); untargeted ones play on every
speaker. The phones get the push either way. If the TTS service
is down the announcement is skipped with a log line (the phones still get
their notification). Note: a spoken alarm can be picked up by the bridge's
own microphone if it lands inside a follow-up window; the recorder's
min-speech guards make that harmless (a lone announcement is never a valid
command — it contains no wake word and the LLM just answers once).
Consent (AI permissions)
The core's AI permission gate (architecture "AI permissions &
consent") pauses an actuating tool call or an external provider call until
the user answers. On the phones the answer is a dialog; the speaker asks
aloud instead: a watcher thread (consent.py) polls GET /consent/pending
every consent.poll_seconds and, for each request, speaks "Permission
request. May I use POST /tts, captures
consent.answer_seconds of audio from the shared mic stream and posts it
to POST /stt for parsing. A clear yes answers POST /consent/respond
with allow (one-time — "always allow" belongs to the app dialog); an
unclear answer, no answer or any failure is a deny — consent is never
guessed. Requests for the speaker user arise only while the main thread
waits inside POST /voice, so the mic is free and no capture contention
occurs; a spoken question landing in the mic is handled by the same
guards as the alarm announcements (see above). If the core is older than
the consent endpoints the watcher simply idles (it logs the 404 once).
| key | default | what |
|---|---|---|
consent.enabled |
true |
AI permission requests are spoken and answered with a yes/no capture |
consent.poll_seconds |
2 |
how often the watcher polls the core for open permission requests |
consent.answer_seconds |
5 |
how long the mic listens for the yes/no answer |
LED states
| State | Color |
|---|---|
| idle | dim white (barely visible heartbeat) |
| wake / recording | blue |
| dictating | violet |
| thinking | amber |
| speaking | green |
| follow-up window | dim green |
| error | red |
Installation
On the Pi, copy the repo's speaker/ folder over and run ONE script:
cd speaker
bash install.sh
install.sh performs the whole setup and is idempotent — re-run it whenever
it says so or after a bridge update:
- installs apt dependencies and adds the bus params to
/boot/firmware/config.txt(dtparam=spi=onfor the LEDs,dtparam=i2c_arm=onfor the codec — the codec must answer at I²C address0x1a, check withi2cdetect -y 1), - when
arecord -lshows no capture card, brings one up live — first the STOCKwm8960-soundcardoverlay shipped by the RPi kernel, then (clone boards answer at a different I²C address, e.g.0x18instead of0x1a) a minimal overlay bound to the detected address, trying the known codec families (wm8960, TLV320AIC3104) and persisted intoconfig.txt; only as a last resort the Seeed out-of-tree driver (respeaker/seeed-voicecard, tarball download — no GitHub account needed;install_arm64.shon a 64-bit OS). No reboot is needed; one is only requested as a fallback when the card still does not appear; once the card is up, install.sh also enables the codec's capture/output mixer paths and stores them withalsactl store— they reset on every reboot otherwise), - creates the python venv with all bridge dependencies (openWakeWord runs on onnxruntime — see troubleshooting below) and prefetches the wake word models,
- generates a first-run
config.yamlwith the detected mic card and LED SPI device pre-filled (existingconfig.yamlis never modified — except that amic_devicenaming an ALSA device that does not exist, e.g. a leftover placeholder or a stale card id, is auto-repaired to the detected card and the service restarted), - registers the
holai-speakersystemd service.
Then:
nano config.yaml # core.url + the speaker user's credentials
sudo systemctl enable --now holai-speaker
journalctl -u holai-speaker -f
A config.yaml still carrying the default password keeps the service
disabled on purpose.
Manual run (no systemd):
cd speaker
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python -m holai_speaker --config config.yaml
Logs go to the journal (journalctl -u holai-speaker -f) or stdout; every
exchange also appears in the core's audit log and the phone client's
conversation feed (speaker user), exactly like any other voice client.
Troubleshooting
POST /voicereturns 502 with a service URL — the STT/TTS containers are unreachable from the core; this is expected degradation, see getting-started.- No capture device —
arecord -llists zero cards: the Seeed driver is missing (installrespeaker/seeed-voicecard, see installation) ordtparam=i2c_arm=onis not set. A card exists butarecordcomplains "Unknown PCM": setaudio.mic_deviceto the card's real name, e.g.plughw:CARD=wm8960soundcard,DEV=0— the bridge logs the card list on this error. - Mic records silence after a reboot — the codec's mixer paths (input
switches, gain, HPF) reset to defaults on every boot; install.sh enables
and stores them (
alsactl store) — rerun it, or set them manually andsudo alsactl storeagain. - Wake word never fires — the bridge logs
wake scores peak …every 3 s; setwake.thresholdjust under the peaks your phrase produces (raise it if it fires without you speaking). - LEDs never light — check
/dev/spidev0.1exists (SPI enabled) and the user is in thespi+gpiogroups (sudo usermod -aG spi,gpio <user>); without LEDs the bridge keeps running (they auto-disable). - Follow-up fires on TV noise — raise
record.energy_thresholdandfollowup.energy_threshold, or setfollowup.window_ms: 0. capture discarded (…)right after the beep — the log names the reason:no speech within 2.0 smeans you started speaking later than the bridge waits after the cue (speak right after the beep);too shortmeans only a bump or click was caught. The cue's tail and room echo are dropped by a short guard, so they can no longer end the capture before you speak.- Wake word fires constantly / never — tune
wake.threshold(raise/lower in small steps); a custom keyword model can be trained with openWakeWord's tooling and referenced by path inwake.model. tflite-runtimehas no installable version ("No matching distribution found") — openWakeWord's default backend ships no wheels for Python ≥ 3.13 (Raspberry Pi OS Trixie);install.shinstalls openWakeWord without its pinned dependencies and the bridge automatically runs it on onnxruntime with the.onnxvariant of the model — no action needed.- Reply plays with wrong volume only on the speaker —
alsamixeron the Pi (cardwm8960soundcard) controls the output gain; the bridge does not touch it.
Files
speaker/
├── config.example.yaml # configuration template (copy to config.yaml)
├── install.sh # one-script setup: buses + Seeed driver + deps + config + systemd
├── holai-speaker.service # systemd unit template
├── fix-codec-card.sh # one-shot overlay rescue for the TLV320AIC3104 (v2.0) boards
├── requirements.txt
├── README.md # short pointer to this page
└── holai_speaker/
├── __main__.py # entry point + main state loop
├── config.py # config loading + defaults
├── core.py # core HTTP client (login, /voice, /audio)
├── audio.py # arecord stream, VAD, wav packing, playback
├── wake.py # openWakeWord wrapper (lazy import)
├── leds.py # APA102 status feedback (graceful degradation)
└── volume.py # local voice volume control (mixer on this device)
Last updated: November 2026