feat(voice): in a game, partial transcription waits while an answer is written

- the app's ready message says whether the game stage runs (llm ready game=true); the worker then
  holds partial passes while a reply is being written and runs them again, the newest audio per
  speaker, when no answer is; finals never wait; without a game nothing changes
- M0 gamemode_tune decision: the game placement answered 1.7 times faster with partials held
  (64.9 against 37.5 tok/s with a partial pass every 2 s)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-14 10:58:11 +09:00
parent 5316f4e9b0
commit 3d58cf8ab1
8 changed files with 138 additions and 20 deletions

View File

@@ -47,8 +47,11 @@ class _Job:
class SttScheduler:
def __init__(self, transcriber: Transcriber, max_batch: int = 16, max_partial_batch: int = 2):
def __init__(self, transcriber: Transcriber, max_batch: int = 16, max_partial_batch: int = 2,
partials_held: Callable[[], bool] = lambda: False):
self.transcriber = transcriber
# While this says so (an answer is written in a game), partial passes wait; finals never do.
self.partials_held = partials_held
self.max_batch = max_batch
# Whisper's encoder always runs on a 30 s window, so its cost grows with every clip in a batch
# and batching saves little. A small partial batch bounds how long a final can wait behind one.
@@ -80,6 +83,10 @@ class SttScheduler:
self._partials[key] = _Job(key, audio, opts, callback)
self._wake.set()
def wake(self) -> None:
"""Look again (partials are no longer held)."""
self._wake.set()
def drop_partials(self, predicate: Callable[[Hashable], bool]) -> None:
for key in [k for k in self._partials if predicate(k)]:
del self._partials[key]
@@ -87,7 +94,7 @@ class SttScheduler:
def _take(self) -> tuple[str, list[_Job]]:
if self._finals:
kind, pool = "final", self._finals
elif self._partials:
elif self._partials and not self.partials_held():
kind, pool = "partial", list(self._partials.values())
else:
return "", []