pocketmonkey commited on
Commit
2179545
1 Parent(s): 752514f

Create inference.py

Browse files
Files changed (1) hide show
  1. inference.py +20 -0
inference.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from IPython.display import Audio
2
+
3
+ load the model:
4
+ model= SpeechT5ForTextToSpeech.from_pretrained("pocketmonkey/speecht5_tts_urdu")
5
+
6
+ get a speaker embedding:
7
+ example = dataset["test"][304] speaker_embeddings = torch.tensor(example["speaker_embeddings"]).unsqueeze(0) speaker_embeddings.shape
8
+
9
+ def urdu_to_roman_urdu(text):
10
+ urdu_to_roman_dict = { 'ا': 'a', 'ب': 'b', 'پ': 'p', 'ت': 't', 'ٹ': 't', 'ث': 's', 'ج': 'j', 'چ': 'ch', 'ح': 'h', 'خ': 'kh', 'د': 'd', 'ڈ': 'd', 'ذ': 'z', 'ر': 'r', 'ڑ': 'r', 'ز': 'z', 'ژ': 'zh', 'س': 's', 'ش': 'sh', 'ص': 's', 'ض': 'z', 'ط': 't', 'ظ': 'z', 'ع': 'a', 'غ': 'gh', 'ف': 'f', 'ق': 'q', 'ک': 'k', 'گ': 'g', 'ل': 'l', 'م': 'm', 'ن': 'n', 'ں': 'n', 'و': 'w', 'ہ': 'h', 'ء': 'a', 'ی': 'y', 'ے': 'e', 'آ': 'a', 'ؤ': 'o', 'ئ': 'y', 'ٔ': '', ' ': ' ', '۔': '.', '،': ',', '؛': ';', '؟': '?','ھ': 'h' }
11
+ roman_text = ''.join(urdu_to_roman_dict.get(char, char) for char in text)
12
+ return roman_text
13
+
14
+ text = "زندگی میں کامیابی" text=urdu_to_roman_urdu(text)
15
+
16
+ inputs = processor(text=text, return_tensors="pt")
17
+
18
+ with torch.no_grad(): speech = vocoder(spectrogram)
19
+
20
+ Audio(speech.numpy(), rate=16000)