- Timestamp:
- Sep 22, 2016, 1:48:44 PM (8 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- f334300
- Parents:
- 88c89e3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_mfcc.py
r88c89e3 r70b2ab0 3 3 import sys 4 4 from aubio import source, pvoc, mfcc 5 from numpy import vstack, zeros 5 from numpy import vstack, zeros, diff 6 6 7 win_s = 512 # fft size8 hop_s = win_s // 4 # hop size9 7 n_filters = 40 # must be 40 for mfcc 10 8 n_coeffs = 13 11 samplerate = 4410012 9 13 10 if len(sys.argv) < 2: 14 print("Usage: %s <source_filename>" % sys.argv[0]) 11 print("Usage: %s <source_filename> [samplerate] [win_s] [hop_s] [mode]" % sys.argv[0]) 12 print(" where [mode] can be 'delta' or 'ddelta' for first and second derivatives") 15 13 sys.exit(1) 16 14 17 15 source_filename = sys.argv[1] 16 17 if len(sys.argv) > 2: samplerate = int(sys.argv[2]) 18 else: samplerate = 0 19 if len(sys.argv) > 3: win_s = int(sys.argv[3]) 20 else: win_s = 512 21 if len(sys.argv) > 4: hop_s = int(sys.argv[4]) 22 else: hop_s = win_s // 4 23 if len(sys.argv) > 5: mode = sys.argv[5] 24 else: mode = "default" 18 25 19 26 samplerate = 0 … … 49 56 wave.yaxis.set_visible(False) 50 57 58 # compute first and second derivatives 59 if mode in ["delta", "ddelta"]: 60 mfccs = diff(mfccs, axis = 0) 61 if mode == "ddelta": 62 mfccs = diff(mfccs, axis = 0) 63 51 64 all_times = arange(mfccs.shape[0]) * hop_s 52 65 n_coeffs = mfccs.shape[1] … … 54 67 ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs), 0.8, 0.65 / n_coeffs], sharex = wave ) 55 68 ax.xaxis.set_visible(False) 56 ax.yaxis.set_visible(False) 69 ax.set_yticks([]) 70 ax.set_ylabel('%d' % i) 57 71 ax.plot(all_times, mfccs.T[i]) 58 72 59 73 # add time to the last axis 60 set_xlabels_sample2time( ax, frames_read, samplerate) 74 set_xlabels_sample2time( ax, frames_read, samplerate) 61 75 62 76 #plt.ylabel('spectral descriptor value') 63 77 ax.xaxis.set_visible(True) 64 wave.set_title('MFCC for %s' % source_filename) 78 title = 'MFCC for %s' % source_filename 79 if mode == "delta": title = mode + " " + title 80 elif mode == "ddelta": title = "double-delta" + " " + title 81 wave.set_title(title) 65 82 plt.show()
Note: See TracChangeset
for help on using the changeset viewer.