From 05aa9c6d9c64329379b3a4081450414ba24f49ba Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 10 Apr 2025 12:27:11 -0700 Subject: [PATCH] refac --- backend/open_webui/routers/audio.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index f29a65358..aaac94681 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -68,7 +68,7 @@ from pydub import AudioSegment from pydub.utils import mediainfo -def audio_needs_conversion(file_path): +def get_audio_format(file_path): """Check if the given file needs to be converted to a different format.""" if not os.path.isfile(file_path): log.error(f"File not found: {file_path}") @@ -500,14 +500,14 @@ def transcribe(request: Request, file_path): log.debug(data) return data elif request.app.state.config.STT_ENGINE == "openai": - conversion_type = audio_needs_conversion(file_path) - if conversion_type: - os.rename(file_path, file_path.replace(".wav", f".{conversion_type}")) + audio_format = get_audio_format(file_path) + if audio_format: + os.rename(file_path, file_path.replace(".wav", f".{audio_format}")) # Convert unsupported audio file to WAV format convert_audio_to_wav( - file_path.replace(".wav", f".{conversion_type}"), + file_path.replace(".wav", f".{audio_format}"), file_path, - conversion_type, + audio_format, ) r = None