feat(voice_worker): finals are also decoded with the recent conversation as Whisper's prompt

The words of the topic were the ones misheard live (화면공이 for 화면 공유, 계산지 for 계산기), and
five models made the same mistakes. Each final is decoded as before and again with the last 180 s
of the channel's conversation (everyone's finals and Jarvis's speech, at most context_chars=200
characters) as the previous-text prompt; the prompted text is used only when the plain one was kept,
stays within half its letters and keeps every hotword count, as for the hint.

Measured on the game PC (RTX 5070 Ti, 100 recordings of the user, 16 with their own text): CER
12.0% -> 7.5%, empty results unchanged, noise clips with text unchanged (16/108), final decode
p95 170 -> 253 ms. Finals with a context are decoded one clip at a time (ctranslate2 needs the
start token at one position in a batch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-19 19:38:10 +09:00
parent 478968949c
commit 628d89c4f1
10 changed files with 234 additions and 17 deletions

View File

@@ -303,7 +303,7 @@ class SlowTranscriber(LevelTranscriber):
super().__init__()
self.delay = delay
def transcribe(self, clips, opts):
def transcribe(self, clips, opts, contexts=None):
import time as _t
_t.sleep(self.delay)
return super().transcribe(clips, opts)

View File

@@ -96,3 +96,39 @@ def test_wake_word_matching_ignores_case_spacing_and_punctuation():
def test_spacing_and_punctuation_differences_do_not_change_the_choice():
assert choose_with_hint("자비스 오늘 서울 날씨 어때", -0.1, "자비스, 오늘 서울 날씨 어때?", -0.1, HINT) \
== "자비스 오늘 서울 날씨 어때"
# The recent conversation as Whisper's previous-text prompt (voice_worker.spec.md, "Conversation
# context"). Live 2026-11-19 the prompt fixed words of the topic ("화면공이" -> "화면 공유", "계산지" ->
# "계산기"); on noise it wrote words of the prompt. The decode without it decides, as with the hint.
from voice_worker.stt_whisper import choose_with_context # noqa: E402
@pytest.mark.unit
def test_the_context_may_fix_words_of_what_was_said():
assert choose_with_context("내 화면공이 안 보여?", "내 화면 공유 안 보여?", HINT) == "내 화면 공유 안 보여?"
@pytest.mark.unit
def test_nothing_heard_without_the_context_stays_nothing():
# Noise: the prompted decode wrote words of the conversation.
assert choose_with_context("", "화면에 디스코드", HINT) == ""
@pytest.mark.unit
def test_a_prompted_decode_far_from_what_was_heard_is_not_used():
heard = "가상화면을 못 봐"
copied = "네, 현재 화면에 디스코드 채팅 창과 여러 프로그램이 정상적으로 보입니다."
assert choose_with_context(heard, copied, HINT) == heard
@pytest.mark.unit
def test_the_context_never_changes_how_many_wake_words_were_heard():
assert choose_with_context("라비스 지금 영상 재생되고 있어?", "자비스 지금 영상 재생되고 있어?", HINT) \
== "라비스 지금 영상 재생되고 있어?"
assert choose_with_context("자비스 날씨 알려 줘", "날씨 알려 줘", HINT) == "자비스 날씨 알려 줘"
@pytest.mark.unit
def test_an_empty_prompted_decode_keeps_what_was_heard():
assert choose_with_context("네.", "", HINT) == "네."

View File

@@ -25,7 +25,7 @@ class FakeTranscriber:
self.gate.set()
self.fail_on_beam = fail_on_beam
def transcribe(self, clips, opts):
def transcribe(self, clips, opts, contexts=None):
self.entered.set()
self.gate.wait(5)
self.calls.append((opts, [len(c) for c in clips]))
@@ -218,12 +218,45 @@ class StepTranscriber:
def step(self):
self._steps.release()
def transcribe(self, clips, opts):
def transcribe(self, clips, opts, contexts=None):
self.calls.append([len(c) for c in clips])
self._steps.acquire(timeout=5)
return ["" for _ in clips]
@pytest.mark.unit
def test_each_final_reaches_the_model_with_its_own_context():
class Ctx:
def __init__(self):
self.calls = []
def transcribe(self, clips, opts, contexts=None):
self.calls.append(list(contexts or []))
return [f"n{len(c)}" for c in clips]
eng = Ctx()
async def body():
s = SttScheduler(eng)
s.start()
got = []
done = asyncio.Event()
def cb(r):
got.append(r.text)
if len(got) == 3:
done.set()
s.submit_final("a", clip(100), FINAL, cb, context="화면 공유")
s.submit_final("b", clip(200), FINAL, cb)
s.submit_partial("c", clip(300), PARTIAL, cb)
await asyncio.wait_for(done.wait(), 5)
await s.stop()
asyncio.run(body())
assert eng.calls[0] == ["화면 공유", ""]
assert eng.calls[1] == [""], "partials go without context"
@pytest.mark.unit
def test_partial_batches_are_kept_small_so_finals_can_cut_in():
t = StepTranscriber()

View File

@@ -32,7 +32,7 @@ class LevelTranscriber:
def __init__(self):
self.calls = []
def transcribe(self, clips, opts):
def transcribe(self, clips, opts, contexts=None):
self.calls.append((opts, len(clips)))
return [f"level {np.argmax(np.abs(np.fft.rfft(c))) * 16000 / len(c) / 1000:.1f}" for c in clips]
@@ -336,7 +336,7 @@ def test_48k_stereo_input_reaches_the_model_at_16k():
lengths = []
orig = t.transcribe
def spy(clips, opts):
def spy(clips, opts, contexts=None):
lengths.extend(len(c) for c in clips)
return orig(clips, opts)
@@ -496,3 +496,47 @@ def test_old_recordings_are_also_removed_while_the_worker_keeps_running(tmp_path
r.said(later.timestamp(), "1", "A", "vc", "나중", np.zeros(1600))
r.close()
assert sorted(p.name for p in tmp_path.iterdir()) == [later.date().isoformat()]
class ContextTranscriber(LevelTranscriber):
def __init__(self):
super().__init__()
self.contexts = []
def transcribe(self, clips, opts, contexts=None):
if opts.beam > 1: # finals
self.contexts += list(contexts or [""] * len(clips))
return super().transcribe(clips, opts)
async def _said(ws, speaker, level):
await stream(ws, speaker, level, 600)
await ws.send(json.dumps({"type": "speaking_end", "speaker": speaker}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "final" and m["speaker"] == speaker)
@pytest.mark.unit
def test_each_final_is_transcribed_with_the_recent_conversation_of_the_channel():
"""voice_worker.spec.md, "Conversation context": what was said and answered just before, in the
channel Jarvis is in, is the model's prompt for the next final."""
t = ContextTranscriber()
async def body(url):
async with connect(url) as ws:
await hello(ws, stt={"partials": False})
await ws.send(json.dumps({"type": "voice_join", "channel": "vc1"}))
await _said(ws, "100", 0.9)
await ws.send(json.dumps({"type": "tts", "id": "r1", "text": "디스코드 화면 공유가 보입니다.",
"more": False}))
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
await _said(ws, "200", 0.6)
await ws.send(json.dumps({"type": "voice_join", "channel": "vc2"})) # another channel
await _said(ws, "100", 0.9)
await ws.send(json.dumps({"type": "config", "context_chars": 0}))
await _said(ws, "100", 0.6)
asyncio.run(with_worker(body, transcriber=t, tts=FakeTts()))
assert t.contexts[0] == ""
assert t.contexts[1] == "level 0.9 디스코드 화면 공유가 보입니다."
assert t.contexts[2] == "", "a new channel starts without the old channel's conversation"
assert t.contexts[3] == "", "context_chars 0 turns it off"