def _wav2array(nchannels, sampwidth, data):
 (num_samples, remainder) = divmod(len(data), (sampwidth * nchannels))
 if (remainder > 0):
  raise ValueError('The length of data is not a multiple of sampwidth * num_channels.')
 if (sampwidth > 4):
  raise ValueError('sampwidth must not be greater than 4.')
 if (sampwidth == 3):
  a = _np.empty((num_samples, nchannels, 4), dtype=_np.uint8)
  raw_bytes = _np.fromstring(data, dtype=_np.uint8)
  a[:, :, :sampwidth] = raw_bytes.reshape((-1), nchannels, sampwidth)
  a[:, :, sampwidth:] = ((a[:, :, (sampwidth - 1):sampwidth] >> 7) * 255)
  result = a.view('<i4').reshape(a.shape[:(-1)])
 else:
  dt_char = ('u' if (sampwidth == 1) else 'i')
  a = _np.fromstring(data, dtype=('<%s%d' % (dt_char, sampwidth)))
  result = a.reshape((-1), nchannels)
 return result

def _wav2array ( nchannels , sampwidth , data ) : ( num_samples , remainder ) = divmod ( len ( data ) , ( sampwidth * nchannels ) ) if ( remainder > 0 ) : raise ValueError ( 'The length of data is not a multiple of sampwidth * num_channels.' ) if ( sampwidth > 4 ) : raise ValueError ( 'sampwidth must not be greater than 4.' ) if ( sampwidth == 3 ) : a = _np . empty ( ( num_samples , nchannels , 4 ) , dtype = _np . uint8 ) raw_bytes = _np . fromstring ( data , dtype = _np . uint8 ) a [ : , : , : sampwidth ] = raw_bytes . reshape ( ( - 1 ) , nchannels , sampwidth ) a [ : , : , sampwidth : ] = ( ( a [ : , : , ( sampwidth - 1 ) : sampwidth ] >> 7 ) * 255 ) result = a . view ( '<i4' ) . reshape ( a . shape [ : ( - 1 ) ] ) else : dt_char = ( 'u' if ( sampwidth == 1 ) else 'i' ) a = _np . fromstring ( data , dtype = ( '<%s%d' % ( dt_char , sampwidth ) ) ) result = a . reshape ( ( - 1 ) , nchannels ) return result
data must be the string containing the bytes from the wav file .