refac
This commit is contained in:
1 parent
40c09167cd
commit
bb1419328b
1 file changed
+7
-3
@@ -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):
|
async def _tts_elevenlabs(request, payload, file_path, file_body_path, user):
|
||||||
"""Generate speech via the ElevenLabs TTS API."""
|
"""Generate speech via the ElevenLabs TTS API."""
|
||||||
voice_id = payload.get('voice', '')
|
voice_id = (payload.get('voice') or '').strip()
|
||||||
if voice_id not in await get_available_voices(request):
|
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')
|
raise HTTPException(status_code=400, detail='Invalid voice id')
|
||||||
|
|
||||||
r = None
|
r = None
|
||||||
@@ -1344,7 +1348,7 @@ async def get_available_voices(request) -> dict:
|
|||||||
voices_data = await resp.json()
|
voices_data = await resp.json()
|
||||||
return {v['voice_id']: v['name'] for v in voices_data.get('voices', [])}
|
return {v['voice_id']: v['name'] for v in voices_data.get('voices', [])}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f'Error fetching ElevenLabs voices: {e}')
|
log.warning(f'Error fetching ElevenLabs voices: {e}')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if engine == 'azure':
|
if engine == 'azure':
|
||||||
|
|||||||
Reference in new issue
Block a user