-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrebase_tsv.py
executable file
·28 lines (23 loc) · 981 Bytes
/
rebase_tsv.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
#!/usr/bin/env python3
import argparse, os, re
parser = argparse.ArgumentParser(description="Rebase a TSV file's wav files.")
parser.add_argument('filename', help='Dataset TSV file to rebase.')
parser.add_argument('new_wav_path', help='Path to directory containing the wav files.')
args = parser.parse_args()
if not os.path.exists(args.filename):
raise Exception('File does not exist: %s' % args.filename)
if not os.path.exists(args.new_wav_path):
raise Exception('Path does not exist: %s' % args.new_wav_path)
lines = []
with open(args.filename, 'r') as f:
for line in f:
fields = line.rstrip('\n').split('\t')
wav_path = fields[0]
wav_path = re.sub(r'\\', '/', wav_path)
wav_path = re.sub(r'^.*/', '', wav_path)
wav_path = os.path.join(args.new_wav_path, wav_path)
fields[0] = wav_path
lines.append(fields)
with open(args.filename, 'w') as f:
for line in lines:
f.write('\t'.join(line) + '\n')