class_docstr: Speech Representation Using Encoder Outputs from OpenAI's Whisper Model:
  
  URL: https://github.com/openai/whisper
class_docstr_tok: ["Speech","Representation","Using","Encoder","Outputs","from","OpenAI","'s","Whisper","Model",":","URL",":","https",":","\/\/github.com\/openai\/whisper"]
code: def log_mel_spectrogram(
      self,
      audio: torch.Tensor,
      ilens: torch.Tensor = None,
  ) -> torch.Tensor:
      window = torch.hann_window(self.win_length).to(audio.device)
      stft = torch.stft(
          audio,
          self.n_fft,
          self.hop_length,
          window=window,
          return_complex=True,
      )
  
      # whisper deletes the last frame by default (Shih-Lun)
      magnitudes = stft[..., :-1].abs() ** 2
  
      filters = self.mel_filters(audio.device, self.n_mels)
      mel_spec = filters @ magnitudes
  
      log_spec = torch.clamp(mel_spec, min=1e-10).log10()
  
      if ilens is not None:
          olens = ilens // self.hop_length
      else:
          olens = None
  
      log_spec = torch.maximum(
          log_spec,
          log_spec.view(audio.size(0), -1).max(dim=-1)[0][:, None, None]
          - 8.0,
      )
      log_spec = (log_spec + 4.0) / 4.0
  
      return log_spec, olens
  
file_path: espnet/espnet2/asr/frontend/whisper.py
imports: import contextlib
  from typing import Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
label_desc: Use image node_id 3 for calling the WhisperFrontend obj's underlying member method code with example usage: obj.log_mel_spectrogram(audio, ilens) and returns: log_spec,  olens