-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtdrill.py
executable file
·103 lines (70 loc) · 2.28 KB
/
qtdrill.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import sys
from PyQt4 import QtGui
from labelled_audiofile import LabelledAudiofile
from yamlfile import YamlFile
from drillsergeant import DrillSergeant
from gui import Gui
from simplelabelfile import SimpleLabelFile
import codecs
import argparse
import logging
import string
import os
logging.basicConfig(level=logging.DEBUG)
def get_args(input_type_choices):
arg_parser = argparse.ArgumentParser(description=u'')
arg_parser.add_argument('type',
type=str,
choices=input_type_choices)
arg_parser.add_argument('audiofiles',
type=str,
help='path to the audio file',
nargs='+')
try:
args = arg_parser.parse_args()
except Exception as x:
print('incorrect arguments')
return
return args
def main():
input_file_types = {
'simple' : SimpleLabelFile,
'drills' : LabelledAudiofile
}
args = get_args(input_file_types.keys())
label_file_type = None
if args.type == 'simple':
label_file_type = SimpleLabelFile
elif args.type == 'drills':
label_file_type = LabelledAudiofile
else:
raise Exception('unknown input file type {}'.format(args.type))
handlers = {
'.flac' : label_file_type,
'.mp3' : label_file_type,
'.wav' : label_file_type,
'.yaml' : YamlFile
}
drill_sections = list()
for audiofile_path in args.audiofiles:
_, ext = os.path.splitext(audiofile_path)
if ext not in handlers:
logging.error('no handler for {}.'.format(ext))
raise Exception('unknown file extension {}'.format(ext))
af = handlers[ext](audiofile_path)
try:
af.parse()
except Exception as e:
logging.error('could not parse %s' % audiofile_path)
raise e
else:
drill_sections.extend(af.get_drill_sections())
logging.info('a total of %d drill section have been found'
% len(drill_sections))
app = QtGui.QApplication(sys.argv)
gui = Gui()
drill_sergeant = DrillSergeant(gui, drill_sections)
sys.exit(app.exec_())
if __name__ == '__main__':
main()