speecht5_tts_urdu / inference.py
pocketmonkey's picture
Create inference.py
2179545 verified
raw
history blame contribute delete
No virus
1.19 kB
from IPython.display import Audio
load the model:
model= SpeechT5ForTextToSpeech.from_pretrained("pocketmonkey/speecht5_tts_urdu")
get a speaker embedding:
example = dataset["test"][304] speaker_embeddings = torch.tensor(example["speaker_embeddings"]).unsqueeze(0) speaker_embeddings.shape
def urdu_to_roman_urdu(text):
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' }
roman_text = ''.join(urdu_to_roman_dict.get(char, char) for char in text)
return roman_text
text = "زندگی میں کامیابی" text=urdu_to_roman_urdu(text)
inputs = processor(text=text, return_tensors="pt")
with torch.no_grad(): speech = vocoder(spectrogram)
Audio(speech.numpy(), rate=16000)