Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app (1).py +77 -0
- packages.txt +1 -0
- requirements.txt +2 -0
app (1).py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tempfile
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
from TTS.utils.manage import ModelManager
|
8 |
+
from TTS.utils.synthesizer import Synthesizer
|
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 |
+
# output = (synthesizer.output_sample_rate, np.array(wavs))
|
54 |
+
# return output
|
55 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
56 |
+
synthesizer.save_wav(wavs, fp)
|
57 |
+
return fp.name
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
iface = gr.Interface(
|
62 |
+
fn=tts,
|
63 |
+
inputs=[
|
64 |
+
gr.inputs.Textbox(
|
65 |
+
label="Input",
|
66 |
+
default="Hello, how are you?",
|
67 |
+
),
|
68 |
+
gr.inputs.Radio(
|
69 |
+
label="Pick a TTS Model",
|
70 |
+
choices=MODEL_NAMES,
|
71 |
+
),
|
72 |
+
],
|
73 |
+
outputs=gr.outputs.Audio(label="Output"),
|
74 |
+
title="🐸💬 - Coqui TTS",
|
75 |
+
description="🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production",
|
76 |
+
article="more info at https://github.com/coqui-ai/TTS",
|
77 |
+
)iface.launch(share=True) # Muestra el botón de la API
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
libsndfile1-dev
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
TTS==0.2.1
|
2 |
+
Werkzeug==2.0.3
|