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:
@@ -51,9 +51,27 @@ def test_a_wake_word_the_hint_adds_to_real_speech_is_dropped():
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_hint_may_fix_how_a_spoken_wake_word_is_spelt():
|
||||
fixed = "자비스, 오늘 서울 날씨 어때?"
|
||||
assert choose_with_hint(fixed, -0.1, "자비수, 오늘 서울 날씨 어때?", -0.2, HINT) == fixed
|
||||
def test_a_one_letter_wake_word_the_hint_adds_is_dropped():
|
||||
assert choose_with_hint("봇 오늘 날씨 알려 줘", -0.1, "오늘 날씨 알려 줘", -0.1, ("봇",)) == "오늘 날씨 알려 줘"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_hint_may_not_turn_a_similar_real_word_into_the_wake_word():
|
||||
assert choose_with_hint("자비스 신청해 줘", -0.1, "서비스 신청해 줘", -0.1, HINT) == "서비스 신청해 줘"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_near_miss_spelling_is_left_as_heard_rather_than_guessed():
|
||||
# "자비수" may be the wake word or another word; text alone cannot tell, so the plain decode stands
|
||||
# and fuzzy wake word matching is left to the call detection that reads it.
|
||||
plain = "자비수, 오늘 서울 날씨 어때?"
|
||||
assert choose_with_hint("자비스, 오늘 서울 날씨 어때?", -0.1, plain, -0.2, HINT) == plain
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_hint_is_used_when_it_keeps_the_wake_words_as_they_were():
|
||||
hinted = "자비스, 철수 화면 공유 보여 줘"
|
||||
assert choose_with_hint(hinted, -0.1, "자비스 철수 화면공유 보여줘", -0.15, HINT) == hinted
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
@@ -292,12 +292,13 @@ def test_quiet_and_loud_speakers_are_both_understood(engines, level_db):
|
||||
|
||||
def test_real_noise_recordings_produce_no_text(engines):
|
||||
"""Optional: point JARVIS_NOISE_DIR at noise-only recordings (16 kHz or 44.1 kHz mono/stereo WAV,
|
||||
e.g. ESC-50 keyboard, mouse, breathing, coughing, laughing). None may produce text."""
|
||||
e.g. ESC-50 keyboard, mouse, breathing, coughing, laughing; ESC-50 is CC BY-NC, so it is not in
|
||||
the repository). Each plays as recorded and at -25 dBFS; none may produce text."""
|
||||
folder = os.environ.get("JARVIS_NOISE_DIR")
|
||||
if not folder:
|
||||
pytest.skip("set JARVIS_NOISE_DIR to a folder of noise-only WAV files")
|
||||
from scipy.signal import resample_poly
|
||||
texts = []
|
||||
texts, reached, clips = [], 0, 0
|
||||
for path in sorted(Path(folder).glob("*.wav")):
|
||||
with wave.open(str(path), "rb") as w:
|
||||
x = np.frombuffer(w.readframes(w.getnframes()), dtype="<i2").astype(np.float32) / 32768.0
|
||||
@@ -308,8 +309,10 @@ def test_real_noise_recordings_produce_no_text(engines):
|
||||
from math import gcd
|
||||
g = gcd(rate, 16000)
|
||||
x = resample_poly(x, 16000 // g, rate // g).astype(np.float32)
|
||||
for m in _stream_clip_16k(engines, x, {"hotwords": ["자비스"], "partials": False}):
|
||||
if m["text"]:
|
||||
texts.append((path.name, m["text"]))
|
||||
print(texts)
|
||||
for level in (x, np.clip(_at_db(x, -25), -1, 1)): # as recorded, and as a loud mic would send it
|
||||
clips += 1
|
||||
finals = _stream_clip_16k(engines, level, {"hotwords": ["자비스"], "partials": False})
|
||||
reached += bool(finals) # a final means the clip passed the VAD and went to the model
|
||||
texts += [(path.name, m["text"]) for m in finals if m["text"]]
|
||||
print(f"noise clips {clips}, reached the model {reached}, with text {texts}")
|
||||
assert texts == []
|
||||
|
||||
Reference in New Issue
Block a user