-
Notifications
You must be signed in to change notification settings - Fork 22
/
preprocess.py
38 lines (29 loc) · 1.14 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
from sys import stderr
import argparse
import data
def make_parser():
p = argparse.ArgumentParser()
p.add_argument('--n-quant', '-nq', type=int, metavar='INT',
default=256, help='Number of quantization levels for Mu-law companding')
p.add_argument('--sample-rate', '-sr', type=int, metavar='INT',
default=16000, help='Number of samples per second for parsing sound files')
# positional arguments
p.add_argument('sam_file', type=str, metavar='SAMPLES_FILE',
help='File containing lines:\n'
+ '<id1>\t/path/to/sample1.flac\n'
+ '<id2>\t/path/to/sample2.flac\n')
p.add_argument('dat_file', type=str, metavar='OUTPUT_DAT_FILENAME',
help='Name for output file to produce')
return p
def main():
parser = make_parser()
opts = parser.parse_args()
print('Starting...', file=stderr)
stderr.flush()
catalog = data.parse_catalog(opts.sam_file)
data.convert(catalog, opts.dat_file, opts.n_quant, opts.sample_rate)
print('Wrote catalog to {}'.format(opts.dat_file),
file=stderr)
return 0
if __name__ == '__main__':
main()