rutsam commited on
Commit
5e334c0
1 Parent(s): 75149e6

deploy tts

Browse files
Files changed (3) hide show
  1. app.py +49 -0
  2. packages.txt +2 -0
  3. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tempfile
2
+ from typing import Optional
3
+ import gradio as gr
4
+ import numpy as np
5
+ from TTS.config import load_config
6
+ from TTS.utils.manage import ModelManager
7
+ from TTS.utils.synthesizer import Synthesizer
8
+
9
+ MAX_TXT_LEN = 100
10
+ manager = ModelManager()
11
+ model_name="DigitalUmuganda/Kinyarwanda_YourTTS"
12
+ def generate_audio(text):
13
+ if len(text) > MAX_TXT_LEN:
14
+ text = text[:MAX_TXT_LEN]
15
+ print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
16
+ model_path, config_path, model_item = manager.download_model(model_name)
17
+ vocoder_name: Optional[str] = model_item["default_vocoder"]
18
+ vocoder_path = None
19
+ vocoder_config_path = None
20
+ if vocoder_name is not None:
21
+ vocoder_path, vocoder_config_path, _ = manager.download_model(vocoder_name)
22
+ synthesizer = Synthesizer(
23
+ model_path, config_path, None, None, vocoder_path, vocoder_config_path,
24
+ )
25
+ if synthesizer is None:
26
+ raise NameError("model not found")
27
+ wavs = synthesizer.tts(text)
28
+
29
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
30
+ synthesizer.save_wav(wavs, fp)
31
+ return fp.name
32
+
33
+ iface = gr.Interface(
34
+ fn=generate_audio,
35
+ inputs=[
36
+ gr.inputs.Textbox(
37
+ label="Input Text",
38
+ default="This sentence has been generated by a speech synthesis system.",
39
+ ),
40
+ ],
41
+ outputs=gr.outputs.Audio(label="Output"),
42
+ title="Kinyarwanda tts Demo",
43
+ description="Kinyarwanda tts build with ",
44
+ allow_flagging=False,
45
+ flagging_options=['error', 'bad-quality', 'wrong-pronounciation'],
46
+ layout="vertical",
47
+ live=False
48
+ )
49
+ iface.launch(share=False)
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ libsndfile1
2
+ espeak-ng
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/coqui-ai/TTS@0910cb76bcd85df56bf43654bb31427647cdfd0d#egg=TTS