fix(voice_worker): the wake word hint may never add, drop or create a wake word
Hotword occurrences were counted with fuzzy matching, which never counted a one-letter wake word (so a hinted "봇 ..." was accepted over a plain decode without it) and counted the real word "서비스" as "자비스" (so the hint could turn it into the wake word). Occurrences are now counted exactly (case, spacing and punctuation ignored); near misses are left as heard for call detection. The real-noise eval now plays each recording as recorded and at -25 dBFS and reports how many clips reached the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -48,31 +48,21 @@ def _edit_distance(a: str, b: str) -> int:
|
||||
|
||||
|
||||
def _mentions(text: str, word: str) -> int:
|
||||
"""How many times ``word`` occurs in ``text``, allowing a near miss in spelling (자비수 for 자비스)."""
|
||||
t, w = _letters(text), _letters(word)
|
||||
if not w:
|
||||
return 0
|
||||
slack = max(1, len(w) // 3)
|
||||
count, i = 0, 0
|
||||
while i <= len(t) - max(1, len(w) - slack):
|
||||
hit = next((n for n in range(len(w) - slack, len(w) + slack + 1)
|
||||
if i + n <= len(t) and _edit_distance(t[i:i + n], w) <= slack), None)
|
||||
if hit:
|
||||
count += 1
|
||||
i += hit
|
||||
else:
|
||||
i += 1
|
||||
return count
|
||||
"""Exact occurrences of ``word`` in ``text``, ignoring case, spacing and punctuation. No fuzzy
|
||||
matching: a near miss ("자비수", or the real word "서비스") is not the wake word as far as the
|
||||
hint is concerned."""
|
||||
w = _letters(word)
|
||||
return _letters(text).count(w) if w else 0
|
||||
|
||||
|
||||
def choose_with_hint(hint_text: str, hint_lp: float, plain_text: str, plain_lp: float,
|
||||
hotwords: tuple[str, ...]) -> str:
|
||||
"""Pick between the decode that had the hotwords as a hint and the plain decode of the same audio.
|
||||
|
||||
The hint can make Whisper write a wake word that nobody said (on laughter, or tacked onto a real
|
||||
sentence), so the plain decode decides: no plain text means nothing was said, and the hint's text
|
||||
is used only when it stays close to the plain one and mentions every hotword as often (it may fix
|
||||
their spelling, not add or drop them).
|
||||
The hint can make Whisper write a wake word that nobody said (on laughter, tacked onto a real
|
||||
sentence, or in place of a similar word), so the plain decode decides: no plain text means nothing
|
||||
was said, and the hint's text is used only when it stays close to the plain one and contains every
|
||||
hotword exactly as often. It may change other words, never how many wake words were heard.
|
||||
"""
|
||||
if not keep_transcript(plain_text, plain_lp):
|
||||
return ""
|
||||
|
||||
@@ -134,16 +134,19 @@ text is empty:
|
||||
- Its compression ratio (UTF-8 bytes over zlib bytes) is at most 2.4, which catches repetition loops.
|
||||
- With hotwords: the clip is decoded once with them and once without, from the same encoder pass.
|
||||
The plain decode must pass the checks above, otherwise nothing was said. The hinted text is used
|
||||
only when it stays within half the plain text's letters of it and mentions every hotword as often
|
||||
as the plain one (a near miss in spelling counts as a mention), so the hint can fix how a spoken
|
||||
wake word is written but never add or drop one. Otherwise the plain text is used.
|
||||
only when it stays within half the plain text's letters of it and contains every hotword exactly
|
||||
as often as the plain one (ignoring case, spacing and punctuation, no fuzzy matching), so the hint
|
||||
can never add, drop or create a wake word: not from laughter, not after a real sentence, not from
|
||||
a one-letter wake word, and not by turning a similar word ("서비스", or the near miss "자비수")
|
||||
into it. Otherwise the plain text is used; matching near misses is left to call detection.
|
||||
|
||||
`no_speech_prob` is not used: large-v3-turbo reports 0.0 for silence and noise alike.
|
||||
|
||||
Measured (2026-11-11, RTX 5050) with 54 real noise recordings from ESC-50 (typing, mouse, breathing,
|
||||
coughing, laughing, crying, vacuum, ...), each at its own level and at -25 dBFS: of the 108 noise-only
|
||||
clips, 102 never reached the model (the VAD rule above) and the 6 that did (coughs, laughter, crying)
|
||||
all came out empty, with and without the wake word hint. Over 89 mixes of speech with that noise
|
||||
clips streamed through the worker with the wake word hint on, 103 never reached the model (the VAD
|
||||
rule above) and the 5 that did (coughs, laughter, crying) all came out empty
|
||||
(`test_real_noise_recordings_produce_no_text` with `JARVIS_NOISE_DIR`). Over 89 mixes of speech with that noise
|
||||
(SNR 20, 10 and 0 dB, plus clean) the mean character error rate was 4.8%. Left over: one
|
||||
"thank you" written for laughter just before a sentence (mean log-probability -0.70, right at the
|
||||
line), two short words lost in loud noise, and one word repeated three times at SNR 0. A stricter
|
||||
|
||||
Reference in New Issue
Block a user