Plot sound wave

xiaoxiao2021-02-28  109

import numpy as np import wave import pylab as pl # open wav file f = wave.open(r"F:\Data\ESC-50-wav-files\audio\1-12653-A-15.wav", "rb") # read format info # (nchannels, sampwidth, framerate, nframes, comptype, compname) params = f.getparams() nchannels, sampwidth, framerate, nframes = params[:4] >>> print(nchannels) 1 >>> print(sampwidth) 2 >>> print(framerate) 44100 >>> print(nframes) 220500 str_data = f.readframes(nframes) f.close() wave_data = np.fromstring(str_data, dtype=np.short) time = np.arange(0, nframes) * (1.0 / framerate) >>> print(time) [ 0.00000000e+00 2.26757370e-05 4.53514739e-05 ..., 4.99993197e+00 4.99995465e+00 4.99997732e+00] >>> pl.plot(time, wave_data) [<matplotlib.lines.Line2D object at 0x0000000007BFDBA8>] >>> pl.xlabel("time (seconds)") <matplotlib.text.Text object at 0x0000000007BA7B70> >>> pl.show()

转载请注明原文地址: https://www.6miu.com/read-60875.html

最新回复(0)