aaa056b7 on main, November 2, 2026, with Lemonade 2026.44.1. Builds on read-aloud
(#6489).
GAIA can already speak a reply (read-aloud) and gaia talk can hold a spoken conversation in a
terminal, but neither app can listen. This plan adds two ways to talk to GAIA in both the Agent
UI and the TUI:
- Dictation. A microphone button in the composer. You talk, and when you stop, the text lands in the box for you to edit before sending.
- Voice mode. A screen of its own for a hands-free conversation. GAIA listens, answers in one or two spoken sentences, and keeps the detailed text of what it did on screen: tool steps, results and files. Captions of both sides are optional.
Decisions made in review
Options considered and why they lost
- Each app runs the loop. The app would chain the listen socket, the chat SSE and one
POST /api/speechper sentence. It reuses read-aloud as it is, but costs extra hops. Every sentence would come back as a whole WAV, and in the TUI as a temp file played by a freshly started PowerShell, hundreds of ms per sentence on Windows. Turn-taking would also be written twice, once in TypeScript and once in Go. - Whisper-Base for everything. Whisper isn’t a streaming model, so Lemonade re-decodes windows and the final transcript lands later. Moonshine Streaming (0.2–0.4 GB) is built for live captions. Whisper stays for the languages Moonshine doesn’t cover.
- NPU Whisper (
whisper-v3-turbo-FLM) by default. Running ASR on the NPU would leave the GPU to the LLM, and it would make a strong showcase. Its latency is unmeasured, so it becomes the default on NPU PCs only if it wins the PR 1 benchmark. - A small dedicated voice model (Qwen3-1.7B, Gemma-4-E2B) that chats instantly and hands
tasks to the flagship. Lemonade holds one LLM at a time (
max_models.llm = 1), so each handoff would evict and reload. That is slower, not faster. Revisit if FLM models on the NPU turn out to sit in a separate slot. - Audio straight into Gemma (
gemma4-it-e2b-FLMaccepts audio). It skips ASR but gives no live captions, and E2B’s tool use is unproven. Not for the first version. - Silence while tools run. It feels broken.
- Scripted per-tool cues (“Searching the web” every time). They’re cheap, but they get tiring fast and say nothing about what this particular step is for. The model already writes a line before a tool call; speaking it costs ~10–15 output tokens per step.
- Browser speech APIs (
SpeechRecognition,speechSynthesis). Chrome’s recognizer sends audio to a cloud service, and system voices can be online. Both break the local-only rule.
What the current code establishes
- Lemonade has everything needed. As of 2026.44.1, Lemonade provides:
- a realtime transcription WebSocket (
websocket_portin/api/v1/health, protocol in #372) with server-side voice-activity detection - one resident model per type (
max_models:llm,transcriptionandttsare separate), so the chat model, a recognizer and Kokoro can all stay loaded together pinned_modelsto keep them there- catalog entries
Moonshine-{Tiny,Small,Medium}-Streaming,Whisper-{Tiny,Base,Small,…}andwhisper-v3-turbo-FLM, all labelledrealtime-transcription
- a realtime transcription WebSocket (
- GAIA’s speech recognition is file-at-a-time.
LemonadeASRClientuploads one WAV per utterance toPOST /audio/transcriptions(src/gaia/audio/lemonade_asr.py).WhisperAsrhard-codes"en". gaia talkdetects speech by loudness (audio_recorder.py), cuts after ~1.3 s of quiet, and mutes the mic while speaking. Only Enter interrupts.- Speech output is
POST /audio/speechwithkokoro-v1, 24 kHz 16-bit PCM (lemonade_tts.py). Read-aloud (#6489) added:POST /api/speech(whole WAV, ≤1000 characters)GET/PUT /api/speech/settings- the
read_aloud_voice/read_aloud_speed/read_aloud_autoconfig keys - a TUI player that shells out to the OS per file (
tui/internal/speech/)
- Neither the chat request nor the flagship has a per-request style option.
ChatRequest(src/gaia/ui/models.py) and the flagship’s strictQueryRequest(gaia_agent/server.py) need a new field. - The agent stream already separates the work from the answer:
step,tool_*,thinking,chunk,answeranddone(_chat_helpers.py,sse_handler.py, and the TUI’stui/internal/event/canonical.go). That separation lets voice mode speak the summary and show the steps. - No microphone code exists in either app. There is no
getUserMediain the webui, no Electron media-permission handler, and no TUI capture.
Architecture
Revision: turns run in the apps
The first design hadVoiceSession run each turn itself. Mapping it onto the code showed why
that doesn’t fit:
- The daemon has no in-process way to run a turn.
- The TUI keeps its own conversation and sends it with every query.
- The Agent UI’s chat pipeline is what saves a turn.
- The socket sends
finalwith the transcript. - The app sends it as an ordinary message with
reply_style: "voice". It is saved, shown and cancelled like any other message. - As the answer streams, the app sends each spoken piece back over the socket (
speak), and the server synthesizes and plays it (Agent UI: PCM frames to the browser; daemon: its own speaker). - Barge-in: the app sends
interrupt, which drops queued speech at once.
<spoken> split happens where the answer stream is parsed: sse_handler.py for the Agent UI,
and the TUI’s own parser. Both run the same test cases. Phone calls (phase B of
Phone calls and texts) are the one host with no app; there the Agent UI
server runs the turns, since it owns the chat pipeline.
The diagram and protocol below describe the first design, except where this revision says
otherwise.
gaia.voice(new package,src/gaia/voice/) owns the whole loop. It runs the turn state machine, endpointing, barge-in, warm-up and timing. It reports errors as typed exceptions with stable codes. Parts:RealtimeListenerholds one Lemonade realtime connection. It takes PCM16 frames from any source and emitspartial,final,speech_startedandspeech_stopped. It picks Moonshine or Whisper from the voice language.- Turn runner (injected) runs one agent turn and yields the canonical agent events. The
Agent UI server passes its existing chat pipeline, so voice turns are saved to the chat
session like typed ones. The daemon passes the flagship query relay.
VoiceSessionnever talks to an agent directly. SpeechStreamerreadsspoken_chunkevents as tokens arrive. It cuts the first piece at the first clause break or 8 words, and later pieces at sentence ends. Each piece goes to Kokoro while the model is still writing, and the PCM goes out as soon as it is synthesized. Pending pieces are cancelled on barge-in.- Status lines:
SpeechStreameralso speakscommentaryevents, the text the model writes just before a tool call, whichsse_handler.pyalready separates from the answer. Each line is trimmed to its first sentence. A line still queued when the next step starts is dropped, so speech never falls behind the work. The earcon is a short bundled tone.
- The Agent UI server hosts it for the browser. The browser streams mic frames up and plays PCM frames through an AudioWorklet ring buffer. Barge-in flushes that buffer locally, with no server round trip, then tells the server.
- The daemon hosts it for the TUI. The daemon records and plays through
sounddevice(thetalkextra), so there are no temp files or per-sentence player processes. The TUI receives events only. This keeps cgo and per-OS recorders out of the Go build. The cost is that the daemon bundle must carry PortAudio; PR 5 verifies that on all three OSes. - Why the server relays and the browser doesn’t call Lemonade directly: Lemonade’s port, its
API key (embeddable Lemonade sets
LEMONADE_API_KEY) and model-slot leases belong to GAIA. Speech has to be generated from the agent’s token stream on the server anyway. - Read-aloud’s speaker button keeps
POST /api/speech. Only voice mode uses the streaming path.
Making it fast
Latency budget
Targets on a warm session, measured by PR 4’s benchmark on the Strix Halo pool and a mid-range Ryzen AI laptop. These are budgets until that harness records real numbers.
Every turn emits a
timing event with these stage marks. The Agent UI shows them in a developer
overlay, and both hosts log them. A regression shows up as a number, not a feeling.
Session protocol
One WebSocket per voice session:WS /api/voice/session (Agent UI server) and
WS /v1/voice/session (daemon).
- Client → server:
- JSON
start {purpose: "dictation"|"voice", session_id} - JSON
stop,interrupt,ptt_down,ptt_up - binary PCM16 16 kHz mic frames, about 100 ms each. Agent UI only; the daemon captures itself.
- JSON
- Server → client:
- JSON events:
state(warming·listening·thinking·speaking·paused)partial,final- the turn’s canonical agent events (steps, tools, files)
spoken_text,answer,timingerror {code}
- binary PCM16 24 kHz speech frames. Agent UI only; the daemon plays them itself.
- JSON events:
- Status endpoints:
GET /api/voice/statusandGET /v1/voice/statusreport readiness: Lemonade reachable, models downloaded, mic present (daemon). The daemon also hasGET /v1/voice/devices.
error codes are stable so each app shows a translated message and its own recovery action. Raw
exception text is never the user-facing string. The codes are lemonade_unreachable,
model_missing, mic_denied, mic_missing, mic_busy, remote_lemonade, cloud_model,
tts_failed and session_lost.
Dictation
Dictation is a voice session withpurpose: "dictation": listening only, with no turn runner
and no speech.
Agent UI
- Mic button in the composer’s
leftControlsslot (Composer.tsx), after attach.- Click to start. A level meter and timer replace the placeholder while recording.
- Click again, press Esc, or press Enter to stop. Enter stops and does not send.
- Live partials show in a strip above the composer. On stop, the final transcript is inserted at the cursor, with a leading space where needed, and focus returns to the box.
- Pauses don’t end dictation. VAD segments are joined. A 5-minute cap stops the recording with a notice.
- Capture:
getUserMedia({audio: {echoCancellation: true, noiseSuppression: true}}), then an AudioWorklet that resamples to 16 kHz mono PCM16. - Electron:
session.setPermissionRequestHandlerandsetPermissionCheckHandlerinmain.cjsgrantmedia(audio only) to the app’s own origin and deny everything else. macOS needsNSMicrophoneUsageDescriptionand thecom.apple.security.device.audio-inputentitlement inelectron-builder.yml.
TUI
Ctrl+R(free in the chat view) toggles dictation./dictatedoes the same, and both are listed in the palette (palette.go) and the help overlay.- While recording, the composer border shows
● Listening — Ctrl+R or Esc to stopand the partial transcript in dim text. On stop, the final text is inserted at the cursor. - The daemon’s microphone is the daemon machine’s. Over SSH the status line says
Listening on <host>.
Voice mode
The turn loop
- Each voice turn is an ordinary message in the current chat session. The same agent, tools, permissions and memory apply. Leaving voice mode returns to the chat with the voice turns in the history. Text and voice stay at parity (#702).
- Status lines come from the model. Before each tool call the model writes one short sentence about what it is doing and why (“Let me look for last week’s invoices in Downloads”). The voice prompt asks it to vary the wording and never repeat the previous line. If the model writes none for a step, GAIA stays quiet; it doesn’t fill in a scripted line. A line is skipped when its step finished before speech could start.
- Permission prompts and questions pause the loop. GAIA speaks the question (“I need your OK to run a shell command. It’s on screen.”), and the card takes the answer. Approving gated tools by voice is out of scope.
- Stop: Esc, the on-screen Stop button, or 2 minutes of silence. That pauses listening; it doesn’t leave the screen.
Turn-taking and barge-in
- Hands-free (default): server VAD ends the user’s turn after the silence window.
- Push-to-talk (setting): hold Space or the on-screen button.
- Barge-in, Agent UI: browser echo cancellation removes GAIA’s own voice, so the mic stays open while GAIA speaks. Speech flushes the playback buffer locally and cancels pending synthesis. If the agent is still working, it keeps going; Stop cancels the task.
- Barge-in, TUI: the daemon’s capture has no echo cancellation, so leaving the mic open would bring back #3494. The daemon pauses capture while speaking, and any key stops playback and resumes listening. Spoken barge-in in the TUI waits for AEC or a headphones setting.
Agent UI screen
- Entry: a waveform button in the composer’s
rightControls. When the composer is empty, the send button is the waveform button; typing turns it back into send. It opens the voice screen for the current session and starts warm-up. Esc closes it. - Layout, kept minimal:
- Top: the animated shape and one state word (Warming up · Listening · Thinking · Speaking · Paused). Nothing else under it: no hints like “Your turn” or “Speak naturally”.
- Middle: captions, when on: your words live, then GAIA’s spoken summary word by word as it plays.
- Side (desktop) or pull-up sheet (phone): “What GAIA did”, the turn’s work log, rendered with the existing step, tool and file components. This is the detailed text, and it scrolls. Rows carry an icon and no text tag: a mic for what you said, a speaker for a spoken status line, a wrench for a tool call.
- Bottom: Stop / Pause, captions toggle, push-to-talk button when that mode is on.
- With captions off, the shape and “What GAIA did” stay. The detail never hides; only the live captions do.
Animations
Each state has its own shape, so you can tell at a glance who has the floor without reading. Listening and speaking are both driven by the live audio level: anAnalyserNode on the mic
stream while listening, and on the playback node while speaking (on the TUI, the daemon sends a
level value with each audio frame).
- The state word shimmers while that state is active: a highlight in the state’s color sweeps across “Listening”, “Thinking” or “Speaking”, the way the Claude Code CLI shows work in progress. It stops on Paused. In right-to-left layouts it sweeps right to left.
- Changes between states crossfade over about 250 ms; listening collapses into the thinking core the moment the earcon plays.
- Colors come from the theme tokens, so both themes work. The shape alone carries the state; color is never the only cue.
prefers-reduced-motion: the shapes stay, but the motion, ripples and shimmer stop. The state word still changes.- Drawn on one
<canvas>at device pixel ratio. Drawing stops when the screen is hidden.
TUI screen
- Entry:
/talk./voiceis read-aloud’s voice picker, and/talkmatchesgaia talk. - A full-screen view on the same chat session:
- Header: a state line.
- Middle: caption area (toggle
c). - Below: the expanded work log (
worklog.go).
- Keys: Esc leaves, Space is push-to-talk when that mode is on,
ppauses, and any key interrupts speech. - The state line uses the same shimmer, and a block-character level meter stands in for the shape.
Phone (mobile access)
GAIA reaches a phone through mobile access: the Agent UI as an installable web app, served from the PC over an ngrok tunnel (gaia/ui/tunnel.py). Voice uses the same session, so nothing new
runs on the phone.
- Where the work happens. The phone records and plays. Its audio goes to the PC over the
tunnel’s HTTPS WebSocket, and Moonshine or Whisper, the chat model and Kokoro all run on the
PC. Mobile access already gives the secure context that
getUserMedianeeds; a plainhttp://LAN address would not. - The same socket rules as the rest of mobile access.
WS /api/voice/sessionchecks the tunnel host and origin the waysecurity.pychecks every other request. Voice settings that change the PC (model downloads, the recognizer) follow the existing mobile-access rules; voice adds no new PC-only gate. - One-time notice the first time voice opens on a phone: “Your voice goes to your PC over mobile access, like your messages. Nothing is processed on this phone or by a cloud speech service.” The tunnel carries audio exactly as it already carries chat text; see Privacy.
- Layout:
- Full screen, the shape in the middle, captions under it.
- A large round button in thumb reach: pause listening, interrupt GAIA, or stop the task, depending on the state. Keyboard on the left returns to the chat; ✕ on the right ends voice.
- “What GAIA did · 3” is a bar above the controls that opens a sheet.
- Safe-area insets on all sides; text inputs at 16 px so iOS doesn’t zoom.
- Phone rules:
- Audio may only start after a tap, so the tap that opens voice mode also creates the
AudioContextand asks for the mic. - The screen stays on while voice mode is open (Screen Wake Lock API).
- Locking the phone or switching apps stops capture. Voice mode pauses. If the web app may show notifications, one says “Voice paused. Open to keep talking.” Opening it shows Paused, and one tap resumes.
- On iPhone,
navigator.audioSession.type = "play-and-record"so GAIA is heard with the silent switch on, and output goes to the speaker, not the earpiece. - Turn-taking and the mic are remembered per device in local storage, so push-to-talk on the phone doesn’t change the PC.
- Phone echo cancellation varies by model. If it lets GAIA hear itself, the phone falls back to tap-to-interrupt with the big button, and says so once. PR 4 decides from tests on real phones.
- Audio may only start after a tap, so the tap that opens voice mode also creates the
- Network. The tunnel adds a round trip each way. Speech plays through a 120 ms jitter buffer. PCM16 at 16 kHz is about 256 kbit/s up, and speech at 24 kHz is about 384 kbit/s down. If that proves too much on mobile data, Opus through WebCodecs is the follow-up.
- Dictation on a phone is the composer mic, as on desktop. It stays local, unlike the keyboard’s own dictation, which can use a cloud service.
The spoken-reply contract
-
Request:
ChatRequest.reply_style: "text" | "voice"(default"text"), forwarded to the flagship’sQueryRequest.reply_style. That class is_Strict, so the field is added explicitly. The daemon’s turn runner sets it onPOST /v1/gaia/query. -
Prompt: when
reply_style == "voice",GaiaAgentappends one volatile fragment after the tools block, and turns reasoning down for the turn. The cached static prompt for text turns is unchanged:This turn is spoken aloud. Before each tool call, write one short sentence (under 12 words) saying what you are about to do, in plain words; vary it and don’t claim a result you don’t have yet. Begin your final answer with
<spoken>…</spoken>: one or two plain sentences, at most 40 words, that tell the user the outcome. No markdown, file paths, URLs, code or lists in anything spoken. If something failed or you are unsure, say so. Then write the detailed answer as usual. - Opening, not closing. The final answer comes after every tool call, so the model already knows the outcome. Putting the summary first lets speech start on its first clause while the detail still streams.
-
Parsing:
sse_handler.py(UI) and the flagship event relay (daemon) detect<spoken>…</spoken>at the start of the answer stream. They emitspoken_chunk/spokenand strip the tags fromchunk/answer. The summary is kept and stored as the message’s lead line, styled apart from the detail, so the chat history shows what GAIA said and then what it did.<spoken>inside thinking is ignored. -
When the block is missing or malformed: GAIA speaks one fixed, translated line (“Done. The
details are on screen.”) and marks the turn. The slip is logged as
voice_reply.missing_spokenfor evals and telemetry. Speaking the detail’s first sentence instead was rejected because it would hide format regressions behind plausible audio. - Cost: about 150 prompt tokens, 40–60 output tokens for the summary, and 10–15 per tool step for status lines. Turning reasoning down on Qwen3.6 saves more than that. PR 3 measures both models.
-
Compact tier: voice mode needs no withheld tool, so it works on Gemma-4-E4B’s
compacttier.
Settings
A Settings › Voice section replaces the existing Read aloud section from read-aloud (#6489), keeping its config keys.voice_asr_model: autopicksMoonshine-Tiny-Streamingfor English. Small replaces Tiny if PR 1’s word-error check shows Tiny misses too much. It picksWhisper-Basefor other languages and forautolanguage, because Moonshine doesn’t detect languages. It pickswhisper-v3-turbo-FLMon NPU PCs only if PR 1’s benchmark shows it is faster. Choosing a model explicitly overridesauto.- Every key is validated like the read-aloud keys (
check_*ingaia/config.py). A bad value inconfig.jsonis an error naming the key, not a silent reset. - A model that isn’t downloaded is offered for download from the setting itself, with its size.
Arabic and other non-English languages
- Whisper transcribes Arabic, so dictation works fully in Arabic.
- Kokoro speaks only English. When the voice language isn’t English, voice mode:
- turns spoken replies and status lines off; the earcon stays (status lines still show as captions)
- forces captions on and shows the spoken summary as a highlighted caption
- shows one notice: “Spoken replies are English-only for now. GAIA will answer on screen.”
- The prompt contract still applies, so the user gets the short answer and the detail, in Arabic text.
Failure states and recovery
The apps recover by themselves wherever they can. Users are never told to run a command.Privacy
- Audio is streamed to Lemonade and never written to disk. There is no recording history.
- On a phone, audio travels to the PC over mobile access, the same tunnel that already carries the chat. ngrok terminates TLS at its edge, so the relay could see the audio just as it can see chat text today. Processing still happens only on the PC. End-to-end encryption through the tunnel is an open question for mobile access as a whole, not for voice alone.
- The mic indicator is always visible while capture is live. Pausing or leaving the screen closes the stream and unpins the speech models.
- Local only, enforced. If
LEMONADE_BASE_URLpoints off this machine, voice refuses to start (remote_lemonade) and explains that voice only runs on a local Lemonade. Dictation and voice mode never use the browser’sSpeechRecognition/speechSynthesis; a test fails the build if the webui references them. - Voice mode needs a local chat model. If the selected model is a cloud provider, the voice
screen offers to switch to the local default (
resolve_default_chat_model()) for the session. It doesn’t silently reroute. Dictation only touches speech recognition, and the user decides whether to send the text, so it works with any chat model.
Test and eval strategy
gaia.voiceunit tests run against fake Lemonade realtime and speech servers:- partials, finals, VAD events, socket drop, a missing model, auth headers
- turn state machine, barge-in cancelling pending synthesis, clause chunking, dropping stale status lines, refusing a remote Lemonade
- assert the shape of outgoing frames (base64 PCM16 at 16 kHz,
input_audio_buffer.append, the model param), not just that a call was made
- Integration: a
require_lemonadetest streams a committed WAV through the real realtime endpoint from a cold state, with the model not downloaded, so the download path is exercised (the #1655 lesson). - Latency benchmark (
util/voice_latency.py): it replays recorded utterances through a real session and writes the stage table above. PR 1 runs it to pick the default recognizer. PR 4 runs it for the release notes, on the Strix Halo pool and a laptop. Budgets are reported, not gated, until there is a baseline. - Agent UI: component tests for the mic button, voice screen states and every failure card.
The
reviewing-agent-uipass covers English and Arabic, empty, warming, listening, speaking, failed, long transcript and modal-open states. The mic button joins “composer chips stay whole at phone width” invisual/rtl.visual.ts. Electron permissions are checked in the packaged app. Screenshots cover each animation state in both themes, plus reduced motion. - Phone: the voice screen at 375 px in English and Arabic, then a manual pass over mobile access on iOS Safari and Android Chrome: first-tap audio unlock, permission denied, lock and resume, silent switch, echo during barge-in, and a weak connection.
- TUI: Go tests for the voice screen model and the dictation insert. A
driving-the-tuisession with a stubbed daemon socket for screenshots. - Evals (LLM-affecting, PR 3):
- A new category,
gaia_voice_mode, run withreply_style: voice. Scenarios check:- the block is present and ≤ 40 words, with no markdown, paths or URLs
- each tool call has a short status line; consecutive lines differ; none claims a result before the tool returned
- the summary agrees with the detail
- a failed tool is admitted in the summary (honesty)
- a multi-tool task keeps its full detail
- reasoning-down doesn’t break tool choice
- Re-run
gaia_voice,gaia_honestyandgaia_tool_selectionwith the field unset; they should match baseline. Name these categories in the PR for the next RC.
- A new category,
Delivery sequence
Each PR updates the docs it touches:
docs/guides/voice.mdx(new), linked fromdocs/guides/agent-ui.mdxanddocs/guides/talk.mdxdocs/reference/cli.mdxfor the TUI commandsdocs/sdk/sdks/agent-ui.mdxfor the endpoints
Out of scope and open questions
- Out of scope for the first version:
- wake word
- approving gated tools by voice
- spoken barge-in in the TUI
- keeping recordings
- non-English speech output
- audio-native LLM input
- a native phone app; the phone uses the Agent UI through mobile access
- GAIA calling your phone over the phone network; see Phone calls and texts
- Open:
- Should
gaia talk(CLI) move ontogaia.voice, or retire in favor of the TUI’s/talk, after PR 6? - The flagship’s
text_to_speechtool (#6204, merged) also callslemonade_tts.py. Should voice mode’s streaming speech share that client, or keep its own?
- Should