mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-05 12:34:43 -04:00
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>
27 lines
984 B
Python
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
|