Skip to content

Commit 715cf97

Browse files
committed
refac
1 parent 8979987 commit 715cf97

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

backend/open_webui/env.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,11 @@ def parse_section(section):
517517

518518
BYPASS_MODEL_ACCESS_CONTROL = os.environ.get('BYPASS_MODEL_ACCESS_CONTROL', 'False').lower() == 'true'
519519

520+
# When enabled, skips pydub-based preprocessing (format conversion, compression,
521+
# and chunked splitting) before sending files to processing engines. Useful when
522+
# the upstream provider handles these steps or when ffmpeg is unavailable.
523+
BYPASS_PYDUB_PREPROCESSING = os.environ.get('BYPASS_PYDUB_PREPROCESSING', 'False').lower() == 'true'
524+
520525
# When disabled (default), the OpenAI catch-all proxy endpoint (/{path:path})
521526
# is blocked. Enable only if you need direct passthrough to upstream OpenAI-
522527
# compatible APIs for endpoints not natively handled by Open WebUI.

backend/open_webui/routers/audio.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
AIOHTTP_CLIENT_SESSION_SSL,
5555
AIOHTTP_CLIENT_TIMEOUT,
5656
AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST,
57+
BYPASS_PYDUB_PREPROCESSING,
5758
DEVICE_TYPE,
5859
ENABLE_FORWARD_USER_INFO_HEADERS,
5960
)
@@ -1098,24 +1099,28 @@ def transcription_handler(request, file_path, metadata, user=None):
10981099
def transcribe(request: Request, file_path: str, metadata: Optional[dict] = None, user=None):
10991100
log.info(f'transcribe: {file_path} {metadata}')
11001101

1101-
if is_audio_conversion_required(file_path):
1102-
file_path = convert_audio_to_mp3(file_path)
1102+
if BYPASS_PYDUB_PREPROCESSING:
1103+
log.info('Bypassing pydub preprocessing (BYPASS_PYDUB_PREPROCESSING=true)')
1104+
chunk_paths = [file_path]
1105+
else:
1106+
if is_audio_conversion_required(file_path):
1107+
file_path = convert_audio_to_mp3(file_path)
11031108

1104-
try:
1105-
file_path = compress_audio(file_path)
1106-
except Exception as e:
1107-
log.exception(e)
1109+
try:
1110+
file_path = compress_audio(file_path)
1111+
except Exception as e:
1112+
log.exception(e)
11081113

1109-
# Always produce a list of chunk paths (could be one entry if small)
1110-
try:
1111-
chunk_paths = split_audio(file_path, MAX_FILE_SIZE)
1112-
print(f'Chunk paths: {chunk_paths}')
1113-
except Exception as e:
1114-
log.exception(e)
1115-
raise HTTPException(
1116-
status_code=status.HTTP_400_BAD_REQUEST,
1117-
detail=ERROR_MESSAGES.DEFAULT(e),
1118-
)
1114+
# Always produce a list of chunk paths (could be one entry if small)
1115+
try:
1116+
chunk_paths = split_audio(file_path, MAX_FILE_SIZE)
1117+
print(f'Chunk paths: {chunk_paths}')
1118+
except Exception as e:
1119+
log.exception(e)
1120+
raise HTTPException(
1121+
status_code=status.HTTP_400_BAD_REQUEST,
1122+
detail=ERROR_MESSAGES.DEFAULT(e),
1123+
)
11191124

11201125
results = []
11211126
try:

0 commit comments

Comments
 (0)