-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze.py
46 lines (39 loc) · 1.04 KB
/
analyze.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
from voice import Voice
def analyze(filename):
'''Analyze a voice file.
Example:
python analyze 'myfile'
Return:
The detailed infomation and the mood prediction result if success.
The file should use its full path, and will be mood_predict by our program.
The prediction is processed by svm-machine , model file and scale file should
be generated by the script train.py, and no need to indicate. All you need is
to tell us which file or directory you want to predict.'''
#print 'Analyzing %s'%filename
m = Voice()
try:
m.analyze(filename)
m.calFeatures()
m.mood_predict()
m.callInfo()
m.report()
print 'Analyze success'
except Exception as e:
print 'Analyze failed:'+ repr(e)
if __name__ == '__main__':
import sys
import os
if len(sys.argv) < 2:
print analyze.__doc__
sys.exit(0)
arg = sys.argv[1]
if os.path.isdir(arg):
directory = arg
os.chdir(directory)
for name in os.listdir(os.getcwd()):
analyze(name)
elif os.path.isfile(arg):
filename = arg
analyze(filename)
else:
print analyze.__doc__