SeyedAli commited on
Commit
16803e6
β€’
1 Parent(s): 7e6c36c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -10,11 +10,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=output)
17
- # return fp.name
18
- return output
19
  iface = gr.Interface(fn=TTS, inputs="text", outputs="text")
20
  iface.launch(share=False)
 
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
+ pipe = pipeline("text-to-speech", model=model,tokenizer=tokenizer)
14
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
15
+ scipy.io.wavfile.write(fp, rate=pipe(text)['sampling_rate'], data=pipe(text)['audio'])
16
+ return fp.name
 
 
17
  iface = gr.Interface(fn=TTS, inputs="text", outputs="text")
18
  iface.launch(share=False)