Spaces:
Sleeping
Sleeping
Update utils/text_to_speech.py
Browse files- utils/text_to_speech.py +22 -0
utils/text_to_speech.py
CHANGED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# genesis/utils/text_to_speech.py
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
|
5 |
+
ELEVEN_API_KEY = os.getenv("ELEVEN_LABS_API_KEY")
|
6 |
+
|
7 |
+
def elevenlabs_tts(text, voice_id="Bella", output_file="output.mp3"):
|
8 |
+
"""Convert text to speech using ElevenLabs."""
|
9 |
+
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
|
10 |
+
headers = {
|
11 |
+
"xi-api-key": ELEVEN_API_KEY,
|
12 |
+
"Content-Type": "application/json"
|
13 |
+
}
|
14 |
+
payload = {"text": text, "voice_settings": {"stability": 0.75, "similarity_boost": 0.75}}
|
15 |
+
|
16 |
+
response = requests.post(url, json=payload, headers=headers)
|
17 |
+
response.raise_for_status()
|
18 |
+
|
19 |
+
with open(output_file, "wb") as f:
|
20 |
+
f.write(response.content)
|
21 |
+
|
22 |
+
return output_file
|