def plotstft(audiopath, binsize=2**10, plotpath=None, colormap="jet"): samplerate, samples = wav.read(audiopath) frames = wu.get_frames(samples, 1000, 150) s = stft(frames[200], binsize) sshow, freq = logscale_spec(s, factor=1.0, sr=samplerate) ims = 20.*np.log10(np.abs(sshow)/10e-6) # amplitude to decibel timebins, freqbins = np.shape(ims) plt.figure(figsize=(15, 7.5)) plt.imshow(np.transpose(ims), origin="lower", aspect="auto", cmap=colormap, interpolation="none") plt.colorbar() plt.xlabel("time (s)") plt.ylabel("frequency (hz)") plt.xlim([0, timebins-1]) plt.ylim([0, freqbins]) xlocs = np.float32(np.linspace(0, timebins-1, 5)) plt.xticks(xlocs, ["%.02f" % l for l in ((xlocs*len(samples)/timebins)+(0.5*binsize))/samplerate]) ylocs = np.int16(np.round(np.linspace(0, freqbins-1, 10))) plt.yticks(ylocs, ["%.02f" % freq[i] for i in ylocs]) if plotpath: plt.savefig(plotpath, bbox_inches="tight") else: plt.show() plt.clf() #plotstft("my_audio_file.wav")
from features import * from scipy import signal import matplotlib.pyplot as plt from pylab import plot,show,subplot,specgram #path = 'F:\CETVRTA GODINA\Soft\SoftSound\Test\TestFiles\Woodwinds\BasClarinet\BassClarinet 04.wav' #path = 'F:\CETVRTA GODINA\Soft\SoftSound\Test\TestFiles\Woodwinds\Flute\Flute 14.wav' #path = 'F:\CETVRTA GODINA\Soft\SoftSound\Chan Chan (Trimmed).wav' path = 'F:\CETVRTA GODINA\Diplomski\IRMAS-Sample\IRMAS-Sample\Training\Vio\FormatFactory__[vio][nod][cla]2156__3.wav' #path = 'F:\CETVRTA GODINA\Soft\SoftSound\PreppedUIowa\Brass\TrumpetNoVib\mono\Trumpet.novib.ff.Eb6.mono.wav' #spectrogram.plotstft(path) sample_freq, sound = wavfile.read(path) frames = wav_utils.get_frames(sound, 10000, 150) #example = frames[200] # res = mfcc(sound, sample_freq) # for i in range(0, 20): # print res[i] # print len(res) #wav_utils.plot_spectrogram(example, sample_freq) #win = signal.get_window('hamming', 256) #f, t, Sxx = signal.spectrogram(sound, sample_freq, scaling='spectrum') #plt.pcolormesh(t, f, Sxx) #plt.ylabel('Frequency [Hz]')