-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyze_with_plot.py
47 lines (40 loc) · 949 Bytes
/
analyze_with_plot.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
from voice import Voice
import pylab as pl
import numpy as np
def analyze_with_plot(filename):
'''Analyze a single voice file and plot its volume, pitch, end_point.
Example:
python analyze 'myfile'
'''
#print 'Analyzing %s'%filename
m = Voice()
m.analyze(filename)
t = np.linspace(0,len(m.y)*1.0/m.fs,len(m.frames))
mul = len(m.y)*1.0/m.fs/len(m.frames)
pl.subplot(311)
pl.plot(t, m.volume)
print m.speech_segment
print mul
for s in m.speech_segment:
print s[0]*mul,s[1]*mul
pl.plot([s[0]*mul,s[0]*mul],[0,max(m.volume)],color='red')
pl.plot([s[1]*mul,s[1]*mul],[0,max(m.volume)],color='blue')
pl.subplot(312)
pl.plot(t, m.pitch)
pl.subplot(313)
pl.plot(t, m.energyBelow250)
pl.show()
'''
m.calFeatures()
m.mood_predict()
m.callInfo()
m.report()
'''
if __name__ == '__main__':
import sys
import os
if len(sys.argv) < 2:
print analyze.__doc__
sys.exit(0)
arg = sys.argv[1]
analyze_with_plot(arg)