fix(whisperx): keep the transcript when diarization fails, report real errors (#12427)

AudioTranscription caught every exception and returned an empty
TranscriptResult. A failed diarization step therefore discarded a
transcript that was already finished: with an HF token that has not
accepted the terms of the gated pyannote pipeline, the download fails
with 403 and every transcription came back as an empty text with
HTTP 200.

Diarization now degrades: if it fails, the transcript is returned
without speaker labels and the reason is logged. Any other failure
aborts the call with INTERNAL instead of pretending success with an
empty text.

Assisted-by: Claude:claude-opus-5-5

Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
This commit is contained in:
Stefan Walcz authored and GitHub committed 2026-10-02 09:18:12 +02:00
1 parent 6aa7b9b871
commit 985df46d24
4 files changed
+46 -9

No files matched your search

@@ -10,3 +10,17 @@ def require_diarization_token(diarize, token):
def seconds_to_nanoseconds(seconds):
"""Convert WhisperX timestamps to the duration unit used by LocalAI."""
return int(seconds * 1_000_000_000)
def diarize_or_keep(transcript, diarize, log):
"""Run diarization; if it fails, keep the transcript without speakers.
Diarization is an add-on to a finished transcript. A refused download of
the gated pyannote pipeline (403) or any other diarization error must not
throw the transcript away.
"""
try:
return diarize(transcript)
except Exception as err: # noqa: BLE001 - any diarization failure degrades
log(f"Diarization failed, returning transcript without speakers: {err!r}")
return transcript