class_docstr: Encoder class for saving and loading waveforms.
class_docstr_tok: ["Encoder","class","for","saving","and","loading","waveforms","."]
docstr: Transform a string with a filename into a list of float32.
  
  Args:
    s: path to the file with a waveform.
  
  Returns:
    samples: list of int16s
docstr_tok: ["Transform","a","string","with","a","filename","into","a","list","of","float32",".","Args",":","s",":","path","to","the","file","with","a","waveform",".","Returns",":","samples",":","list","of","int16s"]
code: def encode(self, s):
      """Transform a string with a filename into a list of float32.
  
      Args:
        s: path to the file with a waveform.
  
      Returns:
        samples: list of int16s
      """
  
      def convert_to_wav(in_path, out_path, extra_args=None):
          if not os.path.exists(out_path):
              # TODO(dliebling) On Linux, check if libsox-fmt-mp3 is installed.
              args = [
                  "sox",
                  "--rate",
                  "16k",
                  "--bits",
                  "16",
                  "--channel",
                  "1",
              ]
              if extra_args:
                  args += extra_args
              call(args + [in_path, out_path])
  
      # Make sure that the data is a single channel, 16bit, 16kHz wave.
      # TODO(chorowski): the directory may not be writable, this should fallback
      # to a temp path, and provide instructions for installing sox.
      if s.endswith(".mp3"):
          out_filepath = s[:-4] + ".wav"
          convert_to_wav(s, out_filepath, ["--guard"])
          s = out_filepath
      elif not s.endswith(".wav"):
          out_filepath = s + ".wav"
          convert_to_wav(s, out_filepath)
          s = out_filepath
      rate, data = wavfile.read(s)
      assert rate == self._sample_rate
      assert len(data.shape) == 1
      if data.dtype not in [np.float32, np.float64]:
          data = data.astype(np.float32) / np.iinfo(data.dtype).max
      return data.tolist()
  
file_path: tensor2tensor/tensor2tensor/data_generators/audio_encoder.py
imports: import os
  from subprocess import call
  import tempfile
  import numpy
  from scipy.io import wavfile
label_desc: Use image node_id 3 for calling the AudioEncoder obj's underlying member method code with example usage: obj.encode(s) and returns: data