class_docstr: Generator module in JETS.
docstr: Run inference.
  
  Args:
      text (Tensor): Input text index tensor (B, T_text,).
      text_lengths (Tensor): Text length tensor (B,).
      feats (Tensor): Feature tensor (B, T_feats, aux_channels).
      feats_lengths (Tensor): Feature length tensor (B,).
      pitch (Tensor): Pitch tensor (B, T_feats, 1)
      energy (Tensor): Energy tensor (B, T_feats, 1)
      sids (Optional[Tensor]): Speaker index tensor (B,) or (B, 1).
      spembs (Optional[Tensor]): Speaker embedding tensor (B, spk_embed_dim).
      lids (Optional[Tensor]): Language index tensor (B,) or (B, 1).
      use_teacher_forcing (bool): Whether to use teacher forcing.
  
  Returns:
      Tensor: Generated waveform tensor (B, T_wav).
      Tensor: Duration tensor (B, T_text).
docstr_tok: ["Run","inference",".","Args",":","text","(","Tensor",")",":","Input","text","index","tensor","(","B",",","T_text",",",")",".","text_lengths","(","Tensor",")",":","Text","length","tensor","(","B",",",")",".","feats","(","Tensor",")",":","Feature","tensor","(","B",",","T_feats",",","aux_channels",")",".","feats_lengths","(","Tensor",")",":","Feature","length","tensor","(","B",",",")",".","pitch","(","Tensor",")",":","Pitch","tensor","(","B",",","T_feats",",","1",")","energy","(","Tensor",")",":","Energy","tensor","(","B",",","T_feats",",","1",")","sids","(","Optional","[","Tensor","]",")",":","Speaker","index","tensor","(","B",",",")","or","(","B",",","1",")",".","spembs","(","Optional","[","Tensor","]",")",":","Speaker","embedding","tensor","(","B",",","spk_embed_dim",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","index","tensor","(","B",",",")","or","(","B",",","1",")",".","use_teacher_forcing","(","bool",")",":","Whether","to","use","teacher","forcing",".","Returns",":","Tensor",":","Generated","waveform","tensor","(","B",",","T_wav",")",".","Tensor",":","Duration","tensor","(","B",",","T_text",")","."]
code: def inference(
      self,
      text: torch.Tensor,
      text_lengths: torch.Tensor,
      feats: Optional[torch.Tensor] = None,
      feats_lengths: Optional[torch.Tensor] = None,
      pitch: Optional[torch.Tensor] = None,
      energy: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      use_teacher_forcing: bool = False,
  ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
      """Run inference.
  
      Args:
          text (Tensor): Input text index tensor (B, T_text,).
          text_lengths (Tensor): Text length tensor (B,).
          feats (Tensor): Feature tensor (B, T_feats, aux_channels).
          feats_lengths (Tensor): Feature length tensor (B,).
          pitch (Tensor): Pitch tensor (B, T_feats, 1)
          energy (Tensor): Energy tensor (B, T_feats, 1)
          sids (Optional[Tensor]): Speaker index tensor (B,) or (B, 1).
          spembs (Optional[Tensor]): Speaker embedding tensor (B, spk_embed_dim).
          lids (Optional[Tensor]): Language index tensor (B,) or (B, 1).
          use_teacher_forcing (bool): Whether to use teacher forcing.
  
      Returns:
          Tensor: Generated waveform tensor (B, T_wav).
          Tensor: Duration tensor (B, T_text).
  
      """
      # forward encoder
      x_masks = self._source_mask(text_lengths)
      hs, _ = self.encoder(text, x_masks)  # (B, T_text, adim)
  
      # integrate with GST
      if self.use_gst:
          style_embs = self.gst(feats)
          hs = hs + style_embs.unsqueeze(1)
  
      # integrate with SID and LID embeddings
      if self.spks is not None:
          sid_embs = self.sid_emb(sids.view(-1))
          hs = hs + sid_embs.unsqueeze(1)
      if self.langs is not None:
          lid_embs = self.lid_emb(lids.view(-1))
          hs = hs + lid_embs.unsqueeze(1)
  
      # integrate speaker embedding
      if self.spk_embed_dim is not None:
          hs = self._integrate_with_spk_embed(hs, spembs)
  
      h_masks = make_pad_mask(text_lengths).to(hs.device)
      if use_teacher_forcing:
          # forward alignment module and obtain duration, averaged pitch, energy
          log_p_attn = self.alignment_module(
              hs,
              feats,
              text_lengths,
              feats_lengths,
              h_masks,
          )
          d_outs, _ = viterbi_decode(
              log_p_attn, text_lengths, feats_lengths
          )
          p_outs = average_by_duration(
              d_outs, pitch.squeeze(-1), text_lengths, feats_lengths
          ).unsqueeze(-1)
          e_outs = average_by_duration(
              d_outs, energy.squeeze(-1), text_lengths, feats_lengths
          ).unsqueeze(-1)
      else:
          # forward duration predictor and variance predictors
          p_outs = self.pitch_predictor(hs, h_masks.unsqueeze(-1))
          e_outs = self.energy_predictor(hs, h_masks.unsqueeze(-1))
          d_outs = self.duration_predictor.inference(hs, h_masks)
  
      p_embs = self.pitch_embed(p_outs.transpose(1, 2)).transpose(1, 2)
      e_embs = self.energy_embed(e_outs.transpose(1, 2)).transpose(1, 2)
      hs = hs + e_embs + p_embs
  
      # upsampling
      if feats_lengths is not None:
          h_masks = make_non_pad_mask(feats_lengths).to(hs.device)
      else:
          h_masks = None
      d_masks = make_non_pad_mask(text_lengths).to(d_outs.device)
      hs = self.length_regulator(
          hs, d_outs, h_masks, d_masks
      )  # (B, T_feats, adim)
  
      # forward decoder
      if feats_lengths is not None:
          h_masks = self._source_mask(feats_lengths)
      else:
          h_masks = None
      zs, _ = self.decoder(hs, h_masks)  # (B, T_feats, adim)
  
      # forward generator
      wav = self.generator(zs.transpose(1, 2))
  
      return wav.squeeze(1), d_outs
  
imports: import logging
  from typing import Any, Dict, List, Optional, Sequence, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from espnet2.gan_tts.hifigan import HiFiGANGenerator
  from espnet2.gan_tts.jets.alignments import AlignmentModule, average_by_duration, viterbi_decode
  from espnet2.gan_tts.jets.length_regulator import GaussianUpsampling
  from espnet2.gan_tts.utils import get_random_segments
  from espnet2.torch_utils.initialize import initialize
  from espnet2.tts.fastspeech2.variance_predictor import VariancePredictor
  from espnet2.tts.gst.style_encoder import StyleEncoder
  from espnet.nets.pytorch_backend.conformer.encoder import Encoder
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictor
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, make_pad_mask
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
label_desc: Use image node_id 3 for calling the JETSGenerator obj's underlying member method code with example usage: obj.inference(text, text_lengths, feats, feats_lengths, pitch, energy, sids, spembs, lids, use_teacher_forcing) and returns: wav,  d_outs