Skip to content

Voice-first interaction: parity between voice and text as P0 enabling technology #702

Open

Description

@kovtcharov

Summary

Voice is a P0 enabling technology, not a nice-to-have. A privacy-first desktop assistant that can't talk is incomplete. Users interact primarily via voice at home and text on the road — both must deliver the same experience.

Strategic Context

Power users of local AI assistants report voice as their primary interaction mode at home (~50%+ of interactions). Voice-first is also the key differentiator vs cloud assistants — local ASR + TTS means voice data never leaves the device.

GAIA already has the building blocks: Whisper ASR (src/gaia/audio/whisper_asr.py), Kokoro TTS (src/gaia/audio/kokoro_tts.py), and Talk mode (gaia talk). The gap is integrating these into the Agent UI as a first-class interaction mode with parity to text.

Design Principle: Voice/Text Parity

  • Same capabilities available in both modes
  • Voice input → same processing pipeline as text input
  • Responses delivered as both text (in UI) and speech (via TTS)
  • Push-to-talk and always-listening modes
  • Voice commands for smart home, email triage, daily briefs, system control

Key Deliverables

  1. Agent UI voice mode — mic button in chat, push-to-talk, streaming transcription displayed as it's spoken
  2. TTS response playback — agent reads responses aloud, interruptible
  3. Voice command routing — "hey GAIA" wake word (optional), direct command parsing
  4. Streaming ASR in UI — real-time transcription via Lemonade WebSocket (Add streaming transcription via Lemonade WebSocket realtime API #372)
  5. Voice + tool execution — voice triggers tools, results spoken back with summaries
  6. Smart home voice control — natural multi-device commands via Home Assistant integration

Dependencies

Acceptance Criteria

  • Agent UI has a voice input button with push-to-talk
  • Streaming transcription displays in real-time as user speaks
  • Agent responses played back via TTS (toggleable)
  • Voice and text produce identical agent behavior
  • Works fully offline — local Whisper ASR + Kokoro TTS
  • Latency: < 500ms from end of speech to start of agent processing
  • Multi-command parsing: "turn kitchen lights to 50% and play jazz"

Activity

  1. added
    enhancement
    p0
    audio
    on Apr 1, 2026
  2. kovtcharov commented on Apr 26, 2026

    @kovtcharov
    ContributorAuthor

    Scope confirmation: voice loop must be platform-agnostic

    Per the consumer-use-case review, voice-first parity is most consumer-impactful when the voice surface is wherever the user is — not exclusively the Agent UI mic.

    Requested explicit scope clarifications

    • Voice in/out is implemented at the agent boundary, not the Agent UI boundary — surfaces consume it, not reimplement it
    • Telegram (Telegram messaging adapter (Phase 0) — pull forward from v0.23.0 #889) integrates the same Kokoro/Whisper path used by the Agent UI mic
    • When messaging adapters in v0.23.0 land (Discord/Slack/Signal/etc.), they get voice in/out for free by reusing the same primitive
    • Configurable per-skill whether to respond in voice or text (some skills are voice-natural, others are text-natural)

    Why this matters

    Without platform-agnosticism, voice-first becomes 'voice in the desktop app' — which is the experience consumers like least (laptop is for typing). Voice is most valuable when consumers are commuting, cooking, exercising — i.e., on their phone, via Telegram/WhatsApp/Slack — and the agent reaches them there.

    This aligns with Hermes Agent's voice posture: TTS providers (Edge, ElevenLabs, OpenAI, MiniMax, NeuTTS) are wired at the runtime layer and consumed identically by CLI, Telegram, Discord, and Discord VC.

  3. added
    consumer
    on Apr 26, 2026
  4. added
    track:consumer-app
    domain:agent-core
    and removed on Apr 26, 2026
  5. kovtcharov commented on Apr 26, 2026

    @kovtcharov
    ContributorAuthor

    Technical spec — agent-boundary voice abstraction (v0.20.0 scope split)

    Concrete starting point for src/gaia/voice/ (new package) and surface adapters consuming it. Reflects the post-#889/#896 scope split: the voice primitive lands at the agent boundary in v0.20.0; full multimodal model integration (Lemonade v10 dependent — #533/#539/#540) defers to v0.21.0.

    Scope split

    Lands in v0.20.0 (this spec) Defers to v0.21.0
    VoiceIO interface at the agent boundary Native multimodal model I/O (Lemonade v10)
    Agent UI mic + push-to-talk Audio modality passed to the model directly (no ASR step)
    Telegram (#889) consumes same primitive Image-in / audio-in over the same socket
    Mobile browser (#896) consumes same primitive /v1/audio/speech server-side TTS endpoint
    Codec negotiation across surfaces Streaming TTS at the model layer (vs the surface layer)
    Per-skill voice/text response config
    Low-confidence ASR → clarification flow

    The interface shipped in v0.20.0 is forward-compatible with v0.21.0 multimodal: when Lemonade v10 lands, the VoiceIO.transcribe step becomes a no-op and audio frames flow directly to the model.

    Architecture

                     ┌──────────────────────────────────────────┐
                     │          src/gaia/voice/                  │
                     │  ┌────────────────────────────────────┐  │
                     │  │  VoiceIO (Protocol)                │  │
                     │  │   .transcribe(audio, codec) -> str │  │
                     │  │   .synthesize(text) -> AudioStream │  │
                     │  │   .negotiate(client_codecs) -> Cdc │  │
                     │  └────────────────────────────────────┘  │
                     │                  ▲                       │
                     │                  │ injected per-session  │
                     │  ┌───────────────┴────────────────────┐  │
                     │  │ DefaultVoiceIO                     │  │
                     │  │   ASR: WhisperAsr (existing)       │  │
                     │  │   TTS: KokoroTTS (existing)        │  │
                     │  │   codec: CodecNegotiator           │  │
                     │  └────────────────────────────────────┘  │
                     └────────────────┬─────────────────────────┘
                                      │ consumed by every surface
            ┌─────────────────────────┼──────────────────────────────────┐
            ▼                         ▼                                  ▼
    ┌──────────────────┐  ┌──────────────────────┐  ┌──────────────────────────────┐
    │ Agent UI mic      │  │ Telegram adapter     │  │ Mobile browser (#896)         │
    │ (browser MediaRec │  │ (#889 — OGG/Opus)    │  │ iOS Safari / Android Chrome   │
    │  WebM/Opus)       │  │                      │  │ via WebRTC or MediaRecorder   │
    └──────────────────┘  └──────────────────────┘  └──────────────────────────────┘
    

    The VoiceIO instance is held by the agent, not the surface. Surfaces forward raw audio frames + a codec hint and receive transcripts back; surfaces forward agent text + receive an audio stream they can pipe to their native player.

    Interface

    # src/gaia/voice/io.py
    from dataclasses import dataclass, field
    from enum import Enum
    from typing import Protocol, AsyncIterator
    
    class Codec(Enum):
        PCM16_16K     = "pcm16/16000"   # Whisper-native
        WEBM_OPUS     = "audio/webm;codecs=opus"
        OGG_OPUS      = "audio/ogg;codecs=opus"   # Telegram voice notes
        MP4_AAC       = "audio/mp4;codecs=mp4a"   # iOS Safari
        WAV_PCM       = "audio/wav"
    
    @dataclass
    class TranscriptResult:
        text: str
        confidence: float            # 0.0..1.0 — derived from Whisper avg_logprob
        language: str | None = None  # ISO-639-1, None if unknown
        needs_clarification: bool = False  # True if confidence < threshold
    
    @dataclass
    class VoicePreference:
        """Per-skill toggle, set by skill frontmatter (see #890 Skill format)."""
        response_mode: str = "match_input"   # "voice" | "text" | "match_input"
        streaming: bool = True               # stream TTS chunks vs buffer-and-send
    
    class VoiceIO(Protocol):
        async def negotiate(self, client_codecs: list[Codec]) -> Codec: ...
        async def transcribe(self, audio: bytes, codec: Codec) -> TranscriptResult: ...
        async def synthesize(
            self, text: str, *, streaming: bool = True
        ) -> AsyncIterator[bytes]: ...
    
    @dataclass
    class VoiceConfig:
        """Per-agent voice config; lives on Agent like any other config dataclass."""
        asr_model: str = "base"                         # whisper model size
        tts_voice: str = "af_heart"                     # kokoro voice id
        confidence_threshold: float = 0.55              # below → clarify
        max_audio_seconds: int = 60                     # surface enforces; reject longer
        server_codecs: list[Codec] = field(
            default_factory=lambda: [Codec.PCM16_16K, Codec.WEBM_OPUS, Codec.OGG_OPUS]
        )
        privacy_mode: str = "device_only"               # never "cloud" — fail loud if set

    Default implementation — DefaultVoiceIO

    # src/gaia/voice/default.py
    class DefaultVoiceIO:
        """Wraps existing WhisperAsr + KokoroTTS behind the VoiceIO protocol.
        No new model dependency — pure refactor of src/gaia/audio/ + src/gaia/talk/sdk.py.
        """
        def __init__(self, config: VoiceConfig):
            if config.privacy_mode != "device_only":
                # CLAUDE.md no-silent-fallbacks: refuse to run with any non-local mode in v0.20
                raise ValueError(
                    f"VoiceConfig.privacy_mode={config.privacy_mode!r} is not supported. "
                    f"v0.20.0 only ships device-only voice (Whisper ASR + Kokoro TTS). "
                    f"Set privacy_mode='device_only' or wait for v0.21.0 multimodal."
                )
            self._asr = WhisperAsr(model_size=config.asr_model)
            self._tts = KokoroTTS()  # pre-loaded; warmup runs once
            self._negotiator = CodecNegotiator(config.server_codecs)
            self._config = config
    
        async def negotiate(self, client_codecs):
            # Pick the first server codec that the client also supports
            for c in self._config.server_codecs:
                if c in client_codecs:
                    return c
            raise ValueError(
                f"no supported codec in client offer {client_codecs}; "
                f"server supports {self._config.server_codecs}"
            )
    
        async def transcribe(self, audio, codec):
            pcm = await self._negotiator.transcode_to_pcm16_16k(audio, codec)
            result = await self._asr.transcribe_async(pcm)  # returns dict with avg_logprob
            confidence = _logprob_to_confidence(result["avg_logprob"])
            return TranscriptResult(
                text=result["text"],
                confidence=confidence,
                language=result.get("language"),
                needs_clarification=confidence < self._config.confidence_threshold,
            )
    
        async def synthesize(self, text, *, streaming=True):
            if streaming:
                async for chunk in self._tts.stream_chunks(text, voice=self._config.tts_voice):
                    yield chunk
            else:
                yield await self._tts.synthesize_full(text, voice=self._config.tts_voice)

    Codec negotiation

    CodecNegotiator is the only component that touches ffmpeg. Surfaces do not transcode — the server does, in one place, so a Telegram OGG/Opus voice note and a browser WebM/Opus blob both arrive at Whisper as 16-kHz PCM mono.

    # src/gaia/voice/codec.py
    class CodecNegotiator:
        """Server-side transcode to PCM16/16k — Whisper's native input format."""
        async def transcode_to_pcm16_16k(self, audio: bytes, codec: Codec) -> bytes:
            if codec == Codec.PCM16_16K:
                return audio
            # Use ffmpeg-python (already a soft dep via kokoro)
            return await _ffmpeg_transcode(audio, codec, "pcm_s16le", 16000, 1)

    Per-skill response mode

    Skills (#890) declare voice/text preference in frontmatter:

    ---
    name: morning-briefing
    when_to_use: when user says "good morning" or asks for the daily brief
    voice:
      response_mode: voice    # always speak, even if user typed
      streaming: true
    ---
    ---
    name: code-review
    voice:
      response_mode: text     # never speak code aloud
    ---

    The Agent reads skill.voice after skill recall (#888) and uses it to decide whether to call voice.synthesize() on the response.

    Low-confidence ASR handling (no silent failure)

    When TranscriptResult.needs_clarification is True, the agent does not silently send the low-confidence transcript to the LLM. It plays back a clarification prompt:

    async def on_voice_input(audio: bytes, codec: Codec):
        transcript = await self.voice.transcribe(audio, codec)
        if transcript.needs_clarification:
            prompt = f"I heard '{transcript.text}' — did I get that right?"
            async for chunk in self.voice.synthesize(prompt):
                yield chunk
            return  # wait for the user to confirm or repeat
        # confidence high enough — proceed to the agent loop
        response = await self.send(transcript.text)
        ...

    This is the CLAUDE.md "no silent fallbacks" rule applied to ASR: a confidence-below-threshold transcript is an error condition, not a thing to silently shrug at.

    Surface adapters (each ~80 LOC)

    Each surface implements three things: collect audio, hand it to voice.transcribe, play voice.synthesize output back. None of them re-implement ASR/TTS.

    • Agent UI mic — src/gaia/ui/routers/voice.py exposes POST /api/voice/transcribe (multipart audio + Content-Type codec) and GET /api/voice/synthesize (SSE stream of audio chunks). Browser sends audio/webm;codecs=opus from MediaRecorder.
    • Telegram (Telegram messaging adapter (Phase 0) — pull forward from v0.23.0 #889) — adapter posts incoming OGG/Opus voice notes to the same voice.transcribe (no HTTP — direct call inside the bridge process); replies use voice.synthesize and uploads the result via sendVoice.
    • Mobile browser (Voice via mobile browser: ASR + TTS on iOS Safari + Android Chrome #896) — same /api/voice/* endpoints as the Agent UI. iOS Safari sends audio/mp4;codecs=mp4a (no Opus support pre-iOS 17.4); the negotiator transcodes both ways.

    Tests — surface parity

    # tests/integration/voice/test_surface_parity.py
    @pytest.mark.parametrize("surface,codec,fixture", [
        ("ui",       Codec.WEBM_OPUS, "fixtures/voice/hello_webm.bin"),
        ("telegram", Codec.OGG_OPUS,  "fixtures/voice/hello_ogg.bin"),
        ("mobile",   Codec.MP4_AAC,   "fixtures/voice/hello_mp4.bin"),
    ])
    async def test_same_transcript_across_surfaces(surface, codec, fixture):
        """Same audio content → same transcript regardless of surface codec."""
        voice = DefaultVoiceIO(VoiceConfig())
        audio = Path(fixture).read_bytes()
        result = await voice.transcribe(audio, codec)
        assert "hello" in result.text.lower()
        assert result.confidence > 0.7

    Acceptance criteria → tests

    Criterion Test
    Voice abstraction at agent boundary, not UI boundary test_agent_owns_voice_io — assert Agent.voice is a VoiceIO; surfaces call into it
    Same primitive across UI/Telegram/mobile test_surface_parity (above)
    Codec negotiation server-side test_codec_negotiation — client offers [MP4_AAC], server picks compatible; refuses if no overlap
    Streaming TTS chunks test_synthesize_streaming — assert synthesize(streaming=True) yields >1 chunk for >50-word text
    Per-skill voice/text mode test_skill_voice_mode — load fixture skills with response_mode: voice/text/match_input, assert agent honors each
    Low-confidence → clarification test_low_confidence_clarify — feed garbled audio, assert agent plays back "did I get that right?" instead of forwarding to LLM
    Voice never leaves device gaia privacy verify (from #890 spec) — start a voice session, assert no outbound calls except localhost
    Latency budget test_voice_latency — end-of-speech to first TTS audio chunk < 800 ms on baseline hardware (Strix Halo)

    Failure modes (per CLAUDE.md)

    • Whisper model not downloaded → raise RuntimeError(f"Whisper model {size} not found at {path}; run gaia init --download-voice"). Do NOT silently fall back to a smaller model.
    • Kokoro voice id invalid → raise ValueError(f"unknown TTS voice {voice_id!r}; valid: {list_voices()}"). Do NOT silently substitute the default.
    • Codec negotiation fails → return HTTP 415 from the /api/voice/transcribe endpoint with Accept: <list of supported codecs>.
    • privacy_mode != "device_only" in v0.20.0 → constructor raises immediately. Cloud voice routing is a v0.21.0+ topic; users should not be able to opt in by accident.
    • ASR returns empty transcript (silence, music) → return TranscriptResult(text="", confidence=0.0, needs_clarification=True) and let the surface decide whether to prompt the user.

    Privacy invariant

    A static-audit rule in #890's privacy verifier asserts that nothing under src/gaia/voice/ imports any HTTP client or opens any non-localhost socket. Audio frames must reach Whisper without leaving the process. CI fails the PR if a future change introduces a network call from src/gaia/voice/.

    Dependencies

    Attribution

  6. added
    spec-ready
    on Apr 26, 2026
  7. added
    talk
    on Jun 9, 2026
  8. added
    p1
    and removed
    p0
    on Aug 4, 2026
  9. added
    p2
    and removed
    p1
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentaudioconsumerdomain:agent-coreenhancementp2spec-readytalktrack:consumer-app

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions