#transfer data into array wave_data = np.fromstring(str_data, dtype=np.short) wave_data.shape = -1, 2 wave_data = wave_data.T time = np.arange(0, nframes) * (1.0 / framerate) return time, wave_data f = wave.open(r"sample.wav", "rb") # (nchannels, sampwidth, framerate, nframes, comptype, compname) params = f.getparams() nchannels, sampwidth, framerate, nframes = params[:4] print(params) # read data of the wave str_data = f.readframes(nframes) f.close() #transfer data into array wave_data = np.fromstring(str_data, dtype=np.short) wave_data.shape = -1, 2 wave_data = wave_data.T time = np.arange(0, nframes) * (1.0 / framerate) # plot pl.subplot(311) pl.plot(time, wave_data[0]) pl.subplot(312) pl.plot(time, wave_data[1], c="g") pl.xlabel("time (seconds)") pl.subplot(313) pl.magnitude_spectrum(wave_data[0],Fs = params[2] ) pl.show()
time1, wave_data = readwav("sample.wav") time2, read_data = readwav("output.wav") print("time1: " + str(len(time1)),"time2: " + str(len(time2))) #transfer data into array # plot pl.subplot(321) pl.plot(time1, wave_data[0],'g') pl.xlabel("Original: Channel 1") pl.subplot(323) pl.plot(time1, wave_data[1],'g') pl.xlabel("Original: Channel 2") pl.subplot(325) pl.magnitude_spectrum(wave_data[0],Fs = RATE,color='g') pl.subplot(322) pl.plot(time2, read_data[0],'b') pl.xlabel("Record: Channel 1") pl.subplot(324) pl.plot(time2, read_data[1],'b') pl.xlabel("Record: Channel 2") pl.subplot(326) pl.magnitude_spectrum(read_data[0],Fs = RATE,color='b') pl.show()