fix: propagate ElevenLabs voice fetch errors to frontend
- elevenlabs_voices.py: re-raise exception on first fetch failure (empty cache) instead of silently returning empty list - routes_tts.py: catch get_voices() exception and return available=False with the error detail; add optional error field to ProviderVoicesResponse - VoiceSelector: show actual API error message when available=false Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a22fe5c1bc
commit
222826baa7
4 changed files with 18 additions and 4 deletions
|
|
@ -49,6 +49,7 @@ class ProviderVoicesResponse(BaseModel):
|
|||
voices: list[VoiceInfo]
|
||||
default: str
|
||||
available: bool = True
|
||||
error: Optional[str] = None
|
||||
|
||||
|
||||
class LanguagesResponse(BaseModel):
|
||||
|
|
@ -107,7 +108,17 @@ async def list_voices(
|
|||
default="",
|
||||
available=False,
|
||||
)
|
||||
el_voices = await elevenlabs_voice_service.get_voices()
|
||||
try:
|
||||
el_voices = await elevenlabs_voice_service.get_voices()
|
||||
except Exception as e:
|
||||
logger.warning(f"ElevenLabs get_voices failed: {e}")
|
||||
return ProviderVoicesResponse(
|
||||
provider="elevenlabs",
|
||||
voices=[],
|
||||
default="",
|
||||
available=False,
|
||||
error=str(e),
|
||||
)
|
||||
voices = [
|
||||
VoiceInfo(
|
||||
id=v.voice_id,
|
||||
|
|
|
|||
|
|
@ -56,8 +56,10 @@ class ElevenLabsVoiceService:
|
|||
logger.info(f"Fetched {len(voices)} voices from ElevenLabs API")
|
||||
return voices
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch ElevenLabs voices, using stale cache: {e}")
|
||||
return self._cache # Stale cache fallback
|
||||
if self._cache:
|
||||
logger.warning(f"Failed to fetch ElevenLabs voices, using stale cache: {e}")
|
||||
return self._cache
|
||||
raise
|
||||
|
||||
async def _fetch_voices(self) -> list[ElevenLabsVoice]:
|
||||
"""Fetch voices from the ElevenLabs API."""
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export function VoiceSelector({
|
|||
|
||||
// Set default voice from API response if switching providers
|
||||
if (voicesData.available === false) {
|
||||
setError(`ElevenLabs TTS is not configured on the server. Contact your administrator to set up the ELEVENLABS_API_KEY.`);
|
||||
setError(voicesData.error || 'ElevenLabs TTS is not configured on the server. Contact your administrator to set up the ELEVENLABS_API_KEY.');
|
||||
} else if (voicesData.default && voicesData.voices.length > 0) {
|
||||
// Only reset default voice if the current one isn't in the new voice list
|
||||
const currentVoiceExists = voicesData.voices.some(v => v.id === preferences.default_voice);
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ export interface ProviderVoicesResponse {
|
|||
voices: VoiceInfo[];
|
||||
default: string;
|
||||
available?: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** @deprecated Use ProviderVoicesResponse instead */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue