Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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)
|