fighter-programmer/voicegen
0
1import logging2logging.getLogger('numba').setLevel(logging.WARNING)3import IPython.display as ipd4import torch5import commons6import utils7import ONNXVITS_infer8from text import text_to_sequence9 10def get_text(text, hps):11 text_norm = text_to_sequence(text, hps.symbols, hps.data.text_cleaners)12 if hps.data.add_blank:13 text_norm = commons.intersperse(text_norm, 0)14 text_norm = torch.LongTensor(text_norm)15 return text_norm16 17hps = utils.get_hparams_from_file("../vits/pretrained_models/uma87.json")18 19net_g = ONNXVITS_infer.SynthesizerTrn(20 len(hps.symbols),21 hps.data.filter_length // 2 + 1,22 hps.train.segment_size // hps.data.hop_length,23 n_speakers=hps.data.n_speakers,24 **hps.model)25_ = net_g.eval()26 27_ = utils.load_checkpoint("../vits/pretrained_models/uma_1153000.pth", net_g)28 29text1 = get_text("おはようございます。", hps)30stn_tst = text131with torch.no_grad():32 x_tst = stn_tst.unsqueeze(0)33 x_tst_lengths = torch.LongTensor([stn_tst.size(0)])34 sid = torch.LongTensor([0])35 audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()36print(audio)