Kamtera's picture
Update app.py
3d3ba6d
raw
history blame
1.98 kB
import tempfile ,os
from TTS.config import load_config
import gradio as gr
from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer
MAX_TXT_LEN = 800
model_path = os.getcwd() + "/best_model.pth"
config_path = os.getcwd() + "/config.json"
synthesizer = Synthesizer(
model_path, config_path
)
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)
# synthesize
if synthesizer is None:
raise NameError("model not found")
wavs = synthesizer.tts(text)
# 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 persian text to speech model.
Model can be found here: https://huggingface.co/Kamtera/persian-tts-female-glow_tts
Model trained on this dataset : https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale
"""
article= ""
examples=[
["شیش سیخ جیگر سیخی شیش هزار"],
["سه شیشه شیر ، سه سیر سرشیر"],
["دزدی دزدید ز بز دزدی بزی ، عجب دزدی که دزدید ز بز دزدی بزی"],
["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد"],
["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها"],
]
iface = gr.Interface(
fn=tts,
inputs=[
gr.Textbox(
label="Text",
value="زندگی فقط یک بار است؛ از آن به خوبی استفاده کن",
)
],
outputs=gr.Audio(label="Output",type='filepath'),
examples=examples,
title="🗣️Persian ttt - glow_tts 🗣️",
description=description,
article=article,
live=False
)
iface.launch(share=False)