The console is not an error, nor display graphical
The import wave
The import numpy as np
The import pylab as PLT
# open the wav files, open return a is a Wave_read class instance, by calling its methods read wav file formats and data,
F=wave. The open (r "D: \ \ img \ \ hello wav", "rb")
# read format information
# one-time return all WAV file format information, it returns a set of yuan (a tuple) : track number, quantitative digits (byte units), sampling frequency and sampling points, the compression type, the description of the compression type, wave module supports only the compressed data, so you can ignore the last two information
Params=f.g etparams ()
Nchannels sampwidth, framerate, nframes=params [: 4]
# read waveform data
# read voice data, passing a parameter specifies the length of the need to read for the unit with the sampling point ()
Str_data=https://bbs.csdn.net/topics/f.readframes (nframes)
F. lose ()
# the waveform data into an array
And quantitative unit, the # need according to the number of channels will read binary data into an array of objects can be calculated
Wave_data=https://bbs.csdn.net/topics/np.frombuffer (str_data, dtype=np. Short)
Wave_data=https://bbs.csdn.net/topics/wave_data * 1.0/(Max (abs (wave_data))) # wave amplitude normalization
Print (" wave ", len (wave_data))
Print (" nframes nframes)
Print (" framerate, framerate)
# by sampling points and sampling frequency calculated each sampling time,
Time=np. Arange (0, nframes)/framerate
Len_time=14239
Am=time [0: len_time]
# time is an array, and wave_data wave_data [0] or [1] matching form a series of point coordinates,
PLT. Figure ()
PLT. Subplot (5,1,1)
PLT. The plot (am, wave_data)
PLT. The show ()