File size: 705 Bytes
e7db7ab
03fc43e
8d12a0e
03fc43e
e35048f
5b3e648
73316e5
 
03fc43e
 
 
78e4f6a
16803e6
 
5b3e648
16803e6
7ea6bf6
ef3739a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import tempfile ,os
import gradio as gr
from transformers import VitsModel, AutoTokenizer,pipeline
import torch
import numpy as np
import torchaudio


def TTS(text):
   model = VitsModel.from_pretrained("SeyedAli/Persian-Speech-synthesis")
   tokenizer = AutoTokenizer.from_pretrained("SeyedAli/Persian-Speech-synthesis")
   inputs = tokenizer(text, return_tensors="pt")
   pipe = pipeline("text-to-speech", model=model,tokenizer=tokenizer)
   with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
        torchaudio.save(fp, pipe(text)['audio'], rate=pipe(text)['sampling_rate'])
        return fp.name
iface = gr.Interface(fn=TTS, inputs="text", outputs="audio")
iface.launch(share=False)