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