TTS / app.py
ayymen's picture
ⵔⵏⵓ ⵉⵎⴷⵢⴰⵜⵏ
884068b verified
raw
history blame
1.56 kB
import gradio as gr
import tempfile
from TTS.utils.synthesizer import Synthesizer
from huggingface_hub import hf_hub_download
import torch
CUDA = torch.cuda.is_available()
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=CUDA
)
# 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()