diff --git a/backend/app/api/v1/routes_tts.py b/backend/app/api/v1/routes_tts.py index 11c07da..f148e2e 100644 --- a/backend/app/api/v1/routes_tts.py +++ b/backend/app/api/v1/routes_tts.py @@ -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, diff --git a/backend/app/services/elevenlabs_voices.py b/backend/app/services/elevenlabs_voices.py index e03e331..873821c 100644 --- a/backend/app/services/elevenlabs_voices.py +++ b/backend/app/services/elevenlabs_voices.py @@ -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.""" diff --git a/frontend/src/components/VoiceSelector.tsx b/frontend/src/components/VoiceSelector.tsx index 45fa9c6..c919219 100644 --- a/frontend/src/components/VoiceSelector.tsx +++ b/frontend/src/components/VoiceSelector.tsx @@ -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); diff --git a/frontend/src/types/api.ts b/frontend/src/types/api.ts index ca851a8..f03a788 100644 --- a/frontend/src/types/api.ts +++ b/frontend/src/types/api.ts @@ -86,6 +86,7 @@ export interface ProviderVoicesResponse { voices: VoiceInfo[]; default: string; available?: boolean; + error?: string; } /** @deprecated Use ProviderVoicesResponse instead */