feat: reconcile speaker identities through OpenRouter audio
Short chunk overlaps often contain only one participant, so returning speakers receive new transcript IDs. MAI can also split one voice into several IDs within a single request, which overlap stitching cannot fix. Add an opt-in audio comparison pass: --speakers N selects Gemini 3.8 Flash with a known count, and --speaker-model allows another compatible model. Keep request-local identities separate, select up to three clean excerpts per ID, and compare all excerpts in one OpenRouter request. Gemini uses Google AI Studio because the Vertex backend limits prompts to one audio file. No local model or extra Python dependency is required. Only reconcile identities whose sample assignments agree. Preserve uncertain identities separately, reject incomplete or malformed replies, and retain the original words and timestamps. Bound sample count and request size, clip sampling to the real audio duration, and extend worker cleanup and buffered output to the comparison step. Document the sampled method's limitations and additional provider request. Test Plan: - python3 -B -m unittest -v: all 82 tests passed, including real MP3 encoding with fake transcription/comparison responses and cancellation. - bash -n transcribe: passed. - git diff --cached --check: passed. - Live API and voice accuracy unverified: this workspace could not access the configured 1Password credential. Mocked responses prove pipeline behavior, not model accuracy on the supplied recording.
This commit is contained in:
1 parent
1d03dcd587
commit
138c796399
9 files changed
+988
-19
No files matched your search
@@ -118,6 +118,22 @@ class ChunkMergeTests(unittest.TestCase):
|
||||
result = stitch(left, right, 10)
|
||||
self.assertEqual([w["word"] for w in result], ["before", "boundary,", "after", "later"])
|
||||
|
||||
def test_scoped_speakers_keep_shared_words_but_defer_identity_to_audio(self):
|
||||
chunks = [{"start": 0, "end": 63, "seam": 0},
|
||||
{"start": 57, "end": 100, "seam": 60}]
|
||||
responses = [
|
||||
{"words": [dict(word(text, start), speaker=0) for text, start in
|
||||
(("First", 1), ("shared", 59), ("words", 60))]},
|
||||
{"words": [dict(word(text, start), speaker=0) for text, start in
|
||||
(("shared", 2), ("words", 3), ("Last", 20))]},
|
||||
]
|
||||
with contextlib.redirect_stderr(io.StringIO()) as errors:
|
||||
result = merge(chunks, responses, scope_speakers=True)
|
||||
self.assertEqual(result["text"], "First shared words Last")
|
||||
self.assertEqual({w["speaker"] for w in result["words"]}, {0, 1})
|
||||
self.assertNotEqual(result["words"][0]["speaker"], result["words"][-1]["speaker"])
|
||||
self.assertEqual(errors.getvalue(), "")
|
||||
|
||||
def test_words_cut_at_upload_edges_are_discarded(self):
|
||||
left = [word("Before", 5), word("shared", 9), word("words", 10), word("incom-", 12.8)]
|
||||
right = [word("-fore", 7), word("shared", 9.1), word("words", 10.1), word("incomplete", 12.6)]
|
||||
|
||||
Reference in new issue
Block a user