fix(stt): don't clear the primary speaker on an unattributed segment#6460
Open
chuenchen309 wants to merge 1 commit into
Open
fix(stt): don't clear the primary speaker on an unattributed segment#6460chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
`_update_primary_speaker` cleared `_primary_speaker` whenever a final
transcript arrived without a `speaker_id`, folding that case in with the
`detect_primary_speaker=False` case. Those are different situations: the
flag being off means "never track a primary", while a missing speaker_id
just means the diarizer couldn't attribute this one segment.
Clearing the primary matters because `None` is also the "no primary yet"
sentinel: the next attributed segment hits the `is it the first speaker?`
branch and is crowned without any loudness comparison. So a single
unattributed segment lets a quiet background speaker take over:
A speaks (loud) -> primary = A
unattributed segment -> primary = None
B speaks (60x quieter) -> primary = B # skips the RMS threshold
`on_stt_event` already guards `speaker_id is None` before using
`_primary_speaker`, so the segment itself was never going to be labelled
either way - the only effect of clearing was to lose the tracked state.
Leave the primary in place instead. The `detect_primary_speaker=False`
branch keeps its existing behaviour.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_PrimarySpeakerDetector._update_primary_speakerclears_primary_speakerwhenever a final transcript arrives without aspeaker_id, because that case is folded in withdetect_primary_speaker=False:Those are different situations. The flag being off means "never track a primary"; a missing
speaker_idjust means the diarizer couldn't attribute this one segment.Clearing matters because
Noneis also the "no primary yet" sentinel — the next attributed segment takes theit's the first speakerbranch and is crowned with no loudness comparison. One unattributed segment is enough to hand primary to a quiet background speaker:Aspeaker_id)NoneB— skipped the RMS thresholdWithout the unattributed segment in the middle, B is correctly rejected and A stays primary.
on_stt_eventalready guardsspeaker_id is Nonebefore touching_primary_speaker, so the unattributed segment was never going to be labelled either way — the only effect of clearing was losing the tracked state.Scope
The
detect_primary_speaker=Falsebranch keeps its current behaviour; only the missing-speaker_idpath changes. This is reachable throughMultiSpeakerAdapter(exported fromlivekit.agents.stt), which needs a diarization-capable STT — it has no in-repo callers, so nothing inside the framework changes.Testing
New
tests/test_multi_speaker_primary_speaker.py, three unit tests: the quiet-speaker control, the bug case, and thedetect_primary_speaker=Falsebehaviour. The bug test fails onmainand passes with this change; the other two pass on both. Existing stt tests (test_speaker_id_grouping,test_stt*) — 49 passed.ruff check/ruff formatclean;mypyreports the same 14 pre-existing errors in other files with and without this diff, none in the file I touched.Disclosure: written with Claude Code. I verified the reproduction, the reachability, and the test red/green myself.