class_docstr: Energy extractor.
code: def forward(
      self,
      input: torch.Tensor,
      input_lengths: torch.Tensor = None,
      feats_lengths: torch.Tensor = None,
      durations: torch.Tensor = None,
      durations_lengths: torch.Tensor = None,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      # If not provide, we assume that the inputs have the same length
      if input_lengths is None:
          input_lengths = (
              input.new_ones(input.shape[0], dtype=torch.long)
              * input.shape[1]
          )
  
      # Domain-conversion: e.g. Stft: time -> time-freq
      input_stft, energy_lengths = self.stft(input, input_lengths)
  
      assert input_stft.dim() >= 4, input_stft.shape
      assert input_stft.shape[-1] == 2, input_stft.shape
  
      # input_stft: (..., F, 2) -> (..., F)
      input_power = input_stft[..., 0] ** 2 + input_stft[..., 1] ** 2
      # sum over frequency (B, N, F) -> (B, N)
      energy = torch.sqrt(
          torch.clamp(input_power.sum(dim=2), min=1.0e-10)
      )
  
      # (Optional): Adjust length to match with the mel-spectrogram
      if feats_lengths is not None:
          energy = [
              self._adjust_num_frames(e[:el].view(-1), fl)
              for e, el, fl in zip(
                  energy, energy_lengths, feats_lengths
              )
          ]
          energy_lengths = feats_lengths
  
      # (Optional): Average by duration to calculate token-wise energy
      if self.use_token_averaged_energy:
          durations = durations * self.reduction_factor
          energy = [
              self._average_by_duration(e[:el].view(-1), d)
              for e, el, d in zip(energy, energy_lengths, durations)
          ]
          energy_lengths = durations_lengths
  
      # Padding
      if isinstance(energy, list):
          energy = pad_list(energy, 0.0)
  
      # Return with the shape (B, T, 1)
      return energy.unsqueeze(-1), energy_lengths
  
file_path: espnet/espnet2/tts/feats_extract/energy.py
imports: from typing import Any, Dict, Tuple, Union
  import humanfriendly
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.layers.stft import Stft
  from espnet2.tts.feats_extract.abs_feats_extract import AbsFeatsExtract
  from espnet.nets.pytorch_backend.nets_utils import pad_list
label_desc: Use image node_id 4 for calling the Energy obj's underlying member method code with example usage: obj.forward(input, input_lengths, feats_lengths, durations, durations_lengths) and returns: energy,  energy_lengths