-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoConvert.py
More file actions
73 lines (58 loc) · 2.34 KB
/
AutoConvert.py
File metadata and controls
73 lines (58 loc) · 2.34 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import yaml
import json
from pathlib import Path
import os
import torch
from argparse import ArgumentParser
from OneShot.inference import OneShotInferencer
from Waveglow.inference import WaveglowInferencer
import sounddevice as sd
from record_anylength import record_audio
from time import sleep
import numpy as np
from Waveglow.mel2samp import MAX_WAV_VALUE
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-target', '-t', help='target wav path')
# OneShot
parser.add_argument('-attr', '-a', help='data mean & std attr file path')
parser.add_argument('-oneshot_conf', '-c', help='OneShot config file path')
parser.add_argument('-oneshot_model', '-m', help='OneShot model path')
parser.add_argument('-sample_rate', '-sr', help='sample rate', default=22050, type=int)
parser.add_argument('-data_conf', help='data configuration json') # VCTK_config.json
# Waveglow
parser.add_argument('-waveglow_path','-w', help='Path to waveglow decoder model')
parser.add_argument("-sigma", default=1.0, type=float)
parser.add_argument("--is_fp16", action="store_true")
parser.add_argument("-denoiser_strength","-d", default=0.0, type=float,
help='Removes model bias. Start with 0.1 and adjust')
args = parser.parse_args()
with open(args.oneshot_conf) as f:
oneshot_conf = yaml.load(f)
target = Path(args.target)
if not os.path.exists(target):
raise Exception(f"Target file {target} does not exist")
with open(args.data_conf) as f:
data_config = f.read()
data_config = json.loads(data_config)["data_config"]
oneshot_inferencer = OneShotInferencer(config=oneshot_conf, args=args,
waveglow_config=data_config, verbose=False)
waveglow_inferencer = WaveglowInferencer(args)
# source = Path("wav_tmp/input.wav")
while True:
while True:
try:
print("Waiting...")
sleep(2)
except KeyboardInterrupt:
break
source_audio = torch.tensor(record_audio(args.sample_rate)).squeeze(1)
start_skip = int(args.sample_rate * 1)
source_audio = source_audio[start_skip:]
mel,_ = oneshot_inferencer.inference_from_audio(source_audio, target, plot=False)
audio = waveglow_inferencer.inference(mel.T, None, save_wav=False)
# val_clip = MAX_WAV_VALUE * 0.85
# audio = audio / MAX_WAV_VALUE * val_clip
print(f"Audio max value: {np.max(audio)}, min: {np.min(audio)}")
sd.play(audio, args.sample_rate)
sd.wait()