import sndhdr, wave, struct if sndhdr.what(fname)[0] != 'wav': raise Exception("file doesn't have wav header") with wave.open(fname) as wav: params = (nchannels,sampwidth,rate,nframes,comp,compname) = wav.getparams() frames = wav.readframes(nframes*nchannels) out = struct.unpack_from("%dh" % nframes*nchannels, frames)
source share