History

python/demos/demo_mfcc.py: added simple mfcc demo

Paul Brossier committed 13 years ago

Commit d83ac741 parent 1e905881 file · +68 −0Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/demos/demo_mfcc.py+68−0
@@ -0,0 +1,68 @@
1+#! /usr/bin/env python
2+
3+import sys
4+from aubio import source, pvoc, mfcc
5+from numpy import array, vstack, zeros
6+from demo_waveform_plot import set_xlabels_sample2time
7+
8+win_s = 512 # fft size
9+hop_s = win_s / 4 # hop size
10+n_filters = 40
11+n_coeffs = 13
12+samplerate = 44100
13+
14+if len(sys.argv) < 2:
15+ print "Usage: %s <source_filename>" % sys.argv[0]
16+ sys.exit(1)
17+
18+source_filename = sys.argv[1]
19+
20+samplerate = 0
21+if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
22+
23+s = source(source_filename, samplerate, hop_s)
24+samplerate = s.samplerate
25+p = pvoc(win_s, hop_s)
26+m = mfcc(win_s, n_filters, n_coeffs, samplerate)
27+
28+desc = []
29+tdesc = []
30+
31+mfccs = zeros([13,])
32+frames_read = 0
33+while True:
34+ samples, read = s()
35+ spec = p(samples)
36+ mfcc_out = m(spec)
37+ mfccs = vstack((mfccs, mfcc_out))
38+ frames_read += read
39+ if read < hop_s: break
40+
41+# do plotting
42+from numpy import arange
43+from demo_waveform_plot import get_waveform_plot
44+import matplotlib.pyplot as plt
45+
46+fig = plt.figure()
47+plt.rc('lines',linewidth='.8')
48+wave = plt.axes([0.1, 0.75, 0.8, 0.19])
49+
50+get_waveform_plot( source_filename, samplerate, block_size = hop_s, ax = wave)
51+wave.xaxis.set_visible(False)
52+wave.yaxis.set_visible(False)
53+
54+all_times = arange(mfccs.shape[0]) * hop_s
55+n_coeffs = mfccs.shape[1]
56+for i in range(n_coeffs):
57+ ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs), 0.8, 0.65 / n_coeffs], sharex = wave )
58+ ax.xaxis.set_visible(False)
59+ ax.yaxis.set_visible(False)
60+ ax.plot(all_times, mfccs.T[i])
61+
62+# add time to the last axis
63+set_xlabels_sample2time( ax, frames_read, samplerate)
64+
65+#plt.ylabel('spectral descriptor value')
66+ax.xaxis.set_visible(True)
67+wave.set_title('MFCC for %s' % source_filename)
68+plt.show()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t