From bb1419328b11b801b4c939dfc112700ba6f6fdab Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 16 Jun 2026 23:30:24 +0200 Subject: [PATCH] refac --- backend/open_webui/routers/audio.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index 441915972d..d6d3c36273 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -429,8 +429,12 @@ async def _tts_openai(request, payload, file_path, file_body_path, user): async def _tts_elevenlabs(request, payload, file_path, file_body_path, user): """Generate speech via the ElevenLabs TTS API.""" - voice_id = payload.get('voice', '') - if voice_id not in await get_available_voices(request): + voice_id = (payload.get('voice') or '').strip() + if not voice_id: + raise HTTPException(status_code=400, detail='Invalid voice id') + + available_voices = await get_available_voices(request) + if available_voices and voice_id not in available_voices: raise HTTPException(status_code=400, detail='Invalid voice id') r = None @@ -1344,7 +1348,7 @@ async def get_available_voices(request) -> dict: voices_data = await resp.json() return {v['voice_id']: v['name'] for v in voices_data.get('voices', [])} except Exception as e: - log.error(f'Error fetching ElevenLabs voices: {e}') + log.warning(f'Error fetching ElevenLabs voices: {e}') return {} if engine == 'azure':