Spaces:
Paused
Paused
Update tts_elevenlabs.py
Browse files- tts_elevenlabs.py +6 -5
tts_elevenlabs.py
CHANGED
|
@@ -4,6 +4,7 @@ ElevenLabs TTS Implementation
|
|
| 4 |
import httpx
|
| 5 |
from typing import Optional, Dict
|
| 6 |
from tts_interface import TTSInterface, log
|
|
|
|
| 7 |
|
| 8 |
class ElevenLabsTTS(TTSInterface):
|
| 9 |
"""ElevenLabs TTS implementation"""
|
|
@@ -25,7 +26,7 @@ class ElevenLabsTTS(TTSInterface):
|
|
| 25 |
|
| 26 |
# Debug log
|
| 27 |
masked_key = f"{api_key[:4]}...{api_key[-4:]}" if len(api_key) > 8 else "***"
|
| 28 |
-
|
| 29 |
|
| 30 |
async def synthesize(self, text: str, voice_id: Optional[str] = None, **kwargs) -> bytes:
|
| 31 |
"""Convert text to speech using ElevenLabs API"""
|
|
@@ -57,7 +58,7 @@ class ElevenLabsTTS(TTSInterface):
|
|
| 57 |
else:
|
| 58 |
params = {"output_format": "mp3_44100_128"}
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 63 |
response = await client.post(
|
|
@@ -70,14 +71,14 @@ class ElevenLabsTTS(TTSInterface):
|
|
| 70 |
response.raise_for_status()
|
| 71 |
audio_data = response.content
|
| 72 |
|
| 73 |
-
|
| 74 |
return audio_data
|
| 75 |
|
| 76 |
except httpx.HTTPStatusError as e:
|
| 77 |
-
|
| 78 |
raise
|
| 79 |
except Exception as e:
|
| 80 |
-
|
| 81 |
raise
|
| 82 |
|
| 83 |
def get_supported_voices(self) -> Dict[str, str]:
|
|
|
|
| 4 |
import httpx
|
| 5 |
from typing import Optional, Dict
|
| 6 |
from tts_interface import TTSInterface, log
|
| 7 |
+
from logger import log_info, log_error, log_debug, log_warning
|
| 8 |
|
| 9 |
class ElevenLabsTTS(TTSInterface):
|
| 10 |
"""ElevenLabs TTS implementation"""
|
|
|
|
| 26 |
|
| 27 |
# Debug log
|
| 28 |
masked_key = f"{api_key[:4]}...{api_key[-4:]}" if len(api_key) > 8 else "***"
|
| 29 |
+
log_debug(f"π ElevenLabsTTS initialized with key: {masked_key}")
|
| 30 |
|
| 31 |
async def synthesize(self, text: str, voice_id: Optional[str] = None, **kwargs) -> bytes:
|
| 32 |
"""Convert text to speech using ElevenLabs API"""
|
|
|
|
| 58 |
else:
|
| 59 |
params = {"output_format": "mp3_44100_128"}
|
| 60 |
|
| 61 |
+
log_degub(f"π€ Calling ElevenLabs TTS for {len(text)} characters")
|
| 62 |
|
| 63 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 64 |
response = await client.post(
|
|
|
|
| 71 |
response.raise_for_status()
|
| 72 |
audio_data = response.content
|
| 73 |
|
| 74 |
+
log_debug(f"β
ElevenLabs TTS returned {len(audio_data)} bytes")
|
| 75 |
return audio_data
|
| 76 |
|
| 77 |
except httpx.HTTPStatusError as e:
|
| 78 |
+
log_error(f"β ElevenLabs API error: {e.response.status_code} - {e.response.text}")
|
| 79 |
raise
|
| 80 |
except Exception as e:
|
| 81 |
+
log_error("β TTS synthesis error", e)
|
| 82 |
raise
|
| 83 |
|
| 84 |
def get_supported_voices(self) -> Dict[str, str]:
|