Spaces:
Running
Running
import tempfile | |
from typing import Optional | |
from TTS.config import load_config | |
import gradio as gr | |
import numpy as np | |
from TTS.utils.manage import ModelManager | |
from TTS.utils.synthesizer import Synthesizer | |
import os | |
MODEL_NAMES = ["Celtia", "Icia", "Sabela"] | |
# reorder models | |
print(MODEL_NAMES) | |
def tts(text: str, | |
model_file: str = "icia.pth" | |
): | |
model_path = os.path.join(os.getcwd(), model_file) | |
# if text is "celtia" take celtia.pth and celtia_config.json | |
if text == "Celtia": | |
config_path = "celtia_config.json" | |
model_file = "celtia.pth" | |
elif text == "Icia": | |
config_path = "icia_config.json" | |
model_file = "icia.pth" | |
else: | |
config_path = "sabela_config.json" | |
model_file = "sabela.pth" | |
vocoder_path = None | |
vocoder_config_path = None | |
synthesizer = Synthesizer( | |
model_path, config_path, None, vocoder_path, vocoder_config_path, | |
) | |
# synthesize | |
if synthesizer is None: | |
raise NameError("model not found") | |
wavs = synthesizer.tts(text) | |
# return output | |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: | |
synthesizer.save_wav(wavs, fp) | |
return fp.name | |
title = """<h1 align="center">馃惛馃挰 CoquiTTS Demo Proxecto N贸s </h1>""" | |
with gr.Blocks(analytics_enabled=False) as demo: | |
with gr.Row(): | |
with gr.Column(): | |
gr.Markdown( | |
""" | |
## <img src="https://huggingface.co/spaces/proxectonos/README/resolve/main/title-card.png" width="100%" style="border-radius: 0.75rem;"> | |
""" | |
) | |
with gr.Column(): | |
with gr.Row(): | |
gr.Markdown( | |
""" | |
<br/> | |
馃捇 Este space mostra alg煤ns dos modelos TTS desenvolvidos polo **[Proxecto N贸s](https://huggingface.co/proxectonos)**. | |
<br/> | |
""" | |
) | |
with gr.Row(): | |
input_text = gr.Textbox( | |
label="Input Text", | |
value="This sentence has been generated by a speech synthesis system.", | |
) | |
with gr.Row(): | |
model_select = gr.Dropdown( | |
label="Pick Model: tts_models/<language>/<dataset>/<model_name>", | |
choices=MODEL_NAMES, | |
value="tts_models/en/jenny/jenny" | |
) | |
with gr.Row(): | |
tts_button = gr.Button("Send", elem_id="send-btn", visible=True) | |
with gr.Row(): | |
output_audio = gr.Audio(label="Output", type="filepath") | |
tts_button.click( | |
tts, | |
inputs=[ | |
input_text, | |
model_select, | |
], | |
outputs=[output_audio], | |
concurrency_limit=16, | |
) | |
demo.launch(debug=True) |