Views
No views yet
pip install nemo_toolkit['tts'] soundfile
1from nemo.collections.tts.models import UnivNetModel
2from nemo.collections.tts.models import Tacotron2Model
3import torch
4import soundfile as sf
5
6model = Tacotron2Model.from_pretrained("lunarlist/tts-thai-last-step").to('cpu')
7vcoder_model = UnivNetModel.from_pretrained(model_name="tts_en_libritts_univnet")
8text='ภาษาไทย ง่าย นิด เดียว'
9dict_idx={k:i for i,k in enumerate(model.hparams["cfg"]['labels'])}
10parsed2=torch.Tensor([[66]+[dict_idx[i] for i in text if i]+[67]]).int().to("cpu")
11spectrogram2 = model.generate_spectrogram(tokens=parsed2)
12audio2 = vcoder_model.convert_spectrogram_to_audio(spec=spectrogram2)
13
14# Save the audio to disk in a file called speech.wav
15sf.write("speech.wav", audio2.to('cpu').detach().numpy()[0], 22050)