Spaces:
Paused
Paused
bravedims commited on
Commit ·
dd21570
1
Parent(s): f63a9e3
Fix ElevenLabs API issues and improve error handling
Browse files- Remove hardcoded API key and add proper validation
- Improve voice ID handling and logging
- Add detailed error messages and traceback logging
- Add API key validation before making TTS calls
- This should fix the 'Voice ID: (empty)' and 'Error generating speech:' issues
app.py
CHANGED
|
@@ -57,7 +57,9 @@ class GenerateResponse(BaseModel):
|
|
| 57 |
|
| 58 |
class ElevenLabsClient:
|
| 59 |
def __init__(self, api_key: str = None):
|
| 60 |
-
self.api_key = api_key or os.getenv("ELEVENLABS_API_KEY"
|
|
|
|
|
|
|
| 61 |
self.base_url = "https://api.elevenlabs.io/v1"
|
| 62 |
|
| 63 |
async def text_to_speech(self, text: str, voice_id: str = "21m00Tcm4TlvDq8ikWAM") -> str:
|
|
@@ -103,7 +105,10 @@ class ElevenLabsClient:
|
|
| 103 |
logger.error(f"Network error calling ElevenLabs: {e}")
|
| 104 |
raise HTTPException(status_code=400, detail=f"Network error calling ElevenLabs: {e}")
|
| 105 |
except Exception as e:
|
| 106 |
-
logger.error(f"Error generating speech: {e}")
|
|
|
|
|
|
|
|
|
|
| 107 |
raise HTTPException(status_code=500, detail=f"Error generating speech: {e}")
|
| 108 |
|
| 109 |
class OmniAvatarAPI:
|
|
@@ -195,10 +200,16 @@ class OmniAvatarAPI:
|
|
| 195 |
|
| 196 |
if request.text_to_speech:
|
| 197 |
# Generate speech from text using ElevenLabs
|
|
|
|
| 198 |
logger.info(f"Generating speech from text: {request.text_to_speech[:50]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
audio_path = await self.elevenlabs_client.text_to_speech(
|
| 200 |
request.text_to_speech,
|
| 201 |
-
|
| 202 |
)
|
| 203 |
audio_generated = True
|
| 204 |
|
|
@@ -480,3 +491,4 @@ app = gr.mount_gradio_app(app, iface, path="/gradio")
|
|
| 480 |
if __name__ == "__main__":
|
| 481 |
import uvicorn
|
| 482 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
| 57 |
|
| 58 |
class ElevenLabsClient:
|
| 59 |
def __init__(self, api_key: str = None):
|
| 60 |
+
self.api_key = api_key or os.getenv("ELEVENLABS_API_KEY")
|
| 61 |
+
if not self.api_key:
|
| 62 |
+
logger.warning("No ElevenLabs API key found. Text-to-speech will not work.")
|
| 63 |
self.base_url = "https://api.elevenlabs.io/v1"
|
| 64 |
|
| 65 |
async def text_to_speech(self, text: str, voice_id: str = "21m00Tcm4TlvDq8ikWAM") -> str:
|
|
|
|
| 105 |
logger.error(f"Network error calling ElevenLabs: {e}")
|
| 106 |
raise HTTPException(status_code=400, detail=f"Network error calling ElevenLabs: {e}")
|
| 107 |
except Exception as e:
|
| 108 |
+
logger.error(f"Error generating speech: {str(e)}")
|
| 109 |
+
logger.error(f"Exception type: {type(e).__name__}")
|
| 110 |
+
import traceback
|
| 111 |
+
logger.error(f"Traceback: {traceback.format_exc()}")
|
| 112 |
raise HTTPException(status_code=500, detail=f"Error generating speech: {e}")
|
| 113 |
|
| 114 |
class OmniAvatarAPI:
|
|
|
|
| 200 |
|
| 201 |
if request.text_to_speech:
|
| 202 |
# Generate speech from text using ElevenLabs
|
| 203 |
+
voice_id = request.voice_id or "21m00Tcm4TlvDq8ikWAM"
|
| 204 |
logger.info(f"Generating speech from text: {request.text_to_speech[:50]}...")
|
| 205 |
+
logger.info(f"Using voice ID: {voice_id}")
|
| 206 |
+
|
| 207 |
+
if not self.elevenlabs_client.api_key:
|
| 208 |
+
raise HTTPException(status_code=503, detail="ElevenLabs API key not configured")
|
| 209 |
+
|
| 210 |
audio_path = await self.elevenlabs_client.text_to_speech(
|
| 211 |
request.text_to_speech,
|
| 212 |
+
voice_id
|
| 213 |
)
|
| 214 |
audio_generated = True
|
| 215 |
|
|
|
|
| 491 |
if __name__ == "__main__":
|
| 492 |
import uvicorn
|
| 493 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 494 |
+
|