Spaces:
Running
Running
File size: 3,108 Bytes
91e1c8c 5e5e671 91e1c8c 5e5e671 91e1c8c 5e5e671 61616cc 5e5e671 61616cc 5e5e671 61616cc 5e5e671 61616cc 5e5e671 61616cc 5e5e671 9acdcb9 9cc12c0 91e1c8c 5e5e671 61616cc 9cc12c0 91e1c8c 5e5e671 91e1c8c 5e5e671 91e1c8c 5e5e671 91e1c8c de72597 91e1c8c b113478 91e1c8c b113478 91e1c8c b113478 91e1c8c b113478 61616cc bd941fe b113478 bd941fe b113478 9cc12c0 b113478 bd941fe b113478 bd941fe 91e1c8c a4a75eb 91e1c8c a4a75eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
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,
choosen_model: str = "sabela.pth"
):
# if text is "celtia" take celtia.pth and celtia_config.json
if choosen_model == "Celtia":
config_path = "celtia_config.json"
model_file = "celtia.pth"
elif choosen_model == "Icia":
config_path = "icia_config.json"
model_file = "icia.pth"
else:
config_path = "sabela_config.json"
model_file = "sabela.pth"
model_path = os.path.join(os.getcwd(), model_file)
vocoder_path = None
vocoder_config_path = None
print(f"Using model: {model_path}\n"
f"Using config: {config_path}\n"
f"Using vocoder: {vocoder_path}\n"
f"Using vocoder config: {vocoder_config_path}"
)
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="Introduce un texto de entrada:",
value="Probando unha frase nova.",
)
with gr.Row():
model_select = gr.Dropdown(
label="Escolle un modelo:",
choices=MODEL_NAMES,
value=MODEL_NAMES[0],
interactive=True
)
with gr.Row():
tts_button = gr.Button("Enviar", elem_id="send-btn", visible=True)
with gr.Row():
output_audio = gr.Audio(label="Sa铆da", type="filepath")
tts_button.click(
tts,
inputs=[
input_text,
model_select,
],
outputs=[output_audio],
concurrency_limit=16,
)
demo.launch(debug=True) |