class_docstr: Transformer-based Speech Encoder from OpenAI's Whisper Model:
  
  URL: https://github.com/openai/whisper
class_docstr_tok: ["Transformer-based","Speech","Encoder","from","OpenAI","'s","Whisper","Model",":","URL",":","https",":","\/\/github.com\/openai\/whisper"]
docstr: Pad or trim the audio array to N_SAMPLES.
  
  Used in zero-shot inference cases.
docstr_tok: ["Pad","or","trim","the","audio","array","to","N_SAMPLES",".","Used","in","zero-shot","inference","cases","."]
code: def pad_or_trim(
      self,
      array: torch.Tensor,
      length: int,
      axis: int = -1,
  ) -> torch.Tensor:
      """Pad or trim the audio array to N_SAMPLES.
  
      Used in zero-shot inference cases.
      """
      if array.shape[axis] > length:
          array = array.index_select(
              dim=axis, index=torch.arange(length).to(array.device)
          )
  
      if array.shape[axis] < length:
          pad_widths = [(0, 0)] * array.ndim
          pad_widths[axis] = (0, length - array.shape[axis])
          array = F.pad(
              array,
              [pad for sizes in pad_widths[::-1] for pad in sizes],
          )
  
      return array
  
file_path: espnet/espnet2/asr/encoder/whisper_encoder.py
imports: import copy
  from typing import Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.specaug.specaug import SpecAug
label_desc: Use image node_id 3 for calling the OpenAIWhisperEncoder obj's underlying member method code with example usage: obj.pad_or_trim(array, length, axis) and returns: array