voicemode icon indicating copy to clipboard operation
voicemode copied to clipboard

Feature Request: Barge-in / Interrupt TTS playback when user starts speaking

Open rakavanagh opened this issue 10 months ago • 4 comments

Problem Statement

Currently, when Claude responds via TTS, users must wait for the entire response to finish before they can speak. This creates friction in natural conversation, especially when:

  • The user has already understood the point and wants to respond
  • The user needs to redirect the conversation
  • The response is longer than necessary for the user's needs

Proposed Solution

Add a "barge-in" or interrupt capability that detects when the user starts speaking and:

  1. Immediately stops TTS playback
  2. Seamlessly transitions to recording the user's voice input
  3. Continues the conversation without requiring manual intervention

Technical Approach

Looking at the existing NonBlockingAudioPlayer class in audio_player.py, a potential implementation could:

  1. Add a parallel VAD (Voice Activity Detection) thread that continuously monitors the microphone during TTS playback
  2. When voice activity is detected, stop the current TTS playback by:
    • Clearing the audio queue
    • Calling stream.stop()
    • Setting the playback_complete event
  3. Capture the user's speech and send it to Whisper for transcription
  4. Submit the transcription to Claude as the next input

The existing code already uses threading and has mechanisms for stopping playback (CallbackStop, playback_complete event), so the infrastructure is partially there.

Use Case

I use VoiceMode for hands-free coding assistance while working at my desk. The current turn-taking model works well for structured interactions, but true conversational flow requires the ability to interrupt when needed—similar to how human conversations naturally work.

This is especially valuable when:

  • Claude is explaining something I already understand
  • I realize I need to clarify my question mid-response
  • I want to say "yes, do that" before Claude finishes listing all options

Configuration Suggestion

This could be an opt-in feature via environment variable:

VOICEMODE_BARGE_IN=true

Some users might prefer the current sequential behavior for its predictability, so making it configurable would accommodate both preferences.

Additional Context

  • This feature is common in commercial voice assistants (Alexa, Google Assistant, Siri all support barge-in)
  • The VAD functionality is already available through libraries like webrtcvad or could leverage the existing silence detection logic
  • Low latency detection would be important to feel responsive (ideally <100ms from voice onset to TTS stop)

Thank you for building such a useful tool! VoiceMode has made hands-free coding with Claude practical and enjoyable.

rakavanagh avatar Jan 22 '26 21:01 rakavanagh

Yes, this is a useful feature. @ai-cora, please create a task in Taskmaster, refine it and break down the features.json and generate a report card on the task. Then get some minions to work on it.

mbailey avatar Feb 02 '26 14:02 mbailey

Task created in Taskmaster: VM-606

Report Card: A (92%) - Excellent specification, ready for implementation.

Implementation Plan

The task has been broken into 5 phases with 14 tracked features:

  1. Phase 1: Core Infrastructure

    • Add barge-in configuration options
    • Create BargeInMonitor class with VAD-based voice detection
    • Write unit tests
  2. Phase 2: Audio Player Integration

    • Modify NonBlockingAudioPlayer for interrupt support
    • Update text_to_speech() in core.py
    • Write integration tests
  3. Phase 3: Conversation Flow Integration

    • Integrate into converse() tool
    • Handle edge cases (false positives, STT errors)
    • Full integration tests
  4. Phase 4: Streaming Support

    • Add barge-in support for streaming TTS mode
  5. Phase 5: Polish & Documentation

    • Documentation updates
    • Performance testing (<100ms target)
    • PR and review

Configuration (opt-in)

Variable Default Description
VOICEMODE_BARGE_IN false Enable barge-in feature
VOICEMODE_BARGE_IN_VAD 2 VAD aggressiveness (0-3)
VOICEMODE_BARGE_IN_MIN_MS 150 Minimum speech duration to trigger

Work will begin shortly. Thank you for the well-written feature request, @rakavanagh!

ai-cora avatar Feb 02 '26 14:02 ai-cora

Update, @rakavanagh — we just merged a control channel (VM-1676) that delivers the deterministic half of what you asked for: a Stream Deck button, media key, spoken keyword, or any local process can pause / resume / stop in-flight TTS instantly (stop lands under ~200 ms).

When you stop this way, converse returns normally with a control marker, so Claude reads a clean result and continues — no killed server, no ESC reconnect. It's the explicit-trigger counterpart to the VAD approach in your write-up: you get "cut Claude off when he's long-winded" without false-positive risk, at the cost of an explicit press instead of voice-onset detection.

VAD-based barge-in (auto-stop the moment you start speaking, exactly as you outlined) remains tracked as a separate path. Pause/stop is step one; skip forward / back is next, which is where this turns into true hands-free barge-in.

Opt in with VOICEMODE_CONTROL_CHANNEL_ENABLED=true. Docs: docs/reference/control-channel.md.

ai-cora avatar Jun 26 '26 12:06 ai-cora

On barge-in mechanics specifically (commented on #485 too, on the broader always-on question): we ended up needing more than one barge-in behavior, not just on/off — landed on a small preset set (mute-and-steer-now, finish-then-deliver, abort-and-listen, abort-and-steer-now, plus a safe do-nothing default), since different contexts want a real tradeoff between responsiveness and not losing the assistant's train of thought. Also: a hard safety-stop phrase needs to bypass barge-in gating entirely, not route through the same path — that path can have false negatives under load (see the loop in #485), and a safety stop can't inherit those.

Real numbers if useful: WebRTC AEC3 measured 5-8dB mean attenuation across 41 trials on real hardware, zero false barge-ins across that whole batch — the false-positive issue only showed up under a specific rapid-fire real-speech pattern the earlier steady-state testing never hit. That gap between "passes a first test" and "holds under real conversational rhythm" was the single most useful thing we learned. (ConvoBox, if the approach is of interest: github.com/LegionForge/convobox)

jp-cruz avatar Aug 22 '26 17:08 jp-cruz