wedyanessam commited on
Commit
5638628
·
verified ·
1 Parent(s): d71b13d

Create TTS/tts.py

Browse files
Files changed (1) hide show
  1. TTS/tts.py +14 -0
TTS/tts.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import VitsModel, AutoTokenizer
2
+ import torch
3
+
4
+
5
+ model = VitsModel.from_pretrained("facebook/mms-tts-ara")
6
+ tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-ara")
7
+
8
+ def text_to_speech(text):
9
+ inputs = tokenizer(text, return_tensors="pt")
10
+ with torch.no_grad():
11
+ output = model(**inputs)
12
+ waveform = output.waveform.squeeze().numpy()
13
+ sampling_rate = model.config.sampling_rate
14
+ return waveform, sampling_rate