From 0e46df7111817465e669d4dcf9302e3c254506d8 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Sat, 6 Jul 2024 14:40:54 -0600 Subject: [PATCH] Update subgen.py Try to convert a file to 16khz if encode = true. --- subgen.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subgen.py b/subgen.py index 40ddb8b..8ede8e9 100644 --- a/subgen.py +++ b/subgen.py @@ -438,8 +438,10 @@ def asr( task_id = { 'path': f"Bazarr-asr-{random_name}" } task_queue.put(task_id) - - audio_data = np.frombuffer(audio_file.file.read(), np.int16).flatten().astype(np.float32) / 32768.0 + + audio_data = (np.concatenate([av.audio.resampler.AudioResampler(format='s16', layout='mono', rate=16000).resample(frame).to_ndarray().flatten() for frame in av.open(audio_file.file).decode(audio=0)]).astype(np.float32) / 32768.0) if encode else np.frombuffer(audio_file.file.read(), np.int16).flatten().astype(np.float32) / 32768.0 + + #audio_data = np.frombuffer(audio_file.file.read(), np.int16).flatten().astype(np.float32) / 32768.0 if model_prompt: custom_prompt = greetings_translations.get(language, '') or custom_model_prompt if custom_regroup: