code: def mel_filter_bank(
      num_frequency_bins: int,
      num_mel_filters: int,
      min_frequency: float,
      max_frequency: float,
      sampling_rate: int,
      norm: Optional[str] = None,
      mel_scale: str = "htk",
      triangularize_in_mel_space: bool = False,
  ) -> np.ndarray:
      """
      Creates a frequency bin conversion matrix used to obtain a mel spectrogram. This is called a *mel filter bank*, and
      various implementation exist, which differ in the number of filters, the shape of the filters, the way the filters
      are spaced, the bandwidth of the filters, and the manner in which the spectrum is warped. The goal of these
      features is to approximate the non-linear human perception of the variation in pitch with respect to the frequency.
  
      Different banks of mel filters were introduced in the literature. The following variations are supported:
  
      - MFCC FB-20: introduced in 1980 by Davis and Mermelstein, it assumes a sampling frequency of 10 kHz and a speech
        bandwidth of `[0, 4600]` Hz.
      - MFCC FB-24 HTK: from the Cambridge HMM Toolkit (HTK) (1995) uses a filter bank of 24 filters for a speech
        bandwidth of `[0, 8000]` Hz. This assumes sampling rate ≥ 16 kHz.
      - MFCC FB-40: from the Auditory Toolbox for MATLAB written by Slaney in 1998, assumes a sampling rate of 16 kHz and
        speech bandwidth of `[133, 6854]` Hz. This version also includes area normalization.
      - HFCC-E FB-29 (Human Factor Cepstral Coefficients) of Skowronski and Harris (2004), assumes a sampling rate of
        12.5 kHz and speech bandwidth of `[0, 6250]` Hz.
  
      This code is adapted from *torchaudio* and *librosa*. Note that the default parameters of torchaudio's
      `melscale_fbanks` implement the `"htk"` filters while librosa uses the `"slaney"` implementation.
  
      Args:
          num_frequency_bins (`int`):
              Number of frequencies used to compute the spectrogram (should be the same as in `stft`).
          num_mel_filters (`int`):
              Number of mel filters to generate.
          min_frequency (`float`):
              Lowest frequency of interest in Hz.
          max_frequency (`float`):
              Highest frequency of interest in Hz. This should not exceed `sampling_rate / 2`.
          sampling_rate (`int`):
              Sample rate of the audio waveform.
          norm (`str`, *optional*):
              If `"slaney"`, divide the triangular mel weights by the width of the mel band (area normalization).
          mel_scale (`str`, *optional*, defaults to `"htk"`):
              The mel frequency scale to use, `"htk"`, `"kaldi"` or `"slaney"`.
          triangularize_in_mel_space (`bool`, *optional*, defaults to `False`):
              If this option is enabled, the triangular filter is applied in mel space rather than frequency space. This
              should be set to `true` in order to get the same results as `torchaudio` when computing mel filters.
  
      Returns:
          `np.ndarray` of shape (`num_frequency_bins`, `num_mel_filters`): Triangular filter bank matrix. This is a
          projection matrix to go from a spectrogram to a mel spectrogram.
      """
      if norm is not None and norm != "slaney":
          raise ValueError('norm must be one of None or "slaney"')
  
      # center points of the triangular mel filters
      mel_min = hertz_to_mel(min_frequency, mel_scale=mel_scale)
      mel_max = hertz_to_mel(max_frequency, mel_scale=mel_scale)
      mel_freqs = np.linspace(mel_min, mel_max, num_mel_filters + 2)
      filter_freqs = mel_to_hertz(mel_freqs, mel_scale=mel_scale)
  
      if triangularize_in_mel_space:
          # frequencies of FFT bins in Hz, but filters triangularized in mel space
          fft_bin_width = sampling_rate / (num_frequency_bins * 2)
          fft_freqs = hertz_to_mel(
              fft_bin_width * np.arange(num_frequency_bins),
              mel_scale=mel_scale,
          )
          filter_freqs = mel_freqs
      else:
          # frequencies of FFT bins in Hz
          fft_freqs = np.linspace(
              0, sampling_rate // 2, num_frequency_bins
          )
  
      mel_filters = _create_triangular_filter_bank(
          fft_freqs, filter_freqs
      )
  
      if norm is not None and norm == "slaney":
          # Slaney-style mel is scaled to be approx constant energy per channel
          enorm = 2.0 / (
              filter_freqs[2 : num_mel_filters + 2]
              - filter_freqs[:num_mel_filters]
          )
          mel_filters *= np.expand_dims(enorm, 0)
  
      if (mel_filters.max(axis=0) == 0.0).any():
          warnings.warn(
              "At least one mel filter has all zero values. "
              f"The value for `num_mel_filters` ({num_mel_filters}) may be set too high. "
              f"Or, the value for `num_frequency_bins` ({num_frequency_bins}) may be set too low."
          )
  
      return mel_filters
  
file_path: transformers/src/transformers/audio_utils.py
imports: import warnings
  from typing import Optional, Union
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: mel_filter_bank(num_frequency_bins, num_mel_filters, min_frequency, max_frequency, sampling_rate, norm, mel_scale, triangularize_in_mel_space) and returns: mel_filters