source: python/demos/demo_mfcc.py @ ff74460

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ff74460 was 6ff6d18, checked in by Paul Brossier <piem@piem.org>, 11 years ago

python/demos/demo_{mel-energy,mfcc,specdesc}.py: use set_xlabels_sample2time

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#! /usr/bin/env python
2
3import sys
4from aubio import source, pvoc, mfcc
5from numpy import array, vstack, zeros
6
7win_s = 512                 # fft size
8hop_s = win_s / 4           # hop size
9n_filters = 40
10n_coeffs = 13
11samplerate = 44100
12
13if len(sys.argv) < 2:
14    print "Usage: %s <source_filename>" % sys.argv[0]
15    sys.exit(1)
16
17source_filename = sys.argv[1]
18
19samplerate = 0
20if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
21
22s = source(source_filename, samplerate, hop_s)
23samplerate = s.samplerate
24p = pvoc(win_s, hop_s)
25m = mfcc(win_s, n_filters, n_coeffs, samplerate)
26
27desc = []
28tdesc = []
29
30mfccs = zeros([13,])
31frames_read = 0
32while True:
33    samples, read = s()
34    spec = p(samples)
35    mfcc_out = m(spec)
36    mfccs = vstack((mfccs, mfcc_out))
37    frames_read += read
38    if read < hop_s: break
39
40# do plotting
41from numpy import arange
42from demo_waveform_plot import get_waveform_plot
43from demo_waveform_plot import set_xlabels_sample2time
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()
Note: See TracBrowser for help on using the repository browser.