parameters: (file_name, scale=True)
return_statement: return (samples.reshape(-1, num_channels), sample_rate)
docstring: Read a .wav file into a numpy array.
  
    Note: the FFmpeg based AudioDecoder is more generic, use this only as a
          low-level alternative to AudioDecoder.
  
    Args:
      file_name: string. name of the local file to load.
      scale: boolean. if True, returns float data in the [-1, 1] range instead
          of integers.
  
    Returns:
      2-dimensional numpy array of size (num_samples, num_channels)
  
    Raises:
      AudioIoException:
        - The file header is corrupted.
        - The file uses an unsupported sampling rate, bitdepth or codec.
docstring_summary: Read a .wav file into a numpy array.
docstring_tokens: Read a . wav file into a numpy array .
function: def ReadWavFile(file_name, scale=True):
    """Read a .wav file into a numpy array.
  
    Note: the FFmpeg based AudioDecoder is more generic, use this only as a
          low-level alternative to AudioDecoder.
  
    Args:
      file_name: string. name of the local file to load.
      scale: boolean. if True, returns float data in the [-1, 1] range instead
          of integers.
  
    Returns:
      2-dimensional numpy array of size (num_samples, num_channels)
  
    Raises:
      AudioIoException:
        - The file header is corrupted.
        - The file uses an unsupported sampling rate, bitdepth or codec.
    """
    f = file(file_name, 'r')
    header = f.read(12)
    if len(header) < 12 or header[:4] != 'RIFF' or header[8:] != 'WAVE':
      raise AudioIoException('Corrupted header')
  
    format_header_size = _GoToIffChunk(f, 'fmt ')
    if format_header_size < 0 or format_header_size != 16:
      raise AudioIoException('Invalid header size')
  
    format_header = _ReadBytesOrFail(f, 16, 'Corrupted header')
  
    compression, num_channels, sample_rate, _, _, bitdepth = struct.unpack(
        '<HHLLHH', format_header)
  
    if compression != 1:
      raise AudioIoException('Unknown .wav codec: %d' % compression)
  
    if not num_channels:
      raise AudioIoException('Wrong number of channels')
  
    if sample_rate < 1000 or sample_rate > 96000:
      raise AudioIoException('Invalid sample rate')
  
    if bitdepth != 8 and bitdepth != 16:
      raise AudioIoException('Unsupported bit depth')
  
    sample_data_size = _GoToIffChunk(f, 'data')
    num_samples = sample_data_size / (bitdepth / 8)
    # Make sure we are reading a number of samples which is a multiple of the
    # number of channels. Some corrupted stereo .wav files may contain 5 samples!
    num_samples -= num_samples % num_channels
    if bitdepth == 8:
      samples = numpy.fromfile(f, dtype=numpy.ubyte, count=num_samples)
      if scale:
        samples = (samples / _UNSIGNED_CHAR_TO_FLOAT_SCALE) - 1.0
    else:
      bytes = bitdepth / 8
      samples = numpy.fromfile(f, dtype='<i%d' % bytes, count=num_samples)
      if scale:
        # Semantics of x = x / y and x /= y are different when x and y are
        # numpy arrays of a different type. x /= y casts to y's type, while
        # x = x / y casts to x's type.
        # pylint: disable-msg=C6407
        samples = samples / float(1 << (bitdepth - 1))
    return (samples.reshape(-1, num_channels), sample_rate)
function_tokens: def ReadWavFile ( file_name , scale = True ) : f = file ( file_name , 'r' ) header = f . read ( 12 ) if len ( header ) < 12 or header [ : 4 ] != 'RIFF' or header [ 8 : ] != 'WAVE' : raise AudioIoException ( 'Corrupted header' ) format_header_size = _GoToIffChunk ( f , 'fmt ' ) if format_header_size < 0 or format_header_size != 16 : raise AudioIoException ( 'Invalid header size' ) format_header = _ReadBytesOrFail ( f , 16 , 'Corrupted header' ) compression , num_channels , sample_rate , _ , _ , bitdepth = struct . unpack ( '<HHLLHH' , format_header ) if compression != 1 : raise AudioIoException ( 'Unknown .wav codec: %d' % compression ) if not num_channels : raise AudioIoException ( 'Wrong number of channels' ) if sample_rate < 1000 or sample_rate > 96000 : raise AudioIoException ( 'Invalid sample rate' ) if bitdepth != 8 and bitdepth != 16 : raise AudioIoException ( 'Unsupported bit depth' ) sample_data_size = _GoToIffChunk ( f , 'data' ) num_samples = sample_data_size / ( bitdepth / 8 ) # Make sure we are reading a number of samples which is a multiple of the # number of channels. Some corrupted stereo .wav files may contain 5 samples! num_samples -= num_samples % num_channels if bitdepth == 8 : samples = numpy . fromfile ( f , dtype = numpy . ubyte , count = num_samples ) if scale : samples = ( samples / _UNSIGNED_CHAR_TO_FLOAT_SCALE ) - 1.0 else : bytes = bitdepth / 8 samples = numpy . fromfile ( f , dtype = '<i%d' % bytes , count = num_samples ) if scale : # Semantics of x = x / y and x /= y are different when x and y are # numpy arrays of a different type. x /= y casts to y's type, while # x = x / y casts to x's type. # pylint: disable-msg=C6407 samples = samples / float ( 1 << ( bitdepth - 1 ) ) return ( samples . reshape ( - 1 , num_channels ) , sample_rate )