marks
commited on
Commit
·
45c0e10
1
Parent(s):
8c7facc
Removed await operation
Browse files- api_clients.py +7 -56
- app.py +2 -1
api_clients.py
CHANGED
|
@@ -107,66 +107,17 @@ class OpenRouterClient:
|
|
| 107 |
raise
|
| 108 |
|
| 109 |
class ElevenLabsClient:
|
| 110 |
-
"""Handles ElevenLabs API interactions with detailed performance tracking"""
|
| 111 |
-
|
| 112 |
def __init__(self, api_key: str):
|
| 113 |
-
logger.info("Initializing ElevenLabs client")
|
| 114 |
self.api_key = api_key
|
| 115 |
-
elevenlabs.set_api_key(api_key)
|
| 116 |
-
|
| 117 |
-
@property
|
| 118 |
-
def api_key(self):
|
| 119 |
-
return self._api_key
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
self._api_key = value
|
| 127 |
-
elevenlabs.set_api_key(value)
|
| 128 |
-
logger.info("ElevenLabs API key updated successfully")
|
| 129 |
-
# Clear cached voices when API key changes
|
| 130 |
-
self.get_voices.cache_clear()
|
| 131 |
-
|
| 132 |
-
@lru_cache(maxsize=1)
|
| 133 |
-
async def get_voices(self) -> List[Tuple[str, str]]:
|
| 134 |
-
"""
|
| 135 |
-
Fetch available voices from ElevenLabs
|
| 136 |
-
|
| 137 |
-
Returns:
|
| 138 |
-
List of tuples containing (voice_id, display_name)
|
| 139 |
-
where display_name includes voice description if available
|
| 140 |
-
"""
|
| 141 |
-
logger.info("Fetching available voices from ElevenLabs")
|
| 142 |
-
try:
|
| 143 |
-
voices = await elevenlabs.voices() # Assuming elevenlabs supports async
|
| 144 |
-
logger.info(f"Successfully fetched {len(voices)} voices")
|
| 145 |
-
|
| 146 |
-
voice_list = []
|
| 147 |
-
for voice in voices:
|
| 148 |
-
# Create descriptive name including accent and age if available
|
| 149 |
-
description = f"{voice.name}"
|
| 150 |
-
if hasattr(voice, 'labels') and voice.labels:
|
| 151 |
-
if 'accent' in voice.labels:
|
| 152 |
-
description += f" ({voice.labels['accent']})"
|
| 153 |
-
if 'age' in voice.labels:
|
| 154 |
-
description += f", {voice.labels['age']}"
|
| 155 |
-
voice_list.append((voice.voice_id, description))
|
| 156 |
-
|
| 157 |
-
logger.debug(f"Available voices: {[name for _, name in voice_list]}")
|
| 158 |
-
return voice_list
|
| 159 |
-
except Exception as e:
|
| 160 |
-
logger.error("Failed to fetch voices", exc_info=True)
|
| 161 |
-
raise
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
"""
|
| 166 |
-
Generate audio with comprehensive error handling and quality checks
|
| 167 |
-
|
| 168 |
-
Logs detailed metrics about the input text and resulting audio.
|
| 169 |
-
"""
|
| 170 |
logger.info(f"Starting audio generation with voice: {voice_id}")
|
| 171 |
logger.debug(f"Input text length: {len(text)} chars")
|
| 172 |
|
|
|
|
| 107 |
raise
|
| 108 |
|
| 109 |
class ElevenLabsClient:
|
|
|
|
|
|
|
| 110 |
def __init__(self, api_key: str):
|
|
|
|
| 111 |
self.api_key = api_key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
def get_voices(self):
|
| 114 |
+
"""Synchronously get available voices"""
|
| 115 |
+
# Implement the actual API call to ElevenLabs here
|
| 116 |
+
# Return list of voices
|
| 117 |
+
return [] # Replace with actual implementation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
async def generate_audio(self, text: str, voice_id: str):
|
| 120 |
+
"""Asynchronously generate audio"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
logger.info(f"Starting audio generation with voice: {voice_id}")
|
| 122 |
logger.debug(f"Input text length: {len(text)} chars")
|
| 123 |
|
app.py
CHANGED
|
@@ -24,7 +24,8 @@ class PodcasterUI:
|
|
| 24 |
"""Initialize API clients and fetch models/voices"""
|
| 25 |
try:
|
| 26 |
self.models = await self.router_client.get_models()
|
| 27 |
-
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
logger.error("Failed to initialize API clients", exc_info=True)
|
| 30 |
raise
|
|
|
|
| 24 |
"""Initialize API clients and fetch models/voices"""
|
| 25 |
try:
|
| 26 |
self.models = await self.router_client.get_models()
|
| 27 |
+
# Since get_voices() might not be async, remove await
|
| 28 |
+
self.voices = self.elevenlabs_client.get_voices()
|
| 29 |
except Exception as e:
|
| 30 |
logger.error("Failed to initialize API clients", exc_info=True)
|
| 31 |
raise
|