Changeset 4120fbc for python/demos/demo_spectrogram.py
- Timestamp:
- May 16, 2016, 3:16:00 AM (9 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:
- dc654f8
- Parents:
- 416ddd1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_spectrogram.py
r416ddd1 r4120fbc 2 2 3 3 import sys, os.path 4 from aubio import pvoc, source 4 from aubio import pvoc, source, float_type 5 5 from numpy import zeros, log10, vstack 6 6 import matplotlib.pyplot as plt … … 8 8 def get_spectrogram(filename, samplerate = 0): 9 9 win_s = 512 # fft window size 10 hop_s = win_s / 2# hop size11 fft_s = win_s / 2 + 1# spectrum bins10 hop_s = win_s // 2 # hop size 11 fft_s = win_s // 2 + 1 # spectrum bins 12 12 13 13 a = source(filename, samplerate, hop_s) # source file 14 14 if samplerate == 0: samplerate = a.samplerate 15 15 pv = pvoc(win_s, hop_s) # phase vocoder 16 specgram = zeros([0, fft_s], dtype= 'float32')# numpy array to store spectrogram16 specgram = zeros([0, fft_s], dtype=float_type) # numpy array to store spectrogram 17 17 18 18 # analysis … … 29 29 time_step = hop_s / float(samplerate) 30 30 total_time = len(specgram) * time_step 31 print "total time: %0.2fs" % total_time,32 print ", samplerate: %.2fkHz" % (samplerate / 1000.)31 outstr = "total time: %0.2fs" % total_time 32 print(outstr + ", samplerate: %.2fkHz" % (samplerate / 1000.)) 33 33 n_xticks = 10 34 34 n_yticks = 10 … … 66 66 if __name__ == '__main__': 67 67 if len(sys.argv) < 2: 68 print "Usage: %s <filename>" % sys.argv[0]68 print("Usage: %s <filename>" % sys.argv[0]) 69 69 else: 70 70 for soundfile in sys.argv[1:]: 71 71 fig = get_spectrogram(soundfile) 72 72 # display graph 73 fig.show()73 plt.show() 74 74 #outimage = os.path.basename(soundfile) + '.png' 75 75 #print ("writing: " + outimage)
Note: See TracChangeset
for help on using the changeset viewer.