-
Notifications
You must be signed in to change notification settings - Fork 0
/
voice.py
45 lines (34 loc) · 1.03 KB
/
voice.py
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
39
40
41
42
43
44
from elevenlabs import set_api_key
import os
from dotenv import load_dotenv
load_dotenv()
from elevenlabs import set_api_key
set_api_key(os.environ['elevenlabs_api'])
api_key = os.environ['elevenlabs_api']
import requests
CHUNK_SIZE = 1024
headers = {
"Accept": "audio/mpeg",
"Content-Type": "application/json",
"xi-api-key": api_key
}
def voiceover(script,title,Genre):
if "Horror" or "Suspence" in Genre:
url = "https://api.elevenlabs.io/v1/text-to-speech/piTKgcLEGmPE4e6mEKli"
else:
url = "https://api.elevenlabs.io/v1/text-to-speech/TxGEqnHWrfWFTfGW9XjX"
data = {
"text": script,
"model_id": "eleven_monolingual_v1",
"voice_settings": {
"stability": 0.5,
"similarity_boost": 0.5
}
}
response = requests.post(url, json=data, headers=headers)
print(response)
with open(f'audio_generated\{title}.mp3', 'wb') as f:
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
print(chunk)
if chunk:
f.write(chunk)