class_docstr: Featurizer that converts wavs to Mel Spectrograms.
  See AudioToMelSpectrogramPreprocessor for args.
class_docstr_tok: ["Featurizer","that","converts","wavs","to","Mel","Spectrograms",".","See","AudioToMelSpectrogramPreprocessor","for","args","."]
code: def __init__(
      self,
      sample_rate=16000,
      n_window_size=320,
      n_window_stride=160,
      window="hann",
      normalize="per_feature",
      n_fft=None,
      preemph=0.97,
      nfilt=64,
      lowfreq=0,
      highfreq=None,
      log=True,
      log_zero_guard_type="add",
      log_zero_guard_value=2**-24,
      dither=CONSTANT,
      pad_to=16,
      max_duration=16.7,
      frame_splicing=1,
      exact_pad=False,
      pad_value=0,
      mag_power=2.0,
      use_grads=False,
      rng=None,
      nb_augmentation_prob=0.0,
      nb_max_freq=4000,
      mel_norm="slaney",
      stft_exact_pad=False,  # Deprecated arguments; kept for config compatibility
      stft_conv=False,  # Deprecated arguments; kept for config compatibility
  ):
      super().__init__()
      if stft_conv or stft_exact_pad:
          logging.warning(
              "Using torch_stft is deprecated and has been removed. The values have been forcibly set to False "
              "for FilterbankFeatures and AudioToMelSpectrogramPreprocessor. Please set exact_pad to True "
              "as needed."
          )
      if exact_pad and n_window_stride % 2 == 1:
          raise NotImplementedError(
              f"{self} received exact_pad == True, but hop_size was odd. If audio_length % hop_size == 0. Then the "
              "returned spectrogram would not be of length audio_length // hop_size. Please use an even hop_size."
          )
      self.log_zero_guard_value = log_zero_guard_value
      if (
          n_window_size is None
          or n_window_stride is None
          or not isinstance(n_window_size, int)
          or not isinstance(n_window_stride, int)
          or n_window_size <= 0
          or n_window_stride <= 0
      ):
          raise ValueError(
              f"{self} got an invalid value for either n_window_size or "
              f"n_window_stride. Both must be positive ints."
          )
      logging.info(f"PADDING: {pad_to}")
  
      self.win_length = n_window_size
      self.hop_length = n_window_stride
      self.n_fft = n_fft or 2 ** math.ceil(math.log2(self.win_length))
      self.stft_pad_amount = (
          (self.n_fft - self.hop_length) // 2 if exact_pad else None
      )
  
      if exact_pad:
          logging.info("STFT using exact pad")
      torch_windows = {
          "hann": torch.hann_window,
          "hamming": torch.hamming_window,
          "blackman": torch.blackman_window,
          "bartlett": torch.bartlett_window,
          "none": None,
      }
      window_fn = torch_windows.get(window, None)
      window_tensor = (
          window_fn(self.win_length, periodic=False)
          if window_fn
          else None
      )
      self.register_buffer("window", window_tensor)
      self.stft = lambda x: torch.stft(
          x,
          n_fft=self.n_fft,
          hop_length=self.hop_length,
          win_length=self.win_length,
          center=False if exact_pad else True,
          window=self.window.to(dtype=torch.float),
          return_complex=True,
      )
  
      self.normalize = normalize
      self.log = log
      self.dither = dither
      self.frame_splicing = frame_splicing
      self.nfilt = nfilt
      self.preemph = preemph
      self.pad_to = pad_to
      highfreq = highfreq or sample_rate / 2
  
      filterbanks = torch.tensor(
          librosa.filters.mel(
              sr=sample_rate,
              n_fft=self.n_fft,
              n_mels=nfilt,
              fmin=lowfreq,
              fmax=highfreq,
              norm=mel_norm,
          ),
          dtype=torch.float,
      ).unsqueeze(0)
      self.register_buffer("fb", filterbanks)
  
      # Calculate maximum sequence length
      max_length = self.get_seq_len(
          torch.tensor(max_duration * sample_rate, dtype=torch.float)
      )
      max_pad = pad_to - (max_length % pad_to) if pad_to > 0 else 0
      self.max_length = max_length + max_pad
      self.pad_value = pad_value
      self.mag_power = mag_power
  
      # We want to avoid taking the log of zero
      # There are two options: either adding or clamping to a small value
      if log_zero_guard_type not in ["add", "clamp"]:
          raise ValueError(
              f"{self} received {log_zero_guard_type} for the "
              f"log_zero_guard_type parameter. It must be either 'add' or "
              f"'clamp'."
          )
  
      self.use_grads = use_grads
      if not use_grads:
          self.forward = torch.no_grad()(self.forward)
      self._rng = random.Random() if rng is None else rng
      self.nb_augmentation_prob = nb_augmentation_prob
      if self.nb_augmentation_prob > 0.0:
          if nb_max_freq >= sample_rate / 2:
              self.nb_augmentation_prob = 0.0
          else:
              self._nb_max_fft_bin = int(
                  (nb_max_freq / sample_rate) * n_fft
              )
  
      # log_zero_guard_value is the the small we want to use, we support
      # an actual number, or "tiny", or "eps"
      self.log_zero_guard_type = log_zero_guard_type
      logging.debug(f"sr: {sample_rate}")
      logging.debug(f"n_fft: {self.n_fft}")
      logging.debug(f"win_length: {self.win_length}")
      logging.debug(f"hop_length: {self.hop_length}")
      logging.debug(f"n_mels: {nfilt}")
      logging.debug(f"fmin: {lowfreq}")
      logging.debug(f"fmax: {highfreq}")
      logging.debug(f"using grads: {use_grads}")
      logging.debug(f"nb_augmentation_prob: {nb_augmentation_prob}")
  
imports: import math
  import random
  from typing import Optional, Tuple, Union
  import librosa
  import numpy
  import torch
  import torch.nn
  from nemo.collections.asr.parts.preprocessing.perturb import AudioAugmentor
  from nemo.collections.asr.parts.preprocessing.segment import AudioSegment
  from nemo.utils import logging
label_desc: Use image node_id 1 to create a new FilterbankFeatures object from inherited base classes: nn with example: obj = FilterbankFeatures(sample_rate, n_window_size, n_window_stride, window, normalize, n_fft, preemph, nfilt, lowfreq, highfreq, log, log_zero_guard_type, log_zero_guard_value, dither, pad_to, max_duration, frame_splicing, exact_pad, pad_value, mag_power, use_grads, rng, nb_augmentation_prob, nb_max_freq, mel_norm, stft_exact_pad, stft_conv)