Files
LocalAI/backend/python/whisperx/transcript_utils.py
T
Stefan Walcz 985df46d24 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>
2026-10-02 09:18:12 +02:00

27 lines
984 B
Python

"""Helpers for WhisperX transcript responses."""
def require_diarization_token(diarize, token):
"""Reject diarization when WhisperX cannot load its gated pipeline."""
if diarize and not token:
raise ValueError("HF_TOKEN is required for WhisperX diarization")
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