class_docstr: SpeedPerturbation
  
  The speed perturbation in kaldi uses sox-speed instead of sox-tempo,
  and sox-speed just to resample the input,
  i.e pitch and tempo are changed both.
  
  "Why use speed option instead of tempo -s in SoX for speed perturbation"
  https://groups.google.com/forum/#!topic/kaldi-help/8OOG7eE4sZ8
  
  Warning:
      This function is very slow because of resampling.
      I recommmend to apply speed-perturb outside the training using sox.
class_docstr_tok: ["SpeedPerturbation","The","speed","perturbation","in","kaldi","uses","sox-speed","instead","of","sox-tempo",",","and","sox-speed","just","to","resample","the","input",",","i.e","pitch","and","tempo","are","changed","both",".","``","Why","use","speed","option","instead","of","tempo","-s","in","SoX","for","speed","perturbation","''","https",":","\/\/groups.google.com\/forum\/","#","!","topic\/kaldi-help\/8OOG7eE4sZ8","Warning",":","This","function","is","very","slow","because","of","resampling",".","I","recommmend","to","apply","speed-perturb","outside","the","training","using","sox","."]
code: def __call__(self, x, uttid=None, train=True):
      if not train:
          return x
  
      x = x.astype(numpy.float32)
      if self.accept_uttid:
          ratio = self.utt2ratio[uttid]
      else:
          ratio = self.state.uniform(self.lower, self.upper)
  
      # Note1: resample requires the sampling-rate of input and output,
      #        but actually only the ratio is used.
      y = librosa.resample(x, ratio, 1, res_type=self.res_type)
  
      if self.keep_length:
          diff = abs(len(x) - len(y))
          if len(y) > len(x):
              # Truncate noise
              y = y[diff // 2 : -((diff + 1) // 2)]
          elif len(y) < len(x):
              # Assume the time-axis is the first: (Time, Channel)
              pad_width = [(diff // 2, (diff + 1) // 2)] + [
                  (0, 0) for _ in range(y.ndim - 1)
              ]
              y = numpy.pad(
                  y,
                  pad_width=pad_width,
                  constant_values=0,
                  mode="constant",
              )
      return y
  
imports: import librosa
  import numpy
  import scipy
  import soundfile
  from espnet.utils.io_utils import SoundHDF5File
label_desc: Use image node_id 3 for calling the SpeedPerturbation obj's underlying member method code with example usage: obj.__call__(x, uttid, train) and returns: y, x