import tempfile from typing import Optional from TTS.config import load_config import gradio as gr import numpy as np import os import json from TTS.utils.manage import ModelManager from TTS.utils.synthesizer import Synthesizer MAX_TXT_LEN = 800 def tts(text: str): if len(text) > MAX_TXT_LEN: text = text[:MAX_TXT_LEN] print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.") print(text) model_path = os.getcwd() + "/best_model.pth" config_path = os.getcwd() + "/config.json" synthesizer = Synthesizer( model_path, config_path, speakers_file_path ) # synthesize if synthesizer is None: raise NameError("model not found") wavs = synthesizer.tts(text, speaker_idx) # return output with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: synthesizer.save_wav(wavs, fp) return fp.name description=""" This is a demo of first public free persian text to speech model. Model trained on this dataset : https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale """ article= "" iface = gr.Interface( fn=tts, inputs=[ gr.inputs.Textbox( label="Text", default="زندگی فقط یک بار است؛ از آن به خوبی استفاده کن", ) ], outputs=gr.outputs.Audio(label="Output"), title="🗣️Persian ttt - glow_tts 🗣️", theme="grass", description=description, article=article, allow_flagging=False, flagging_options=['error', 'bad-quality', 'wrong-pronounciation'], layout="vertical", live=False ) iface.launch(share=False)