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
3import sys
4from aubio import source, pvoc, mfcc
5from numpy import array, vstack, zeros
6from demo_waveform_plot import set_xlabels_sample2time
7
8win_s = 512 # fft size
9hop_s = win_s / 4 # hop size
10n_filters = 40
11n_coeffs = 13
12samplerate = 44100
13
14if len(sys.argv) < 2:
15 print "Usage: %s <source_filename>" % sys.argv[0]
16 sys.exit(1)
17
18source_filename = sys.argv[1]
19
20samplerate = 0
21if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
22
23s = source(source_filename, samplerate, hop_s)
24samplerate = s.samplerate
25p = pvoc(win_s, hop_s)
26m = mfcc(win_s, n_filters, n_coeffs, samplerate)
27
28desc = []
29tdesc = []
30
31mfccs = zeros([13,])
32frames_read = 0
33while 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
42from numpy import arange
43from demo_waveform_plot import get_waveform_plot
44import matplotlib.pyplot as plt
45
46fig = plt.figure()
47plt.rc('lines',linewidth='.8')
48wave = plt.axes([0.1, 0.75, 0.8, 0.19])
49
50get_waveform_plot( source_filename, samplerate, block_size = hop_s, ax = wave)
51wave.xaxis.set_visible(False)
52wave.yaxis.set_visible(False)
53
54all_times = arange(mfccs.shape[0]) * hop_s
55n_coeffs = mfccs.shape[1]
56for 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
63set_xlabels_sample2time( ax, frames_read, samplerate)
64
65#plt.ylabel('spectral descriptor value')
66ax.xaxis.set_visible(True)
67wave.set_title('MFCC for %s' % source_filename)
68plt.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