class_docstr: Constructs a UnivNet feature extractor.
  
  This class extracts log-mel-filter bank features from raw speech using the short time Fourier Transform (STFT). The
  STFT implementation follows that of TacoTron 2 and Hifi-GAN.
  
  This feature extractor inherits from [`~feature_extraction_sequence_utils.SequenceFeatureExtractor`] which contains
  most of the main methods. Users should refer to this superclass for more information regarding those methods.
  
  Args:
      feature_size (`int`, *optional*, defaults to 1):
          The feature dimension of the extracted features.
      sampling_rate (`int`, *optional*, defaults to 24000):
          The sampling rate at which the audio files should be digitalized expressed in hertz (Hz).
      padding_value (`float`, *optional*, defaults to 0.0):
          The value to pad with when applying the padding strategy defined by the `padding` argument to
          [`UnivNetFeatureExtractor.__call__`]. Should correspond to audio silence. The `pad_end` argument to
          `__call__` will also use this padding value.
      do_normalize (`bool`, *optional*, defaults to `False`):
          Whether to perform Tacotron 2 normalization on the input. Normalizing can help to significantly improve the
          performance for some models.
      num_mel_bins (`int`, *optional*, defaults to 100):
          The number of mel-frequency bins in the extracted spectrogram features. This should match
          `UnivNetModel.config.num_mel_bins`.
      hop_length (`int`, *optional*, defaults to 256):
          The direct number of samples between sliding windows. Otherwise referred to as "shift" in many papers. Note
          that this is different from other audio feature extractors such as [`SpeechT5FeatureExtractor`] which take
          the `hop_length` in ms.
      win_length (`int`, *optional*, defaults to 1024):
          The direct number of samples for each sliding window. Note that this is different from other audio feature
          extractors such as [`SpeechT5FeatureExtractor`] which take the `win_length` in ms.
      win_function (`str`, *optional*, defaults to `"hann_window"`):
          Name for the window function used for windowing, must be accessible via `torch.{win_function}`
      filter_length (`int`, *optional*, defaults to 1024):
          The number of FFT components to use. If `None`, this is determined using
          `transformers.audio_utils.optimal_fft_length`.
      max_length_s (`int`, *optional*, defaults to 10):
          The maximum input lenght of the model in seconds. This is used to pad the audio.
      fmin (`float`, *optional*, defaults to 0.0):
          Minimum mel frequency in Hz.
      fmax (`float`, *optional*):
          Maximum mel frequency in Hz. If not set, defaults to `sampling_rate / 2`.
      mel_floor (`float`, *optional*, defaults to 1e-09):
          Minimum value of mel frequency banks. Note that the way [`UnivNetFeatureExtractor`] uses `mel_floor` is
          different than in [`transformers.audio_utils.spectrogram`].
      center (`bool`, *optional*, defaults to `False`):
          Whether to pad the waveform so that frame `t` is centered around time `t * hop_length`. If `False`, frame
          `t` will start at time `t * hop_length`.
      compression_factor (`float`, *optional*, defaults to 1.0):
          The multiplicative compression factor for dynamic range compression during spectral normalization.
      compression_clip_val (`float`, *optional*, defaults to 1e-05):
          The clip value applied to the waveform before applying dynamic range compression during spectral
          normalization.
      normalize_min (`float`, *optional*, defaults to -11.512925148010254):
          The min value used for Tacotron 2-style linear normalization. The default is the original value from the
          Tacotron 2 implementation.
      normalize_max (`float`, *optional*, defaults to 2.3143386840820312):
          The max value used for Tacotron 2-style linear normalization. The default is the original value from the
          Tacotron 2 implementation.
      model_in_channels (`int`, *optional*, defaults to 64):
          The number of input channels to the [`UnivNetModel`] model. This should match
          `UnivNetModel.config.model_in_channels`.
      pad_end_length (`int`, *optional*, defaults to 10):
          If padding the end of each waveform, the number of spectrogram frames worth of samples to append. The
          number of appended samples will be `pad_end_length * hop_length`.
      return_attention_mask (`bool`, *optional*, defaults to `True`):
          Whether or not [`~UnivNetFeatureExtractor.__call__`] should return `attention_mask`.
