-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpreview.py
42 lines (37 loc) · 1.3 KB
/
preview.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
import math
import warnings
import argparse
import torch
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import torchaudio
from datautil.dataset import build_data_loader
import simpleutils
if __name__ == '__main__':
# don't delete this line, because my data loader uses queues
torch.multiprocessing.set_start_method('spawn')
args = argparse.ArgumentParser()
args.add_argument('-d', '--data', required=True)
args.add_argument('--noise')
args.add_argument('--air')
args.add_argument('--micirp')
args.add_argument('-p', '--params', default='configs/default.json')
args = args.parse_args()
params = simpleutils.read_config(args.params)
train_data = build_data_loader(params, args.data, args.noise, args.air, args.micirp)
i = 0
train_data.dataset.output_wav = True
train_data.sampler.sampler.shuffle = False
iterator = iter(train_data)
for a in iterator:
i += 1
sound = a.transpose(0,1).flatten(1,2)
sound *= 0.5 / torch.max(torch.abs(sound))
torchaudio.save('temp%d.wav' % i, sound, 8000)
print(i)
if i >= 3:
iterator._shutdown_workers()
# kill my preloader
train_data.sampler.sampler.preloader.terminate()
break
print('stopping...')