class_docstr: Mel-spectrogram loss.
class_docstr_tok: ["Mel-spectrogram","loss","."]
docstr: Calculate Mel-spectrogram loss.
  
  Args:
      y_hat (Tensor): Generated waveform tensor (B, 1, T).
      y (Tensor): Groundtruth waveform tensor (B, 1, T).
      spec (Optional[Tensor]): Groundtruth linear amplitude spectrum tensor
          (B, T, n_fft // 2 + 1).  if provided, use it instead of groundtruth
          waveform.
  
  Returns:
      Tensor: Mel-spectrogram loss value.
docstr_tok: ["Calculate","Mel-spectrogram","loss",".","Args",":","y_hat","(","Tensor",")",":","Generated","waveform","tensor","(","B",",","1",",","T",")",".","y","(","Tensor",")",":","Groundtruth","waveform","tensor","(","B",",","1",",","T",")",".","spec","(","Optional","[","Tensor","]",")",":","Groundtruth","linear","amplitude","spectrum","tensor","(","B",",","T",",","n_fft","\/\/","2","+","1",")",".","if","provided",",","use","it","instead","of","groundtruth","waveform",".","Returns",":","Tensor",":","Mel-spectrogram","loss","value","."]
code: def forward(
      self,
      y_hat: torch.Tensor,
      y: torch.Tensor,
      spec: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      """Calculate Mel-spectrogram loss.
  
      Args:
          y_hat (Tensor): Generated waveform tensor (B, 1, T).
          y (Tensor): Groundtruth waveform tensor (B, 1, T).
          spec (Optional[Tensor]): Groundtruth linear amplitude spectrum tensor
              (B, T, n_fft // 2 + 1).  if provided, use it instead of groundtruth
              waveform.
  
      Returns:
          Tensor: Mel-spectrogram loss value.
  
      """
      mel_hat, _ = self.wav_to_mel(y_hat.squeeze(1))
      if spec is None:
          mel, _ = self.wav_to_mel(y.squeeze(1))
      else:
          mel, _ = self.wav_to_mel.logmel(spec)
      mel_loss = F.l1_loss(mel_hat, mel)
  
      return mel_loss
  
imports: from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from espnet2.tts.feats_extract.log_mel_fbank import LogMelFbank
label_desc: Use image node_id 2 for calling the MelSpectrogramLoss obj's underlying member method code with example usage: obj.forward(y_hat, y, spec) and returns: mel_loss