class_docstr_tok: ["Constructs","a","UnivNet","feature","extractor",".","This","class","extracts","log-mel-filter","bank","features","from","raw","speech","using","the","short","time","Fourier","Transform","(","STFT",")",".","The","STFT","implementation","follows","that","of","TacoTron","2","and","Hifi-GAN",".","This","feature","extractor","inherits","from","[","`","~feature_extraction_sequence_utils.SequenceFeatureExtractor","`","]","which","contains","most","of","the","main","methods",".","Users","should","refer","to","this","superclass","for","more","information","regarding","those","methods",".","Args",":","feature_size","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","feature","dimension","of","the","extracted","features",".","sampling_rate","(","`","int","`",",","*","optional","*",",","defaults","to","24000",")",":","The","sampling","rate","at","which","the","audio","files","should","be","digitalized","expressed","in","hertz","(","Hz",")",".","padding_value","(","`","float","`",",","*","optional","*",",","defaults","to","0.0",")",":","The","value","to","pad","with","when","applying","the","padding","strategy","defined","by","the","`","padding","`","argument","to","[","`","UnivNetFeatureExtractor.__call__","`","]",".","Should","correspond","to","audio","silence",".","The","`","pad_end","`","argument","to","`","__call__","`","will","also","use","this","padding","value",".","do_normalize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","perform","Tacotron","2","normalization","on","the","input",".","Normalizing","can","help","to","significantly","improve","the","performance","for","some","models",".","num_mel_bins","(","`","int","`",",","*","optional","*",",","defaults","to","100",")",":","The","number","of","mel-frequency","bins","in","the","extracted","spectrogram","features",".","This","should","match","`","UnivNetModel.config.num_mel_bins","`",".","hop_length","(","`","int","`",",","*","optional","*",",","defaults","to","256",")",":","The","direct","number","of","samples","between","sliding","windows",".","Otherwise","referred","to","as","``","shift","''","in","many","papers",".","Note","that","this","is","different","from","other","audio","feature","extractors","such","as","[","`","SpeechT5FeatureExtractor","`","]","which","take","the","`","hop_length","`","in","ms.","win_length","(","`","int","`",",","*","optional","*",",","defaults","to","1024",")",":","The","direct","number","of","samples","for","each","sliding","window",".","Note","that","this","is","different","from","other","audio","feature","extractors","such","as","[","`","SpeechT5FeatureExtractor","`","]","which","take","the","`","win_length","`","in","ms.","win_function","(","`","str","`",",","*","optional","*",",","defaults","to","`","``","hann_window","''","`",")",":","Name","for","the","window","function","used","for","windowing",",","must","be","accessible","via","`","torch",".","{","win_function","}","`","filter_length","(","`","int","`",",","*","optional","*",",","defaults","to","1024",")",":","The","number","of","FFT","components","to","use",".","If","`","None","`",",","this","is","determined","using","`","transformers.audio_utils.optimal_fft_length","`",".","max_length_s","(","`","int","`",",","*","optional","*",",","defaults","to","10",")",":","The","maximum","input","lenght","of","the","model","in","seconds",".","This","is","used","to","pad","the","audio",".","fmin","(","`","float","`",",","*","optional","*",",","defaults","to","0.0",")",":","Minimum","mel","frequency","in","Hz",".","fmax","(","`","float","`",",","*","optional","*",")",":","Maximum","mel","frequency","in","Hz",".","If","not","set",",","defaults","to","`","sampling_rate","\/","2","`",".","mel_floor","(","`","float","`",",","*","optional","*",",","defaults","to","1e-09",")",":","Minimum","value","of","mel","frequency","banks",".","Note","that","the","way","[","`","UnivNetFeatureExtractor","`","]","uses","`","mel_floor","`","is","different","than","in","[","`","transformers.audio_utils.spectrogram","`","]",".","center","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","pad","the","waveform","so","that","frame","`","t","`","is","centered","around","time","`","t","*","hop_length","`",".","If","`","False","`",",","frame","`","t","`","will","start","at","time","`","t","*","hop_length","`",".","compression_factor","(","`","float","`",",","*","optional","*",",","defaults","to","1.0",")",":","The","multiplicative","compression","factor","for","dynamic","range","compression","during","spectral","normalization",".","compression_clip_val","(","`","float","`",",","*","optional","*",",","defaults","to","1e-05",")",":","The","clip","value","applied","to","the","waveform","before","applying","dynamic","range","compression","during","spectral","normalization",".","normalize_min","(","`","float","`",",","*","optional","*",",","defaults","to","-11.512925148010254",")",":","The","min","value","used","for","Tacotron","2-style","linear","normalization",".","The","default","is","the","original","value","from","the","Tacotron","2","implementation",".","normalize_max","(","`","float","`",",","*","optional","*",",","defaults","to","2.3143386840820312",")",":","The","max","value","used","for","Tacotron","2-style","linear","normalization",".","The","default","is","the","original","value","from","the","Tacotron","2","implementation",".","model_in_channels","(","`","int","`",",","*","optional","*",",","defaults","to","64",")",":","The","number","of","input","channels","to","the","[","`","UnivNetModel","`","]","model",".","This","should","match","`","UnivNetModel.config.model_in_channels","`",".","pad_end_length","(","`","int","`",",","*","optional","*",",","defaults","to","10",")",":","If","padding","the","end","of","each","waveform",",","the","number","of","spectrogram","frames","worth","of","samples","to","append",".","The","number","of","appended","samples","will","be","`","pad_end_length","*","hop_length","`",".","return_attention_mask","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","[","`","~UnivNetFeatureExtractor.__call__","`","]","should","return","`","attention_mask","`","."]
docstr: Calculates log MEL spectrograms from a batch of waveforms. Note that the input waveform(s) will be padded by
  `int(self.n_fft - self.hop_length) / 2` on both sides using the `reflect` padding mode.
  
  Args:
      waveform (`np.ndarray` of shape `(length,)`):
          The input waveform. This must be a single real-valued, mono waveform.
  
  Returns:
      `numpy.ndarray`: Array containing a log-mel spectrogram of shape `(num_frames, num_mel_bins)`.
