(wavpath, sr=8000)
return sample_rate, audio
audio:
    np.float32, shape [None], sample in [-1, 1], using librosa.load
    np.int16, shape [None], sample in [-32768, 32767], using scipy.io.wavfile
    np.float32, shape[None, audio_channel], sample int [-1, 1], using tf.DecodeWav

  return
    sr: sample rate
    audio: [-1, 1], same to tf.DecodeWav
audio:
    np.float32, shape [None], sample in [-1, 1], using librosa.load
    np.int16, shape [None], sample in [-32768, 32767], using scipy.io.wavfile
    np.float32, shape[None, audio_channel], sample int [-1, 1], using tf.DecodeWav
audio : np . float32 shape [ None ] sample in [ - 1 1 ] using librosa . load np . int16 shape [ None ] sample in [ - 32768 32767 ] using scipy . io . wavfile np . float32 shape [ None audio_channel ] sample int [ - 1 1 ] using tf . DecodeWav
def load_wav(wavpath, sr=8000):
  '''
  audio:
    np.float32, shape [None], sample in [-1, 1], using librosa.load
    np.int16, shape [None], sample in [-32768, 32767], using scipy.io.wavfile
    np.float32, shape[None, audio_channel], sample int [-1, 1], using tf.DecodeWav

  return
    sr: sample rate
    audio: [-1, 1], same to tf.DecodeWav
  '''
  #from scipy.io import wavfile
  #sample_rate, audio = wavfile.read(wavpath)

  #samples, sample_rate = librosa.load(wavpath, sr=sr)

  feat_name = 'load_wav'
  graph = None
  # get session
  if feat_name not in _global_sess:
    graph = tf.Graph()
    with graph.as_default():
      params = speech_ops.speech_params(sr=sr, audio_desired_samples=-1)
      t_wavpath = tf.placeholder(dtype=tf.string, name="wavpath")
      t_audio, t_sample_rate = speech_ops.read_wav(t_wavpath, params)
      t_audio = tf.identity(t_audio, name="audio")
      t_sample_rate = tf.identity(t_sample_rate, name="sample_rate")

  sess = _get_session(feat_name, graph)
  audio, sample_rate = sess.run([
      _get_out_tensor_name('audio', 0),
      _get_out_tensor_name('sample_rate', 0)
  ],
                                feed_dict={"wavpath:0": wavpath})
  audio = audio[:, 0]

  assert sample_rate == sr, 'sampling rate must be {}Hz, get {}Hz'.format(
      sr, sample_rate)
  return sample_rate, audio
def load_wav ( wavpath , sr = 8000 ) : #from scipy.io import wavfile #sample_rate, audio = wavfile.read(wavpath) #samples, sample_rate = librosa.load(wavpath, sr=sr) feat_name = 'load_wav' graph = None # get session if feat_name not in _global_sess : graph = tf . Graph ( ) with graph . as_default ( ) : params = speech_ops . speech_params ( sr = sr , audio_desired_samples = - 1 ) t_wavpath = tf . placeholder ( dtype = tf . string , name = "wavpath" ) t_audio , t_sample_rate = speech_ops . read_wav ( t_wavpath , params ) t_audio = tf . identity ( t_audio , name = "audio" ) t_sample_rate = tf . identity ( t_sample_rate , name = "sample_rate" ) sess = _get_session ( feat_name , graph ) audio , sample_rate = sess . run ( [ _get_out_tensor_name ( 'audio' , 0 ) , _get_out_tensor_name ( 'sample_rate' , 0 ) ] , feed_dict = { "wavpath:0" : wavpath } ) audio = audio [ : , 0 ] assert sample_rate == sr , 'sampling rate must be {}Hz, get {}Hz' . format ( sr , sample_rate ) return sample_rate , audio