aliabd commited on
Commit
2ce8bf5
1 Parent(s): 7e8f434
Files changed (3) hide show
  1. app.py +66 -0
  2. packages.txt +2 -0
  3. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # URL: https://huggingface.co/spaces/gradio/neon-tts-plugin-coqui
2
+ import tempfile
3
+ import gradio as gr
4
+ from neon_tts_plugin_coqui import CoquiTTS
5
+
6
+ # load the model and set up constants
7
+ LANGUAGES = list(CoquiTTS.langs.keys())
8
+ default_lang = "en"
9
+ title = "🐸💬 - NeonAI Coqui AI TTS Plugin"
10
+ description = "🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production"
11
+ info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
12
+ badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
13
+ coquiTTS = CoquiTTS()
14
+
15
+ # define core fn
16
+ def tts(text: str, language: str):
17
+ print(text, language)
18
+ # return output
19
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
20
+ coquiTTS.get_tts(text, fp, speaker = {"language" : language})
21
+ return fp.name
22
+
23
+
24
+ # start a block
25
+ with gr.Blocks() as blocks:
26
+ # define text on page
27
+ gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
28
+ + title
29
+ + "</h1>")
30
+ gr.Markdown(description)
31
+ # define layout
32
+ with gr.Row():
33
+ with gr.Column():
34
+ # define inputs
35
+ textbox = gr.Textbox(
36
+ label="Input",
37
+ value=CoquiTTS.langs[default_lang]["sentence"],
38
+ max_lines=3,
39
+ )
40
+ radio = gr.Radio(
41
+ label="Language",
42
+ choices=LANGUAGES,
43
+ value=default_lang
44
+ )
45
+ with gr.Row():
46
+ # define button
47
+ submit = gr.Button("Submit", variant="primary")
48
+ # define output
49
+ audio = gr.Audio(label="Output", interactive=False)
50
+
51
+ gr.Markdown(info)
52
+ gr.Markdown("<center>"
53
+ +f'<img src={badge} alt="visitors badge"/>'
54
+ +"</center>")
55
+
56
+ # define what will run when submit is clicked
57
+ submit.click(
58
+ tts,
59
+ [textbox, radio],
60
+ [audio],
61
+ )
62
+ # define what will run when the radio input is changed
63
+ radio.change(lambda lang: CoquiTTS.langs[lang]["sentence"], radio, textbox)
64
+
65
+ # launch
66
+ blocks.launch()
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ libsndfile1
2
+ espeak-ng
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ neon-tts-plugin-coqui==0.4.1a9