docstr_tok: ["Calculates","log","MEL","spectrograms","from","a","batch","of","waveforms",".","Note","that","the","input","waveform","(","s",")","will","be","padded","by","`","int","(","self.n_fft","-","self.hop_length",")","\/","2","`","on","both","sides","using","the","`","reflect","`","padding","mode",".","Args",":","waveform","(","`","np.ndarray","`","of","shape","`","(","length",",",")","`",")",":","The","input","waveform",".","This","must","be","a","single","real-valued",",","mono","waveform",".","Returns",":","`","numpy.ndarray","`",":","Array","containing","a","log-mel","spectrogram","of","shape","`","(","num_frames",",","num_mel_bins",")","`","."]
code: def mel_spectrogram(self, waveform: np.ndarray) -> np.ndarray:
      """
      Calculates log MEL spectrograms from a batch of waveforms. Note that the input waveform(s) will be padded by
      `int(self.n_fft - self.hop_length) / 2` on both sides using the `reflect` padding mode.
  
      Args:
          waveform (`np.ndarray` of shape `(length,)`):
              The input waveform. This must be a single real-valued, mono waveform.
  
      Returns:
          `numpy.ndarray`: Array containing a log-mel spectrogram of shape `(num_frames, num_mel_bins)`.
      """
      # Do custom padding based on the official MelGAN and Hifi-GAN implementations
      # See https://github.com/maum-ai/univnet/blob/9bb2b54838bb6d7ce767131cc7b8b61198bc7558/utils/stft.py#L84-L86
      waveform = np.pad(
          waveform,
          (
              int((self.n_fft - self.hop_length) / 2),
              int((self.n_fft - self.hop_length) / 2),
          ),
          mode="reflect",
      )
  
      # Get the complex spectrogram.
      # Note: waveform must be unbatched currently due to the implementation of spectrogram(...).
      complex_spectrogram = spectrogram(
          waveform,
          window=self.window,
          frame_length=self.n_fft,
          hop_length=self.hop_length,
          fft_length=self.n_fft,
          power=None,
          center=self.center,
          mel_filters=None,
          mel_floor=None,
      )
  
      # Apply the MEL filter bank and MEL floor manually since UnivNet uses a slightly different implementation
      amplitude_spectrogram = np.sqrt(
          np.real(complex_spectrogram) ** 2
          + np.imag(complex_spectrogram) ** 2
          + self.mel_floor
      )
      mel_spectrogram = np.matmul(
          self.mel_filters.T, amplitude_spectrogram
      )
  
      # Perform spectral normalization to get the log mel spectrogram.
      log_mel_spectrogram = np.log(
          np.clip(
              mel_spectrogram,
              a_min=self.compression_clip_val,
              a_max=None,
          )
          * self.compression_factor
      )
  
      # Return spectrogram with num_mel_bins last
      return log_mel_spectrogram.T
  
file_path: transformers/src/transformers/models/univnet/feature_extraction_univnet.py
imports: from typing import Any, Dict, List, Optional, Union
  import numpy
  from ...audio_utils import mel_filter_bank, optimal_fft_length, spectrogram, window_function
  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 4 for calling the UnivNetFeatureExtractor obj's underlying member method code with example usage: obj.mel_spectrogram(waveform) and returns: log_mel_spectrogram