class_docstr: Constructs a Speech2Text feature extractor.
  
  This feature extractor inherits from [`Speech2TextFeatureExtractor`] which contains most of the main methods. Users
  should refer to this superclass for more information regarding those methods.
  
  This class extracts mel-filter bank features from raw speech using TorchAudio and applies utterance-level cepstral
  mean and variance normalization to the extracted features.
  
  Args:
      feature_size (`int`, defaults to 80):
          The feature dimension of the extracted features.
      sampling_rate (`int`, defaults to 16000):
          The sampling rate at which the audio files should be digitalized expressed in Hertz per second (Hz).
      num_mel_bins (`int`, defaults to 80):
          Number of Mel-frequency bins.
      padding_value (`float`, defaults to 0.0):
          The value that is used to fill the padding vectors.
      do_ceptral_normalize (`bool`, *optional*, defaults to `True`):
          Whether or not to apply utterance-level cepstral mean and variance normalization to extracted features.
      normalize_means (`bool`, *optional*, defaults to `True`):
          Whether or not to zero-mean normalize the extracted features.
      normalize_vars (`bool`, *optional*, defaults to `True`):
          Whether or not to unit-variance normalize the extracted features.
docstr: Main method to featurize and prepare for the model one or several sequence(s).
  
  Args:
      raw_speech (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
          The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
          values, a list of numpy arrays or a list of list of float values.
      padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `True`):
          Select a strategy to pad the returned sequences (according to the model's padding side and padding
          index) among:
  
          - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
            sequence if provided).
          - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
            acceptable input length for the model if that argument is not provided.
          - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
            lengths).
      max_length (`int`, *optional*):
          Maximum length of the returned list and optionally padding length (see above).
      truncation (`bool`):
          Activates truncation to cut input sequences longer than *max_length* to *max_length*.
      pad_to_multiple_of (`int`, *optional*):
          If set will pad the sequence to a multiple of the provided value.
  
          This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
          >= 7.5 (Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128.
      return_attention_mask (`bool`, *optional*):
          Whether to return the attention mask. If left to the default, will return the attention mask according
          to the specific feature_extractor's default.
  
          [What are attention masks?](../glossary#attention-mask)
  
          <Tip>
  
          For Speech2TextTransoformer models, `attention_mask` should alwys be passed for batched inference, to
          avoid subtle bugs.
  
          </Tip>
  
      return_tensors (`str` or [`~utils.TensorType`], *optional*):
          If set, will return tensors instead of list of python integers. Acceptable values are:
  
          - `'tf'`: Return TensorFlow `tf.constant` objects.
          - `'pt'`: Return PyTorch `torch.Tensor` objects.
          - `'np'`: Return Numpy `np.ndarray` objects.
      sampling_rate (`int`, *optional*):
          The sampling rate at which the `raw_speech` input was sampled. It is strongly recommended to pass
          `sampling_rate` at the forward call to prevent silent errors.
      padding_value (`float`, defaults to 0.0):
          The value that is used to fill the padding values / vectors.
docstr_tok: ["Main","method","to","featurize","and","prepare","for","the","model","one","or","several","sequence","(","s",")",".","Args",":","raw_speech","(","`","np.ndarray","`",",","`","List","[","float","]","`",",","`","List","[","np.ndarray","]","`",",","`","List","[","List","[","float","]","]","`",")",":","The","sequence","or","batch","of","sequences","to","be","padded",".","Each","sequence","can","be","a","numpy","array",",","a","list","of","float","values",",","a","list","of","numpy","arrays","or","a","list","of","list","of","float","values",".","padding","(","`","bool","`",",","`","str","`","or","[","`","~utils.PaddingStrategy","`","]",",","*","optional","*",",","defaults","to","`","True","`",")",":","Select","a","strategy","to","pad","the","returned","sequences","(","according","to","the","model","'s","padding","side","and","padding","index",")","among",":","-","`","True","`","or","`","'longest","'","`",":","Pad","to","the","longest","sequence","in","the","batch","(","or","no","padding","if","only","a","single","sequence","if","provided",")",".","-","`","'max_length","'","`",":","Pad","to","a","maximum","length","specified","with","the","argument","`","max_length","`","or","to","the","maximum","acceptable","input","length","for","the","model","if","that","argument","is","not","provided",".","-","`","False","`","or","`","'do_not_pad","'","`","(","default",")",":","No","padding","(","i.e.",",","can","output","a","batch","with","sequences","of","different","lengths",")",".","max_length","(","`","int","`",",","*","optional","*",")",":","Maximum","length","of","the","returned","list","and","optionally","padding","length","(","see","above",")",".","truncation","(","`","bool","`",")",":","Activates","truncation","to","cut","input","sequences","longer","than","*","max_length","*","to","*","max_length","*",".","pad_to_multiple_of","(","`","int","`",",","*","optional","*",")",":","If","set","will","pad","the","sequence","to","a","multiple","of","the","provided","value",".","This","is","especially","useful","to","enable","the","use","of","Tensor","Cores","on","NVIDIA","hardware","with","compute","capability",">","=","7.5","(","Volta",")",",","or","on","TPUs","which","benefit","from","having","sequence","lengths","be","a","multiple","of","128.","return_attention_mask","(","`","bool","`",",","*","optional","*",")",":","Whether","to","return","the","attention","mask",".","If","left","to","the","default",",","will","return","the","attention","mask","according","to","the","specific","feature_extractor","'s","default",".","[","What","are","attention","masks","?","]","(","..","\/glossary","#","attention-mask",")","<","Tip",">","For","Speech2TextTransoformer","models",",","`","attention_mask","`","should","alwys","be","passed","for","batched","inference",",","to","avoid","subtle","bugs",".","<","\/Tip",">","return_tensors","(","`","str","`","or","[","`","~utils.TensorType","`","]",",","*","optional","*",")",":","If","set",",","will","return","tensors","instead","of","list","of","python","integers",".","Acceptable","values","are",":","-","`","'tf","'","`",":","Return","TensorFlow","`","tf.constant","`","objects",".","-","`","'pt","'","`",":","Return","PyTorch","`","torch.Tensor","`","objects",".","-","`","'np","'","`",":","Return","Numpy","`","np.ndarray","`","objects",".","sampling_rate","(","`","int","`",",","*","optional","*",")",":","The","sampling","rate","at","which","the","`","raw_speech","`","input","was","sampled",".","It","is","strongly","recommended","to","pass","`","sampling_rate","`","at","the","forward","call","to","prevent","silent","errors",".","padding_value","(","`","float","`",",","defaults","to","0.0",")",":","The","value","that","is","used","to","fill","the","padding","values","\/","vectors","."]
code: def __call__(
      self,
      raw_speech: Union[
          np.ndarray, List[float], List[np.ndarray], List[List[float]]
      ],
      padding: Union[bool, str, PaddingStrategy] = False,
      max_length: Optional[int] = None,
      truncation: bool = False,
      pad_to_multiple_of: Optional[int] = None,
      return_tensors: Optional[Union[str, TensorType]] = None,
      sampling_rate: Optional[int] = None,
      return_attention_mask: Optional[bool] = None,
      **kwargs,
  ) -> BatchFeature:
      """
      Main method to featurize and prepare for the model one or several sequence(s).
  
      Args:
          raw_speech (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
              The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
              values, a list of numpy arrays or a list of list of float values.
          padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `True`):
              Select a strategy to pad the returned sequences (according to the model's padding side and padding
              index) among:
  
              - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
                sequence if provided).
              - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
                acceptable input length for the model if that argument is not provided.
              - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
                lengths).
          max_length (`int`, *optional*):
              Maximum length of the returned list and optionally padding length (see above).
          truncation (`bool`):
              Activates truncation to cut input sequences longer than *max_length* to *max_length*.
          pad_to_multiple_of (`int`, *optional*):
              If set will pad the sequence to a multiple of the provided value.
  
              This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
              >= 7.5 (Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128.
          return_attention_mask (`bool`, *optional*):
              Whether to return the attention mask. If left to the default, will return the attention mask according
              to the specific feature_extractor's default.
  
              [What are attention masks?](../glossary#attention-mask)
  
              <Tip>
  
              For Speech2TextTransoformer models, `attention_mask` should alwys be passed for batched inference, to
              avoid subtle bugs.
  
              </Tip>
  
          return_tensors (`str` or [`~utils.TensorType`], *optional*):
              If set, will return tensors instead of list of python integers. Acceptable values are:
  
              - `'tf'`: Return TensorFlow `tf.constant` objects.
              - `'pt'`: Return PyTorch `torch.Tensor` objects.
              - `'np'`: Return Numpy `np.ndarray` objects.
          sampling_rate (`int`, *optional*):
              The sampling rate at which the `raw_speech` input was sampled. It is strongly recommended to pass
              `sampling_rate` at the forward call to prevent silent errors.
          padding_value (`float`, defaults to 0.0):
              The value that is used to fill the padding values / vectors.
      """
  
      if sampling_rate is not None:
          if sampling_rate != self.sampling_rate:
              raise ValueError(
                  f"The model corresponding to this feature extractor: {self} was trained using a sampling rate of"
                  f" {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with"
                  f" {self.sampling_rate} and not {sampling_rate}."
              )
      else:
          logger.warning(
              "It is strongly recommended to pass the `sampling_rate` argument to this function. "
              "Failing to do so can result in silent errors that might be hard to debug."
          )
  
      is_batched = bool(
          isinstance(raw_speech, (list, tuple))
          and (
              isinstance(raw_speech[0], np.ndarray)
              or isinstance(raw_speech[0], (tuple, list))
          )
      )
  
      if is_batched:
          raw_speech = [
              np.asarray(speech, dtype=np.float32)
              for speech in raw_speech
          ]
      elif not is_batched and not isinstance(raw_speech, np.ndarray):
          raw_speech = np.asarray(raw_speech, dtype=np.float32)
      elif isinstance(
          raw_speech, np.ndarray
      ) and raw_speech.dtype is np.dtype(np.float64):
          raw_speech = raw_speech.astype(np.float32)
  
      # always return batch
      if not is_batched:
          raw_speech = [raw_speech]
  
      # extract fbank features
      features = [
          self._extract_fbank_features(waveform)
          for waveform in raw_speech
      ]
  
      # convert into correct format for padding
      encoded_inputs = BatchFeature({"input_features": features})
  
      padded_inputs = self.pad(
          encoded_inputs,
          padding=padding,
          max_length=max_length,
          truncation=truncation,
          pad_to_multiple_of=pad_to_multiple_of,
          return_attention_mask=return_attention_mask,
          **kwargs,
      )
  
      # make sure list is in array format
      input_features = padded_inputs.get("input_features")
      if isinstance(input_features[0], list):
          padded_inputs["input_features"] = [
              np.asarray(feature, dtype=np.float32)
              for feature in input_features
          ]
  
      attention_mask = padded_inputs.get("attention_mask")
      if attention_mask is not None:
          padded_inputs["attention_mask"] = [
              np.asarray(array, dtype=np.int32)
              for array in attention_mask
          ]
  
      # Utterance-level cepstral mean and variance normalization
      if self.do_ceptral_normalize:
          attention_mask = (
              np.array(attention_mask, dtype=np.int32)
              if self._get_padding_strategies(
                  padding, max_length=max_length
              )
              is not PaddingStrategy.DO_NOT_PAD
              else None
          )
          padded_inputs["input_features"] = self.normalize(
              padded_inputs["input_features"],
              attention_mask=attention_mask,
          )
  
      if return_tensors is not None:
          padded_inputs = padded_inputs.convert_to_tensors(
              return_tensors
          )
  
      return padded_inputs
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py
imports: from typing import List, Optional, Union
  import numpy
  import torch
  import torchaudio.compliance.kaldi
  from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
  from ...feature_extraction_utils import BatchFeature
  from ...utils import PaddingStrategy, TensorType, logging
label_desc: Use image node_id 5 for calling the Speech2TextFeatureExtractor obj's underlying member method code with example usage: obj.__call__(raw_speech, padding, max_length, truncation, pad_to_multiple_of, return_tensors, sampling_rate, return_attention_mask) and returns: padded_inputs