-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaturaltts API.py
116 lines (84 loc) · 3.39 KB
/
naturaltts API.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import cfscrape
import random
from requests import Session
import json
from terminaltables import AsciiTable
from tqdm import tqdm
from art import text2art
from colorama import init
from termcolor import colored
init()
print(colored("Text-to-Speech Converter! 💬 -> 🗣️ ", "green", attrs=['bold']))
print(colored("Developed and Tested By Sahil Kumar™", "blue", attrs=['bold']))
chunk_size = 1
Voice_engine_table = [["Index", "Voice Type"],
["1.", "Ivy Female US English"],
["2.", "Joanna Female US English"],
["3.", "Joey Male US English"]]
runner = cfscrape.create_scraper()
session = Session()
def get_socks4():
url = "https://api.proxyscrape.com/?request=getproxies&proxytype=socks4&timeout=10000&country=all"
r = runner.get(url).text
all_proxies = r.split()
return {"https": f"socks4://{random.choice(all_proxies)}"}
def proxy_request(req_type, url, **kwargs):
while 1:
try:
proxy = get_socks4()
r = session.request(req_type, url, proxies=proxy, timeout=5, **kwargs)
break
except:
print("[*] Processinggg.....")
pass
return r
def convert_To_Speech(message):
url = "https://api.naturaltts.com/v1/converter/free"
headers = {
'authority': 'api.naturaltts.com',
'accept': 'application/json, text/plain, */*',
'authorization': 'Bearer null',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36 Edg/86.0.622.38',
'content-type': 'application/json;charset=UTF-8',
'origin': 'https://naturaltts.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://naturaltts.com/',
'accept-language': 'en-US,en;q=0.9,mt;q=0.8',
}
table = AsciiTable(Voice_engine_table)
print(table.table)
choice = int(input("Index of the voice to use: "))
save_name = input("Enter name for the file: ")
if choice == 1:
voiceID = "Ivy"
gender = "Female"
elif choice == 2:
voiceID = "Joanna"
gender = "Female"
elif choice == 3:
voiceID = "Joey"
gender = "Male"
else:
print("[*] Invalid Option Exiting.......")
exit()
data = {"text": message,
"voiceId": voiceID,
"lang": "US English",
"gender": gender,
"engine": "standard"}
result = proxy_request("post", url, headers=headers, data=json.dumps(data)).json()
print(colored("✅ Successfully Converted To Speech ✅", "green",attrs=['bold']))
#print("[*] Successfully Converted To Speech")
print('\nYour link to download the voice : ', result['task']['OutputUri'])
r = runner.get(result['task']['OutputUri'], stream=True)
total_size = int(r.headers['content-length'])
with open(f"Voices/{save_name}.mp3", 'wb') as f:
for data in tqdm(iterable=r.iter_content(chunk_size=chunk_size), total=total_size / chunk_size, unit='KB'):
f.write(data)
message = input("Enter your message: ")
if len(message) <= 200:
convert_To_Speech(message)
else:
print("[*] Sorry the message length should not be more than 200")