Spaces:
Running
Running
Commit
ยท
ef465dd
1
Parent(s):
f2dc2c2
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = "๐ธ๐ฌ - NeonAI Coqui AI TTS Plugin"
|
14 |
+
description = "๐ธ๐ฌ - a deep learning toolkit for Text-to-Speech, battle-tested in research and production"
|
15 |
+
info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
|
16 |
+
badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
coquiTTS = CoquiTTS()
|
21 |
+
|
22 |
+
|
23 |
+
def tts(text: str, language: str):
|
24 |
+
print(text, language)
|
25 |
+
# return output
|
26 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
27 |
+
coquiTTS.get_tts(text, fp, speaker = {"language" : language})
|
28 |
+
return fp.name
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
with gr.Blocks() as blocks:
|
33 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
|
34 |
+
+ title
|
35 |
+
+ "</h1>")
|
36 |
+
gr.Markdown(description)
|
37 |
+
with gr.Row():# equal_height=False
|
38 |
+
with gr.Column():# variant="panel"
|
39 |
+
textbox = gr.Textbox(
|
40 |
+
label="Input",
|
41 |
+
value=CoquiTTS.langs[default_lang]["sentence"],
|
42 |
+
max_lines=3,
|
43 |
+
)
|
44 |
+
radio = gr.Radio(
|
45 |
+
label="Language",
|
46 |
+
choices=LANGUAGES,
|
47 |
+
value=default_lang
|
48 |
+
)
|
49 |
+
with gr.Row():# mobile_collapse=False
|
50 |
+
submit = gr.Button("Submit", variant="primary")
|
51 |
+
audio = gr.Audio(label="Output", interactive=False)
|
52 |
+
gr.Markdown(info)
|
53 |
+
gr.Markdown("<center>"
|
54 |
+
+f'<img src={badge} alt="visitors badge"/>'
|
55 |
+
+"</center>")
|
56 |
+
|
57 |
+
# actions
|
58 |
+
submit.click(
|
59 |
+
tts,
|
60 |
+
[textbox, radio],
|
61 |
+
[audio],
|
62 |
+
)
|
63 |
+
radio.change(lambda lang: CoquiTTS.langs[lang]["sentence"], radio, textbox)
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
blocks.launch()
|