feat(voice_worker): free a speaker's place when they leave the voice channel

- New speaker_leave message: ends the speaker's open utterance (its final is still sent) and drops
  their state, so a long session never hits the 32-speaker limit as people come and go.
- Spec and test cover more than 32 speakers in one session, each leaving mid-utterance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 11:14:25 +09:00
parent 1309525aa8
commit 5838f9edd8
3 changed files with 40 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ token closes with 4401.
```
-> binary 0x01 | u8 n | speaker id (n bytes UTF-8) | PCM16LE samples in the hello "audio" format
-> {"type": "speaking_end", "speaker": "..."} // Discord speaking stopped for this speaker
-> {"type": "speaker_leave", "speaker": "..."} // the speaker left the voice channel
-> {"type": "config", ...any STT settings...} // takes effect immediately
<- {"type": "speech_start", "speaker": "...", "utt": 3}
<- {"type": "partial", "speaker": "...", "utt": 3, "text": "..."}
@@ -61,6 +62,10 @@ token closes with 4401.
"audio_ms": 2310, "wait_ms": 160, "stt_ms": 120}
```
`speaker_leave` ends an open utterance as `speaking_end` does (its final is still sent) and frees the
speaker's state. A session holds at most 32 speakers at once, so the app sends it whenever someone
leaves; a speaker who comes back starts again at `utt` 1.
`utt` counts utterances per speaker. `final` always closes an utterance that sent `speech_start`, even
when the text is empty (noise that Whisper rejected). `wait_ms` is from the moment the end was decided
to the moment the final was sent; `stt_ms` is the model time of the batch it went through.
@@ -179,6 +184,6 @@ never close the connection after the handshake.
## Debug logging
`debug_log(..., "voice_worker")` at: connection accepted or refused, settings changed, utterance end
`debug_log(..., "voice_worker")` at: connection accepted or refused, settings changed, speaker left, utterance end
(speaker, reason, length), each STT batch (kind, size, model time), each TTS sentence (length, time),
cancel, and engine failures.