File size: 870 Bytes
e7db7ab
03fc43e
8d12a0e
03fc43e
e35048f
5b3e648
73316e5
6608fe5
 
1692178
3a1d118
03fc43e
78e4f6a
6608fe5
 
16803e6
8255a9c
16803e6
56d59fe
ef3739a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import tempfile ,os
import gradio as gr
from transformers import VitsModel, AutoTokenizer,pipeline
import torch
import numpy as np
import torchaudio

model = VitsModel.from_pretrained("SeyedAli/Persian-Speech-synthesis")
tokenizer = AutoTokenizer.from_pretrained("SeyedAli/Persian-Speech-synthesis")
text_input = gr.TextArea(label="متن فارسی",text_align="right",rtl=True,type="text")
audio_output = gr.Audio(label="صوت گفتار فارسی", type="filepath")
def TTS(text):
   inputs = tokenizer(text, return_tensors="pt")
   with torch.no_grad():
        output = model(**inputs).waveform 
   with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
        torchaudio.save(fp, output, model.config.sampling_rate,format="wav")
        return fp.name
iface = gr.Interface(fn=TTS, inputs=text_input, outputs=audio_output)
iface.launch(share=False)