1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| f = wave.open(filename, "rb")
params = f.getparams() nchannels, sampwidth, framerate, nframes = params[:4]
str_data = f.readframes(nframes) f.close()
wave_data = np.frombuffer(str_data, dtype=np.short) time = np.arange(0, nframes) * (1.0 / framerate) if nchannels == 2: wave_data.shape = -1, 2 wave_data = wave_data.T pl.subplot(211) pl.plot(time, wave_data[0]) pl.subplot(212) pl.plot(time, wave_data[1], c="g") else: pl.subplot(211) pl.plot(time, wave_data) pl.subplot(212) pl.specgram(wave_data, 1024, framerate) pl.show()
|