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

@@ -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"