TTS / app.py
ayymen's picture
Initial commit
e95bc25
raw
history blame
1.36 kB
import gradio as gr
import tempfile
from TTS.utils.synthesizer import Synthesizer
from huggingface_hub import hf_hub_download
REPO_ID = "ayymen/Coqui-TTS-Vits-shi"
my_title = "Tamazight Text-to-Speech"
my_description = "This model is based on [VITS](https://github.com/jaywalnut310/vits), thanks to 🐸 [Coqui.ai](https://coqui.ai/)."
my_examples = [
["ⴰⵣⵓⵍ"],
["ⴰⵔ ⴽⵎ ⵜⵜⵉⵔⵉⵖ"],
["ⴳⵏ! ⴰⴷ ⴰⴽ ⵉⵙⵙⴳⵏ ⵕⴱⴱⵉ ⵉⵜⵜⵓ ⴽ."]
]
my_inputs = [
gr.Textbox(lines=5, label="Input Text"),
]
my_outputs = gr.Audio(type="filepath", label="Output Audio")
def tts(text: str):
best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
# init synthesizer
synthesizer = Synthesizer(
best_model_path,
config_path,
use_cuda=True
)
# create audio file
wavs = synthesizer.tts(text)
with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
synthesizer.save_wav(wavs, fp)
return fp.name
iface = gr.Interface(
fn=tts,
inputs=my_inputs,
outputs=my_outputs,
title=my_title,
description = my_description,
examples = my_examples,
cache_examples=True
)
iface.launch()