SeyedAli commited on
Commit
ca8a62d
1 Parent(s): c08b5a6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tempfile ,os
2
+ import gradio as gr
3
+ from transformers import VitsModel, AutoTokenizer
4
+ import torch
5
+ import numpy as np
6
+ import torchaudio
7
+
8
+ model = VitsModel.from_pretrained("SeyedAli/Arabic-Speech-synthesis")
9
+ tokenizer = AutoTokenizer.from_pretrained("SeyedAli/Arabic-Speech-synthesis")
10
+
11
+ def TTS(text):
12
+ inputs = tokenizer(text, return_tensors="pt")
13
+ with torch.no_grad():
14
+ output = model(**inputs).waveform
15
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
16
+ torchaudio.save(fp, output, model.config.sampling_rate,format="wav")
17
+ return fp.name
18
+ iface = gr.Interface(fn=TTS, inputs="text", outputs="audio")
19
+ iface.launch(share=False)