julien-c HF staff commited on
Commit
9ec2680
1 Parent(s): 11d33be
Files changed (2) hide show
  1. app.py +71 -8
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,14 +1,77 @@
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- print(gr.__version__)
5
- return "Hello " + gr.__version__ + "!!"
6
 
7
  iface = gr.Interface(
8
- fn=greet,
9
- inputs="text",
10
- outputs="text",
11
- verbose=True,
12
- # enable_queue=True,
 
 
 
 
 
 
 
 
 
 
 
13
  )
14
  iface.launch()
 
1
+ from typing import Optional
2
+
3
+ from TTS.utils.manage import ModelManager
4
+ from TTS.utils.synthesizer import Synthesizer
5
  import gradio as gr
6
+ import tempfile
7
+
8
+
9
+
10
+ MODEL_NAMES = [
11
+ "en/ek1/tacotron2",
12
+ "en/ljspeech/tacotron2-DDC",
13
+ # "en/ljspeech/tacotron2-DDC_ph",
14
+ # "en/ljspeech/glow-tts",
15
+ # "en/ljspeech/tacotron2-DCA",
16
+ # "en/ljspeech/speedy-speech-wn",
17
+ # "en/ljspeech/vits",
18
+ # "en/vctk/sc-glow-tts",
19
+ # "en/vctk/vits",
20
+ # "en/sam/tacotron-DDC",
21
+ # "es/mai/tacotron2-DDC",
22
+ "fr/mai/tacotron2-DDC",
23
+ "zh-CN/baker/tacotron2-DDC-GST",
24
+ "nl/mai/tacotron2-DDC",
25
+ "de/thorsten/tacotron2-DCA",
26
+ # "ja/kokoro/tacotron2-DDC",
27
+ ]
28
+ MODELS = {}
29
+
30
+ manager = ModelManager()
31
+
32
+ for MODEL_NAME in MODEL_NAMES:
33
+ print(f"downloading {MODEL_NAME}")
34
+ model_path, config_path, model_item = manager.download_model(f"tts_models/{MODEL_NAME}")
35
+ vocoder_name: Optional[str] = model_item["default_vocoder"]
36
+ vocoder_path = None
37
+ vocoder_config_path = None
38
+ if vocoder_name is not None:
39
+ vocoder_path, vocoder_config_path, _ = manager.download_model(vocoder_name)
40
+
41
+ synthesizer = Synthesizer(
42
+ model_path, config_path, None, vocoder_path, vocoder_config_path,
43
+ )
44
+ MODELS[MODEL_NAME] = synthesizer
45
+
46
+
47
+ def tts(text: str, model_name: str):
48
+ print(text, model_name)
49
+ synthesizer = MODELS.get(model_name, None)
50
+ if synthesizer is None:
51
+ raise NameError("model not found")
52
+ wavs = synthesizer.tts(text)
53
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
54
+ synthesizer.save_wav(wavs, fp)
55
+ return fp.name
56
+
57
 
 
 
 
58
 
59
  iface = gr.Interface(
60
+ fn=tts,
61
+ inputs=[
62
+ gr.inputs.Textbox(
63
+ label="Input",
64
+ default="Hello, how are you?",
65
+ ),
66
+ gr.inputs.Radio(
67
+ label="Pick a TTS Model",
68
+ choices=MODEL_NAMES,
69
+ ),
70
+ ],
71
+ outputs=gr.outputs.Audio(label="Output"),
72
+ title="🐸💬 - Coqui TTS",
73
+ theme="huggingface",
74
+ description="🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production",
75
+ article="more info at https://github.com/coqui-ai/TTS",
76
  )
77
  iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ TTS