From 76db75f5b51b5d066ce7d010701769ea49b555e4 Mon Sep 17 00:00:00 2001 From: Raivis Dejus Date: Fri, 4 Oct 2024 11:24:13 +0300 Subject: [PATCH] Fix for ffmpeg return code false positive errors --- whisper/audio.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/whisper/audio.py b/whisper/audio.py index cf6c66ad9..2ef9824e7 100644 --- a/whisper/audio.py +++ b/whisper/audio.py @@ -51,15 +51,16 @@ def load_audio(file: str, sr: int = SAMPLE_RATE): "-ac", "1", "-acodec", "pcm_s16le", "-ar", str(sr), + "-loglevel", "error", "-" ] # fmt: on - try: - out = run(cmd, capture_output=True, check=True).stdout - except CalledProcessError as e: - raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e + result = run(cmd, capture_output=True) - return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0 + if len(result.stderr): + raise RuntimeError(f"Failed to load audio: {result.stderr.decode()}") + + return np.frombuffer(result.stdout, np.int16).flatten().astype(np.float32) / 32768.0 def pad_or_trim(array, length: int = N_SAMPLES, *, axis: int = -1):