Spaces:
Running
Running
bigwolfeman
commited on
Commit
Β·
2c1905d
1
Parent(s):
b5f2489
tts logging
Browse files- frontend/src/services/tts.ts +8 -1
- test_elevenlabs_key.py +60 -0
frontend/src/services/tts.ts
CHANGED
|
@@ -28,7 +28,14 @@ export async function synthesizeTts(text: string, options: TtsOptions = {}): Pro
|
|
| 28 |
let message = `TTS failed (HTTP ${response.status})`;
|
| 29 |
try {
|
| 30 |
const data = await response.json();
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
} catch {
|
| 33 |
// ignore parse errors
|
| 34 |
}
|
|
|
|
| 28 |
let message = `TTS failed (HTTP ${response.status})`;
|
| 29 |
try {
|
| 30 |
const data = await response.json();
|
| 31 |
+
// FastAPI HTTPException with detail dict returns: { detail: { error: "...", message: "..." } }
|
| 32 |
+
if (typeof data?.detail === 'object' && data.detail.message) {
|
| 33 |
+
message = data.detail.message;
|
| 34 |
+
} else if (typeof data?.detail === 'string') {
|
| 35 |
+
message = data.detail;
|
| 36 |
+
} else if (data?.message) {
|
| 37 |
+
message = data.message;
|
| 38 |
+
}
|
| 39 |
} catch {
|
| 40 |
// ignore parse errors
|
| 41 |
}
|
test_elevenlabs_key.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Test script to verify ElevenLabs API key."""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import httpx
|
| 6 |
+
|
| 7 |
+
# Read API key from environment
|
| 8 |
+
api_key = os.getenv("ELEVENLABS_API_KEY")
|
| 9 |
+
voice_id = os.getenv("ELEVENLABS_VOICE_ID", "21m00Tcm4TlvDq8ikWAM")
|
| 10 |
+
|
| 11 |
+
print("=" * 60)
|
| 12 |
+
print("ElevenLabs API Key Test")
|
| 13 |
+
print("=" * 60)
|
| 14 |
+
|
| 15 |
+
if not api_key:
|
| 16 |
+
print("β ELEVENLABS_API_KEY is not set!")
|
| 17 |
+
print("\nSet it with:")
|
| 18 |
+
print(" export ELEVENLABS_API_KEY='your-key-here'")
|
| 19 |
+
exit(1)
|
| 20 |
+
|
| 21 |
+
print(f"β API Key found: {api_key[:10]}...{api_key[-4:]}")
|
| 22 |
+
print(f"β Voice ID: {voice_id}")
|
| 23 |
+
print()
|
| 24 |
+
|
| 25 |
+
# Test API key by calling the voices endpoint (free endpoint)
|
| 26 |
+
print("Testing API key with /voices endpoint...")
|
| 27 |
+
try:
|
| 28 |
+
response = httpx.get(
|
| 29 |
+
"https://api.elevenlabs.io/v1/voices",
|
| 30 |
+
headers={"xi-api-key": api_key},
|
| 31 |
+
timeout=10.0
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if response.status_code == 200:
|
| 35 |
+
print("β
API key is VALID!")
|
| 36 |
+
data = response.json()
|
| 37 |
+
voices = data.get("voices", [])
|
| 38 |
+
print(f"\nYou have access to {len(voices)} voices:")
|
| 39 |
+
for voice in voices[:5]: # Show first 5
|
| 40 |
+
print(f" - {voice['name']}: {voice['voice_id']}")
|
| 41 |
+
if len(voices) > 5:
|
| 42 |
+
print(f" ... and {len(voices) - 5} more")
|
| 43 |
+
elif response.status_code == 401:
|
| 44 |
+
print("β API key is INVALID (401 Unauthorized)")
|
| 45 |
+
print("\nPossible reasons:")
|
| 46 |
+
print(" 1. The API key is incorrect or has a typo")
|
| 47 |
+
print(" 2. The API key has been revoked or expired")
|
| 48 |
+
print(" 3. You're using the wrong ElevenLabs account")
|
| 49 |
+
print("\nTo fix:")
|
| 50 |
+
print(" 1. Go to https://elevenlabs.io/app/settings/api-keys")
|
| 51 |
+
print(" 2. Generate a new API key")
|
| 52 |
+
print(" 3. Update ELEVENLABS_API_KEY in your .env or Space secrets")
|
| 53 |
+
else:
|
| 54 |
+
print(f"β οΈ Unexpected status code: {response.status_code}")
|
| 55 |
+
print(f"Response: {response.text[:200]}")
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"β Request failed: {e}")
|
| 59 |
+
|
| 60 |
+
print("=" * 60)
|