-
Notifications
You must be signed in to change notification settings - Fork 17
/
vits_process.py
53 lines (44 loc) · 1.53 KB
/
vits_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from vits import commons
import sys
import torch
from vits import utils
from vits.models import SynthesizerTrn
from vits.text import cleaned_text_to_sequence
from vits.text.cleaners import japanese_cleaners
from vits.text.symbols import symbols
from scipy.io.wavfile import write
import tempfile
hps = utils.get_hparams_from_file("./vits/config.json")
net_g = SynthesizerTrn(
len(symbols),
hps.data.filter_length // 2 + 1,
hps.train.segment_size // hps.data.hop_length,
**hps.model)
_ = net_g.eval()
_ = utils.load_checkpoint("./vits/G_88000.pth", net_g, None)
def get_text(text, hps):
text_norm = cleaned_text_to_sequence(text)
if hps.data.add_blank:
text_norm = commons.intersperse(text_norm, 0)
text_norm = torch.LongTensor(text_norm)
return text_norm
def jtts(text, save_path):
stn_tst = get_text(japanese_cleaners(text), hps)
with torch.no_grad():
x_tst = stn_tst.unsqueeze(0)
x_tst_lengths = torch.LongTensor([stn_tst.size(0)])
audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][
0, 0].data.float().numpy()
write(save_path, hps.data.sampling_rate, audio)
def doTTS(text):
with tempfile.NamedTemporaryFile(delete=False) as f:
jtts(text, f.name)
return f.name
if __name__ == '__main__':
if len(sys.argv) != 4:
exit(1)
model_path = sys.argv[1]
text = sys.argv[2]
save_path = sys.argv[3]
_ = utils.load_checkpoint(model_path, net_g, None)
jtts(text, save_path)