From 1efa708f8325e77165f403c0a60e717752c5d7d5 Mon Sep 17 00:00:00 2001 From: nathaniel Date: Sun, 27 Apr 2025 05:58:06 +0100 Subject: [PATCH] Added WHISPER_LANGUAGE env variable. If set to a country's ISO2, constrains Whisper's stt to that language. Detects language as normal if unset --- backend/open_webui/config.py | 5 +++++ backend/open_webui/main.py | 2 ++ backend/open_webui/routers/audio.py | 1 + 3 files changed, 8 insertions(+) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 3b40977f2..04500411f 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -2510,6 +2510,11 @@ WHISPER_VAD_FILTER = PersistentConfig( os.getenv("WHISPER_VAD_FILTER", "False").lower() == "true", ) +WHISPER_LANGUAGE = PersistentConfig( + "WHISPER_LANGUAGE", + "audio.stt.whisper_language", + os.getenv("WHISPER_LANGUAGE", None).lower(), +) # Add Deepgram configuration DEEPGRAM_API_KEY = PersistentConfig( diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 56ea17fa1..3462661dd 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -167,6 +167,7 @@ from open_webui.config import ( WEB_LOADER_ENGINE, WHISPER_MODEL, WHISPER_VAD_FILTER, + WHISPER_LANGUAGE, DEEPGRAM_API_KEY, WHISPER_MODEL_AUTO_UPDATE, WHISPER_MODEL_DIR, @@ -791,6 +792,7 @@ app.state.config.STT_MODEL = AUDIO_STT_MODEL app.state.config.WHISPER_MODEL = WHISPER_MODEL app.state.config.WHISPER_VAD_FILTER = WHISPER_VAD_FILTER +app.state.config.WHISPER_LANGUAGE = WHISPER_LANGUAGE app.state.config.DEEPGRAM_API_KEY = DEEPGRAM_API_KEY app.state.config.AUDIO_STT_AZURE_API_KEY = AUDIO_STT_AZURE_API_KEY diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index da51d1ecf..c086aea00 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -501,6 +501,7 @@ def transcribe(request: Request, file_path): file_path, beam_size=5, vad_filter=request.app.state.config.WHISPER_VAD_FILTER, + language=request.app.state.config.WHISPER_LANGUAGE ) log.info( "Detected language '%s' with probability %f"