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()