4 from aubio import source, pvoc, mfcc
5 from numpy import array, vstack, zeros
8 hop_s = win_s / 4 # hop size
9 n_filters = 40 # must be 40 for mfcc
14 print "Usage: %s <source_filename>" % sys.argv[0]
17 source_filename = sys.argv[1]
20 if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
22 s = source(source_filename, samplerate, hop_s)
23 samplerate = s.samplerate
24 p = pvoc(win_s, hop_s)
25 m = mfcc(win_s, n_filters, n_coeffs, samplerate)
27 mfccs = zeros([n_coeffs,])
33 mfccs = vstack((mfccs, mfcc_out))
35 if read < hop_s: break
38 from numpy import arange
39 from demo_waveform_plot import get_waveform_plot
40 from demo_waveform_plot import set_xlabels_sample2time
41 import matplotlib.pyplot as plt
44 plt.rc('lines',linewidth='.8')
45 wave = plt.axes([0.1, 0.75, 0.8, 0.19])
47 get_waveform_plot( source_filename, samplerate, block_size = hop_s, ax = wave)
48 wave.xaxis.set_visible(False)
49 wave.yaxis.set_visible(False)
51 all_times = arange(mfccs.shape[0]) * hop_s
52 n_coeffs = mfccs.shape[1]
53 for i in range(n_coeffs):
54 ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs), 0.8, 0.65 / n_coeffs], sharex = wave )
55 ax.xaxis.set_visible(False)
56 ax.yaxis.set_visible(False)
57 ax.plot(all_times, mfccs.T[i])
59 # add time to the last axis
60 set_xlabels_sample2time( ax, frames_read, samplerate)
62 #plt.ylabel('spectral descriptor value')
63 ax.xaxis.set_visible(True)
64 wave.set_title('MFCC for %s' % source_filename)