-
Notifications
You must be signed in to change notification settings - Fork 11
/
preprocess.py
63 lines (47 loc) · 1.88 KB
/
preprocess.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
54
55
56
57
58
59
60
61
62
63
'''Dataset preprocessing.'''
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse
import concurrent.futures
import os
import numpy as np
import wavenet.utils as utils
BATCH = 10240
RATE = 8000
CHUNK = 1600
def split_into(data, n):
res = []
for i in range(n):
res.append(data[i::n])
return res
def process_files(files, id, output, rate, chunk_length, batch):
data = []
ofilename = os.path.join(output, 'vctk_{}'.format(id))
with open(ofilename, 'wb') as ofile:
for filename in files:
for chunk in utils._preprocess(filename, rate, chunk_length):
data.append(chunk)
if len(data) >= batch:
np.save(ofile, np.array(data))
data.clear()
np.save(ofile, np.array(data))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--data', type=str, default=os.getcwd())
parser.add_argument('--output', type=str, default='')
parser.add_argument('--workers', type=int, default=8)
parser.add_argument('--rate', type=int, default=RATE)
parser.add_argument('--stacks_num', type=int, default=5)
parser.add_argument('--layers_num', type=int, default=10)
parser.add_argument('--target_length', type=int, default=CHUNK)
parser.add_argument('--flush_every', type=int, default=BATCH)
args = parser.parse_args()
files = list(utils.wav_files_in(args.data))
file_groups = split_into(files, args.workers)
size = utils.receptive_field_size(args.layers_num, args.stacks_num) + args.target_length
with concurrent.futures.ThreadPoolExecutor(max_workers=args.workers) as pool:
for i in range(args.workers):
pool.submit(process_files, file_groups[i], i, args.output, args.rate,
size, args.flush_every)
if __name__ == '__main__':
main()