Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,18 @@ import tempfile ,os
|
|
2 |
import gradio as gr
|
3 |
from transformers import VitsModel, AutoTokenizer,pipeline
|
4 |
import torch
|
|
|
5 |
import scipy
|
6 |
|
7 |
|
8 |
def TTS(text):
|
9 |
model = VitsModel.from_pretrained("SeyedAli/Persian-Speech-synthesis")
|
10 |
tokenizer = AutoTokenizer.from_pretrained("SeyedAli/Persian-Speech-synthesis")
|
11 |
-
|
12 |
-
inputs = tokenizer(text)
|
13 |
with torch.no_grad():
|
14 |
output = model(**inputs).waveform
|
15 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
16 |
-
scipy.io.wavfile.write(fp, rate=model.config.sampling_rate, data=output)
|
17 |
return fp.name
|
18 |
iface = gr.Interface(fn=TTS, inputs="text", outputs="audio")
|
19 |
iface.launch(share=False)
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import VitsModel, AutoTokenizer,pipeline
|
4 |
import torch
|
5 |
+
import numpy
|
6 |
import scipy
|
7 |
|
8 |
|
9 |
def TTS(text):
|
10 |
model = VitsModel.from_pretrained("SeyedAli/Persian-Speech-synthesis")
|
11 |
tokenizer = AutoTokenizer.from_pretrained("SeyedAli/Persian-Speech-synthesis")
|
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 |
+
scipy.io.wavfile.write(fp, rate=model.config.sampling_rate, data=np.array(output))
|
17 |
return fp.name
|
18 |
iface = gr.Interface(fn=TTS, inputs="text", outputs="audio")
|
19 |
iface.launch(share=False)
|