-
Notifications
You must be signed in to change notification settings - Fork 0
/
_03_voice_gen_ja_11lab.py
51 lines (40 loc) · 1.38 KB
/
_03_voice_gen_ja_11lab.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
45
46
47
48
49
50
import requests
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("ELEVEN_API_KEY")
with open('conversation_scripts.txt', 'r', encoding='utf-8') as file:
lines = file.readlines()
def divide_list(lst, delimiter):
try:
# Find the index of the delimiter
idx = lst.index(delimiter)
# Slice the list into two parts based on the index of the delimiter
return lst[:idx], lst[idx+1:]
except ValueError:
# If the delimiter is not in the list, return the original list and an empty list
return lst, []
lst = lines
delimiter = '*****\n'
en_conv, ja_conv = divide_list(lst, delimiter)
url = "https://api.elevenlabs.io/v1/text-to-speech/j210dv0vWm7fCknyQpbA"
for n in range(len(ja_conv)):
payload = {
"text": f"{ja_conv[n]}",
"voice_settings": {
"stability": 0.4,
"similarity_boost": 0.75
},
"seed": 1,
"model_id": "eleven_multilingual_v2"
}
headers = {
"xi-api-key": f"{api_key}",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
# Save the audio content into an mp3 file
with open(f'elevenlab_ja_voice_{n}.mp3', 'wb') as f:
f.write(response.content)
print(f'Writing elevenlab_ja_voice_{n}.mp3...')
# os.system('start elevenlab_ja_voice.mp3')