Add real-time speaker diarization support

- New whisper_live/diarization.py: SpeakerDiarizer with online clustering
- Uses pyannote.audio speaker embeddings (optional dependency)
- Cosine similarity threshold for speaker matching (default 0.55)
- Running average embedding update for speaker stability
- Configurable max_speakers limit (default 10)
- Client options: enable_diarization, max_speakers
- Segments include 'speaker' field when diarization is active
- Graceful fallback: logs warning if pyannote not installed
- Added 12 unit tests (mock-based, no GPU required)
This commit is contained in:
Aaron Boxer
2026-04-17 10:25:10 -04:00
committed by Aaron Boxer
parent 3d63e82571
commit 18b897277f
7 changed files with 364 additions and 6 deletions
+20
View File
@@ -292,6 +292,7 @@ class TranscriptionServer:
cache_path=self.cache_path,
translation_queue=translation_queue,
hotwords=options.get("hotwords"),
diarization=self._create_diarizer(options),
)
logging.info("Running faster_whisper backend.")
@@ -320,6 +321,25 @@ class TranscriptionServer:
self.client_manager.add_client(websocket, client)
def _create_diarizer(self, options):
"""Create a SpeakerDiarizer if the client requested diarization.
Returns:
SpeakerDiarizer or None
"""
if not options.get("enable_diarization", False):
return None
try:
from whisper_live.diarization import SpeakerDiarizer
return SpeakerDiarizer(
similarity_threshold=options.get("diarization_threshold", 0.55),
max_speakers=options.get("max_speakers", 10),
hf_token=options.get("hf_token"),
)
except ImportError:
logging.warning("pyannote.audio not installed; diarization disabled")
return None
def get_audio_from_websocket(self, websocket):
"""
Receives audio buffer from websocket and creates a numpy array out of it.