(wav_data, sample_rate)
return y
Read PCM-formatted WAV data and return a NumPy array of samples.

  Uses scipy to read and librosa/samplerate to process WAV data. Audio will
  be converted to mono if necessary.

  Args:
    wav_data: WAV audio data to read.
    sample_rate: The number of samples per second at which the audio will be
      returned. Resampling will be performed if necessary.

  Returns:
    A numpy array of audio samples, single-channel (mono) and sampled at the
    specified rate, in float32 format.

  Raises:
    IOError: If scipy is unable to read the WAV data.
    IOError: If audio processing fails.
Read PCM-formatted WAV data and return a NumPy array of samples.
Read PCM - formatted WAV data and return a NumPy array of samples .
def wav_data_to_samples(wav_data, sample_rate):
  """Read PCM-formatted WAV data and return a NumPy array of samples.

  Uses scipy to read and librosa/samplerate to process WAV data. Audio will
  be converted to mono if necessary.

  Args:
    wav_data: WAV audio data to read.
    sample_rate: The number of samples per second at which the audio will be
      returned. Resampling will be performed if necessary.

  Returns:
    A numpy array of audio samples, single-channel (mono) and sampled at the
    specified rate, in float32 format.

  Raises:
    IOError: If scipy is unable to read the WAV data.
    IOError: If audio processing fails.
  """
  try:
    # Read the wav file, converting sample rate & number of channels.
    native_sr, y = scipy.io.wavfile.read(six.BytesIO(wav_data))
  except Exception as e:  # pylint: disable=broad-except
    raise IOError(e)

  if y.dtype == np.int16:  # Convert to float32.
    y = y.astype(np.float32) / np.iinfo(np.int16).max
  elif y.dtype == np.float32:  # Already float32.
    pass
  else:
    raise IOError('WAV file not 16-bit or 32-bit float PCM, unsupported')
  try:  # Convert to mono and the desired sample rate.
    if y.ndim == 2 and y.shape[1] == 2:
      y = np.mean(y, axis=1)
    if native_sr != sample_rate:
      y = resample(y, native_sr, sample_rate)
  except Exception as e:  # pylint: disable=broad-except
    raise IOError(e)
  return y
def wav_data_to_samples ( wav_data , sample_rate ) : try : # Read the wav file, converting sample rate & number of channels. native_sr , y = scipy . io . wavfile . read ( six . BytesIO ( wav_data ) ) except Exception as e : # pylint: disable=broad-except raise IOError ( e ) if y . dtype == np . int16 : # Convert to float32. y = y . astype ( np . float32 ) / np . iinfo ( np . int16 ) . max elif y . dtype == np . float32 : # Already float32. pass else : raise IOError ( 'WAV file not 16-bit or 32-bit float PCM, unsupported' ) try : # Convert to mono and the desired sample rate. if y . ndim == 2 and y . shape [ 1 ] == 2 : y = np . mean ( y , axis = 1 ) if native_sr != sample_rate : y = resample ( y , native_sr , sample_rate ) except Exception as e : # pylint: disable=broad-except raise IOError ( e ) return y