-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_tts.py
More file actions
38 lines (31 loc) · 912 Bytes
/
generate_tts.py
File metadata and controls
38 lines (31 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from dotenv import load_dotenv
import requests
import os
load_dotenv()
CHUNK_SIZE = 1024
voice_id = "uNtKzbGXZY1mQci2XbFp"
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
headers = {
"Accept": "audio/mpeg",
"Content-Type": "application/json",
"xi-api-key": os.getenv('ELEVEN_API_KEY')
}
def generate_tts(text,path):
data = {
"text": text,
"model_id": "eleven_monolingual_v1",
"voice_settings": {
"stability": 0.5,
"similarity_boost": 0.5,
}
}
response = requests.post(url, json=data, headers=headers)
with open(path, 'wb') as f:
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
if chunk:
f.write(chunk)
if __name__ == '__main__':
text = "Good Job!"
path = os.path.join("tts","tts.mp3")
generate_tts(text,path)
print("TTS generated successfully")