SeyedAli's picture
Update app.py
e7db7ab
raw
history blame
639 Bytes
import tempfile ,os
import gradio as gr
from transformers import VitsModel, AutoTokenizer,pipeline
import torch
import scipy
def TTS(text):
model = VitsModel.from_pretrained("SeyedAli/Persian-Speech-synthesis")
tokenizer = AutoTokenizer.from_pretrained("SeyedAli/Persian-Speech-synthesis")
pipe = pipeline("text-to-speech", model=model,tokenizer=tokenizer)
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
scipy.io.wavfile.write(fp, rate=model.config.sampling_rate, data=pipe['audio'])
return fp.name
iface = gr.Interface(fn=TTS, inputs="text", outputs="audio")
iface.launch(share=False)