class_docstr: This function is to calculate the Melspectrogram of the input signal.
  Input signal should be in either of the following shapes.
  
  1. ``(len_audio)``
  
  2. ``(num_audio, len_audio)``
  
  3. ``(num_audio, 1, len_audio)``
  
  The correct shape will be inferred automatically if the input follows these 3 shapes.
  Most of the arguments follow the convention from librosa.
  This class inherits from ``nn.Module``, therefore, the usage is same as ``nn.Module``.
  
  Parameters
  ----------
  sr : int
      The sampling rate for the input audio.
      It is used to calculate the correct ``fmin`` and ``fmax``.
      Setting the correct sampling rate is very important for calculating the correct frequency.
  
  n_fft : int
      The window size for the STFT. Default value is 2048
  
  win_length : int
      the size of window frame and STFT filter.
      Default: None (treated as equal to n_fft)
  
  n_mels : int
      The number of Mel filter banks. The filter banks maps the n_fft to mel bins.
      Default value is 128.
  
  hop_length : int
      The hop (or stride) size. Default value is 512.
  
  window : str
      The windowing function for STFT. It uses ``scipy.signal.get_window``, please refer to
      scipy documentation for possible windowing functions. The default value is 'hann'.
  
  center : bool
      Putting the STFT keneral at the center of the time-step or not. If ``False``,
      the time index is the beginning of the STFT kernel, if ``True``, the time index is the
      center of the STFT kernel. Default value if ``True``.
  
  pad_mode : str
      The padding method. Default value is 'reflect'.
  
  htk : bool
      When ``False`` is used, the Mel scale is quasi-logarithmic. When ``True`` is used, the
      Mel scale is logarithmic. The default value is ``False``.
  
  fmin : int
      The starting frequency for the lowest Mel filter bank.
  
  fmax : int
      The ending frequency for the highest Mel filter bank.
  
  norm :
      if 1, divide the triangular mel weights by the width of the mel band
      (area normalization, AKA 'slaney' default in librosa).
      Otherwise, leave all the triangles aiming for
      a peak value of 1.0
  
  trainable_mel : bool
      Determine if the Mel filter banks are trainable or not. If ``True``, the gradients for Mel
      filter banks will also be calculated and the Mel filter banks will be updated during model
      training. Default value is ``False``.
  
  trainable_STFT : bool
      Determine if the STFT kenrels are trainable or not. If ``True``, the gradients for STFT
      kernels will also be caluclated and the STFT kernels will be updated during model training.
      Default value is ``False``.
  
  verbose : bool
      If ``True``, it shows layer information. If ``False``, it suppresses all prints.
  
  Returns
  -------
  spectrogram : torch.tensor
      It returns a tensor of spectrograms.  shape = ``(num_samples, freq_bins,time_steps)``.
  
  Examples
  --------
  >>> spec_layer = Spectrogram.MelSpectrogram()
  >>> specs = spec_layer(x)
