fix(voice): drop playback-phase barge transcripts that echo Hermes' own TTS

The full-duplex barge-in listener added in 5081551f0 stays active during
TTS playback with no acoustic echo cancellation. On some speaker/mic
combinations, TTS bleed alone crosses the barge threshold, gets
transcribed, and is queued as the next user turn -- whose reply is then
spoken, captured, and queued again, producing an unbounded TTS -> STT ->
TTS feedback loop (#75780).

Add a fail-closed transcript-level guard: when a barge trip happens during
the playback phase, compare the captured transcript against the TTS text
Hermes just spoke (tools/voice_mode.is_tts_echo, a language-agnostic
character-level similarity ratio). A close match is dropped instead of
queued, and the mic is handed back to the normal continuous-listening
loop. Generation-phase trips (no TTS playing, so no bleed is possible)
are unaffected.
This commit is contained in:
chelsealong
2026-08-01 02:04:43 +00:00
committed by kshitij
parent 6ab7528c33
commit d4a753ea42
4 changed files with 193 additions and 0 deletions
+38
View File
@@ -9,6 +9,7 @@ Dependencies (optional):
or: uv sync --extra voice
"""
import difflib
import logging
import math
import os
@@ -1310,6 +1311,43 @@ def is_voice_stop_phrase(transcript: str, stop_phrases: Optional[tuple] = None)
return cleaned in stop_phrases
# Similarity ratio (difflib.SequenceMatcher, 0..1) above which a
# playback-phase barge transcript is treated as a self-capture of Hermes'
# own just-spoken TTS rather than genuine user speech. See #75780: the
# full-duplex listener has no acoustic echo cancellation, so speaker bleed
# on the mic can trip the barge trigger and get transcribed nearly
# verbatim from the TTS text, creating a TTS -> STT -> TTS feedback loop.
DEFAULT_TTS_ECHO_SIMILARITY_THRESHOLD = 0.6
def _normalize_for_echo_compare(text: str) -> str:
return re.sub(r"\s+", " ", text).strip().lower()
def is_tts_echo(
transcript: str,
spoken_text: str,
threshold: float = DEFAULT_TTS_ECHO_SIMILARITY_THRESHOLD,
) -> bool:
"""Return True when *transcript* looks like a self-capture of *spoken_text*.
Compares a playback-phase barge-in transcript against the TTS text
Hermes just spoke using a character-level similarity ratio, which works
across languages without word-tokenization. A genuine user interjection
is very unlikely to closely match Hermes' own words, so a high ratio is
a strong signal of speaker-bleed self-capture (fail-closed guard for the
playback-phase full-duplex listener, which has no acoustic echo
cancellation; see #75780).
"""
if not transcript or not spoken_text:
return False
a = _normalize_for_echo_compare(transcript)
b = _normalize_for_echo_compare(spoken_text)
if not a or not b:
return False
return difflib.SequenceMatcher(None, a, b).ratio() >= threshold
def voice_stop_hint() -> str:
"""One-line 'Say "stop" to end the voice chat.' hint for voice-mode start.