feat: optional speaker-diarization hook (diarize.py)#190
Open
seonghobae wants to merge 1 commit into
Open
Conversation
New standalone module following the repo's optional-AI pattern: dependency-free at import, injectable backend, lazy pyannote.audio import, and a clear DiarizationUnavailableError with install instructions when the optional dependency is missing. - SpeakerTurn / DiarizationResult / AttributedSegment dataclasses - diarize_file(audio_path, *, backend=None) with injectable backend - merge_with_transcript: pure max-overlap speaker assignment with SPEAKER_1 fallback for non-overlapping segments - to_text: renders '[speaker] text' lines - 21 offline tests (fake backend, sys.modules import block, overlap matrix, formatting) — no model download or network Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJRVbDrp1vGYkJgNHMGPpG
Contributor
OpenCode Review Overview
Changed-File Evidence Mapflowchart LR
PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
Evidence --> S1["Changed file: diarize.py"]
S1 --> I1["repository behavior"]
I1 --> R1["Review risk: Changed file: diarize.py"]
R1 --> V1["required checks"]
Evidence --> S2["Test: test_diarize.py"]
S2 --> I2["regression suite"]
I2 --> R2["Review risk: Test: test_diarize.py"]
R2 --> V2["targeted test run"]
|
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
Adds an optional speaker-diarization hook (
diarize.py) — a new standalone module that answers "who spoke when?" for an audio file and attributes transcript segments to speakers. It follows the repo's optional-AI pattern: zero heavy dependencies at import, an injectable backend, lazypyannote.audioimport, and a graceful, actionable error when the optional dependency is missing.What's included
SpeakerTurn(start, end, speaker)andDiarizationResult(turns, speaker_count)dataclassesDiarizationUnavailableErrorraised withpip install pyannote.audioinstructions (and a pointer to the injectable-backend escape hatch) when the optional dependency is absentdiarize_file(audio_path, *, backend=None)— default backend lazily importspyannote.audioinside the function; any callable mapping a path to speaker turns can be injected insteadmerge_with_transcript(turns, segments)— pure function assigning each duck-typed segment (.start/.end/.text) the speaker with maximum accumulated time overlap, falling back toSPEAKER_1when nothing overlapsto_text(merged)— renders[speaker] textlinesTests
tests/test_diarize.py— 21 tests, all offline (no model download, no network):sys.modulespatch: error type, actionable message,ImportErrorchainingto_textformatting including merge round-tripGates
python3.14 -m unittest discover -s tests: 134 tests, no new failures (only the 5 pre-existing macOSos.listxattrbaseline errors)python3.14 -m interrogate -c pyproject.toml diarize.py: 100%🤖 Generated with Claude Code