class_docstr_tok: ["This","function","is","to","calculate","the","Melspectrogram","of","the","input","signal",".","Input","signal","should","be","in","either","of","the","following","shapes",".","1",".","``","(","len_audio",")","``","2",".","``","(","num_audio",",","len_audio",")","``","3",".","``","(","num_audio",",","1",",","len_audio",")","``","The","correct","shape","will","be","inferred","automatically","if","the","input","follows","these","3","shapes",".","Most","of","the","arguments","follow","the","convention","from","librosa",".","This","class","inherits","from","``","nn.Module","``",",","therefore",",","the","usage","is","same","as","``","nn.Module","``",".","Parameters","--","--","--","--","--","sr",":","int","The","sampling","rate","for","the","input","audio",".","It","is","used","to","calculate","the","correct","``","fmin","``","and","``","fmax","``",".","Setting","the","correct","sampling","rate","is","very","important","for","calculating","the","correct","frequency",".","n_fft",":","int","The","window","size","for","the","STFT",".","Default","value","is","2048","win_length",":","int","the","size","of","window","frame","and","STFT","filter",".","Default",":","None","(","treated","as","equal","to","n_fft",")","n_mels",":","int","The","number","of","Mel","filter","banks",".","The","filter","banks","maps","the","n_fft","to","mel","bins",".","Default","value","is","128.","hop_length",":","int","The","hop","(","or","stride",")","size",".","Default","value","is","512.","window",":","str","The","windowing","function","for","STFT",".","It","uses","``","scipy.signal.get_window","``",",","please","refer","to","scipy","documentation","for","possible","windowing","functions",".","The","default","value","is","'hann","'",".","center",":","bool","Putting","the","STFT","keneral","at","the","center","of","the","time-step","or","not",".","If","``","False","``",",","the","time","index","is","the","beginning","of","the","STFT","kernel",",","if","``","True","``",",","the","time","index","is","the","center","of","the","STFT","kernel",".","Default","value","if","``","True","``",".","pad_mode",":","str","The","padding","method",".","Default","value","is","'reflect","'",".","htk",":","bool","When","``","False","``","is","used",",","the","Mel","scale","is","quasi-logarithmic",".","When","``","True","``","is","used",",","the","Mel","scale","is","logarithmic",".","The","default","value","is","``","False","``",".","fmin",":","int","The","starting","frequency","for","the","lowest","Mel","filter","bank",".","fmax",":","int","The","ending","frequency","for","the","highest","Mel","filter","bank",".","norm",":","if","1",",","divide","the","triangular","mel","weights","by","the","width","of","the","mel","band","(","area","normalization",",","AKA","'slaney","'","default","in","librosa",")",".","Otherwise",",","leave","all","the","triangles","aiming","for","a","peak","value","of","1.0","trainable_mel",":","bool","Determine","if","the","Mel","filter","banks","are","trainable","or","not",".","If","``","True","``",",","the","gradients","for","Mel","filter","banks","will","also","be","calculated","and","the","Mel","filter","banks","will","be","updated","during","model","training",".","Default","value","is","``","False","``",".","trainable_STFT",":","bool","Determine","if","the","STFT","kenrels","are","trainable","or","not",".","If","``","True","``",",","the","gradients","for","STFT","kernels","will","also","be","caluclated","and","the","STFT","kernels","will","be","updated","during","model","training",".","Default","value","is","``","False","``",".","verbose",":","bool","If","``","True","``",",","it","shows","layer","information",".","If","``","False","``",",","it","suppresses","all","prints",".","Returns","--","--","--","-","spectrogram",":","torch.tensor","It","returns","a","tensor","of","spectrograms",".","shape","=","``","(","num_samples",",","freq_bins",",","time_steps",")","``",".","Examples","--","--","--","--",">",">",">","spec_layer","=","Spectrogram.MelSpectrogram","(",")",">",">",">","specs","=","spec_layer","(","x",")"]
code: def __init__(
      self,
      sr=22050,
      n_fft=2048,
      win_length=None,
      n_mels=128,
      hop_length=512,
      window="hann",
      center=True,
      pad_mode="reflect",
      power=2.0,
      htk=False,
      fmin=0.0,
      fmax=None,
      norm=1,
      trainable_mel=False,
      trainable_STFT=False,
      verbose=True,
      **kwargs,
  ):
      super().__init__()
      self.stride = hop_length
      self.center = center
      self.pad_mode = pad_mode
      self.n_fft = n_fft
      self.power = power
      self.trainable_mel = trainable_mel
      self.trainable_STFT = trainable_STFT
  
      # Preparing for the stft layer. No need for center
      self.stft = STFT(
          n_fft=n_fft,
          win_length=win_length,
          freq_bins=None,
          hop_length=hop_length,
          window=window,
          freq_scale="no",
          center=center,
          pad_mode=pad_mode,
          sr=sr,
          trainable=trainable_STFT,
          output_format="Magnitude",
          verbose=verbose,
          **kwargs,
      )
  
      # Create filter windows for stft
      start = time()
  
      # Creating kernel for mel spectrogram
      start = time()
      mel_basis = get_mel(
          sr, n_fft, n_mels, fmin, fmax, htk=htk, norm=norm
      )
      mel_basis = torch.tensor(mel_basis)
  
      if verbose == True:
          print(
              "STFT filter created, time used = {:.4f} seconds".format(
                  time() - start
              )
          )
          print(
              "Mel filter created, time used = {:.4f} seconds".format(
                  time() - start
              )
          )
      else:
          pass
  
      if trainable_mel:
          # Making everything nn.Parameter, so that this model can support nn.DataParallel
          mel_basis = nn.Parameter(
              mel_basis, requires_grad=trainable_mel
          )
          self.register_parameter("mel_basis", mel_basis)
      else:
          self.register_buffer("mel_basis", mel_basis)
  
file_path: nnAudio/Installation/nnAudio/features/mel.py
imports: import torch.nn
  import torch
  import numpy
  from time import time
  from ..utils import *
  from .stft import STFT
label_desc: Use image node_id 1 to create a new MelSpectrogram object from inherited base classes: nn with example: obj = MelSpectrogram(sr, n_fft, win_length, n_mels, hop_length, window, center, pad_mode, power, htk, fmin, fmax, norm, trainable_mel, trainable_STFT, verbose)