Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,60 @@
|
|
1 |
import gradio as gr
|
2 |
-
from TTS.api import TTS
|
3 |
|
4 |
-
tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=False)
|
5 |
|
6 |
-
def predict(text):
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
demo = gr.Interface(
|
12 |
-
fn=
|
13 |
-
inputs=
|
14 |
-
outputs=
|
15 |
)
|
16 |
|
17 |
-
|
18 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
# from TTS.api import TTS
|
3 |
|
4 |
+
# tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=False)
|
5 |
|
6 |
+
# def predict(text):
|
7 |
+
# file_path = "output.wav"
|
8 |
+
# tts.tts_to_file(text, speaker=tts.speakers[0], language="en", file_path=file_path)
|
9 |
+
# return file_path
|
10 |
+
|
11 |
+
# demo = gr.Interface(
|
12 |
+
# fn=predict,
|
13 |
+
# inputs='text',
|
14 |
+
# outputs='audio'
|
15 |
+
# )
|
16 |
+
|
17 |
+
|
18 |
+
# demo.launch()
|
19 |
+
|
20 |
+
|
21 |
+
import requests
|
22 |
+
import time
|
23 |
+
import tempfile
|
24 |
+
import os
|
25 |
+
|
26 |
+
token = os.environ['apikey']
|
27 |
+
#discord_id = os.environ['discord-id']
|
28 |
+
API_HOST = "https://labs-proxy.voicemod.net/"
|
29 |
+
|
30 |
+
def download_file(url):
|
31 |
+
response = requests.get(url)
|
32 |
+
if response.status_code == 200:
|
33 |
+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
34 |
+
tmp_file.write(response.content)
|
35 |
+
tmp_file.flush()
|
36 |
+
return tmp_file.name
|
37 |
+
else:
|
38 |
+
print("Error: Unable to download file")
|
39 |
+
|
40 |
+
def tts(text):
|
41 |
+
url = API_HOST + "api/v1/tts/create"
|
42 |
+
payload = {
|
43 |
+
"text": text[:200] if len(text) > 200 else text,
|
44 |
+
"voiceId": "6926ecc5-ff5e-47c6-912b-3ffdb880bf56" # Narrator
|
45 |
+
}
|
46 |
+
headers = {
|
47 |
+
'x-api-key': token,
|
48 |
+
}
|
49 |
+
response = requests.request("POST", url, headers=headers, json=payload)
|
50 |
+
jsonResp = response.json()
|
51 |
+
|
52 |
+
return gr.make_waveform(download_file(jsonResp['audioUrl']))
|
53 |
|
54 |
demo = gr.Interface(
|
55 |
+
fn=tts,
|
56 |
+
inputs="text",
|
57 |
+
outputs="audio"
|
58 |
)
|
59 |
|
|
|
60 |
demo.launch()
|