Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tempfile
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from neon_tts_plugin_coqui import CoquiTTS
|
6 |
+
|
7 |
+
|
8 |
+
LANGUAGES = list(CoquiTTS.langs.keys())
|
9 |
+
default_lang = "en"
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
title = "ChatGPTBots.net | TTS"
|
14 |
+
description = "A deep learning toolkit for Text-to-Speech, battle-tested in research and production"
|
15 |
+
info = "More info at [TTS](https://chatgptbots.net)"
|
16 |
+
|
17 |
+
|
18 |
+
coquiTTS = CoquiTTS()
|
19 |
+
|
20 |
+
|
21 |
+
def tts(text: str, language: str):
|
22 |
+
print(text, language)
|
23 |
+
# return output
|
24 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
25 |
+
coquiTTS.get_tts(text, fp, speaker = {"language" : language})
|
26 |
+
return fp.name
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
with gr.Blocks() as blocks:
|
31 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
|
32 |
+
+ title
|
33 |
+
+ "</h1>")
|
34 |
+
gr.Markdown(description)
|
35 |
+
with gr.Row():# equal_height=False
|
36 |
+
with gr.Column():# variant="panel"
|
37 |
+
textbox = gr.Textbox(
|
38 |
+
label="Input",
|
39 |
+
value=CoquiTTS.langs[default_lang]["sentence"],
|
40 |
+
max_lines=3,
|
41 |
+
)
|
42 |
+
radio = gr.Radio(
|
43 |
+
label="Language",
|
44 |
+
choices=LANGUAGES,
|
45 |
+
value=default_lang
|
46 |
+
)
|
47 |
+
with gr.Row():# mobile_collapse=False
|
48 |
+
submit = gr.Button("Submit", variant="primary")
|
49 |
+
audio = gr.Audio(label="Output", interactive=False)
|
50 |
+
gr.Markdown(info)
|
51 |
+
gr.Markdown("<center>"
|
52 |
+
+f'<img src={badge} alt="visitors badge"/>'
|
53 |
+
+"</center>")
|
54 |
+
|
55 |
+
# actions
|
56 |
+
submit.click(
|
57 |
+
tts,
|
58 |
+
[textbox, radio],
|
59 |
+
[audio],
|
60 |
+
)
|
61 |
+
radio.change(lambda lang: CoquiTTS.langs[lang]["sentence"], radio, textbox)
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
blocks.launch()
|