class_docstr: FastSpeech2 module.
  
  This is a module of FastSpeech2 described in `FastSpeech 2: Fast and
  High-Quality End-to-End Text to Speech`_. Instead of quantized pitch and
  energy, we use token-averaged value introduced in `FastPitch: Parallel
  Text-to-speech with Pitch Prediction`_.
  
  .. _`FastSpeech 2: Fast and High-Quality End-to-End Text to Speech`:
      https://arxiv.org/abs/2006.04558
  .. _`FastPitch: Parallel Text-to-speech with Pitch Prediction`:
      https://arxiv.org/abs/2006.06873
class_docstr_tok: ["FastSpeech2","module",".","This","is","a","module","of","FastSpeech2","described","in","`","FastSpeech","2",":","Fast","and","High-Quality","End-to-End","Text","to","Speech","`","_",".","Instead","of","quantized","pitch","and","energy",",","we","use","token-averaged","value","introduced","in","`","FastPitch",":","Parallel","Text-to-speech","with","Pitch","Prediction","`","_",".","..","_","`","FastSpeech","2",":","Fast","and","High-Quality","End-to-End","Text","to","Speech","`",":","https",":","\/\/arxiv.org\/abs\/2006.04558","..","_","`","FastPitch",":","Parallel","Text-to-speech","with","Pitch","Prediction","`",":","https",":","\/\/arxiv.org\/abs\/2006.06873"]
docstr: Generate the sequence of features given the sequences of characters.
  
  Args:
      text (LongTensor): Input sequence of characters (T_text,).
      feats (Optional[Tensor): Feature sequence to extract style (N, idim).
      durations (Optional[Tensor): Groundtruth of duration (T_text + 1,).
      spembs (Optional[Tensor): Speaker embedding vector (spk_embed_dim,).
      sids (Optional[Tensor]): Speaker ID (1,).
      lids (Optional[Tensor]): Language ID (1,).
      pitch (Optional[Tensor]): Groundtruth of token-avg pitch (T_text + 1, 1).
      energy (Optional[Tensor]): Groundtruth of token-avg energy (T_text + 1, 1).
      alpha (float): Alpha to control the speed.
      use_teacher_forcing (bool): Whether to use teacher forcing.
          If true, groundtruth of duration, pitch and energy will be used.
  
  Returns:
      Dict[str, Tensor]: Output dict including the following items:
          * feat_gen (Tensor): Output sequence of features (T_feats, odim).
          * duration (Tensor): Duration sequence (T_text + 1,).
          * pitch (Tensor): Pitch sequence (T_text + 1,).
          * energy (Tensor): Energy sequence (T_text + 1,).
docstr_tok: ["Generate","the","sequence","of","features","given","the","sequences","of","characters",".","Args",":","text","(","LongTensor",")",":","Input","sequence","of","characters","(","T_text",",",")",".","feats","(","Optional","[","Tensor",")",":","Feature","sequence","to","extract","style","(","N",",","idim",")",".","durations","(","Optional","[","Tensor",")",":","Groundtruth","of","duration","(","T_text","+","1",",",")",".","spembs","(","Optional","[","Tensor",")",":","Speaker","embedding","vector","(","spk_embed_dim",",",")",".","sids","(","Optional","[","Tensor","]",")",":","Speaker","ID","(","1",",",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","ID","(","1",",",")",".","pitch","(","Optional","[","Tensor","]",")",":","Groundtruth","of","token-avg","pitch","(","T_text","+","1",",","1",")",".","energy","(","Optional","[","Tensor","]",")",":","Groundtruth","of","token-avg","energy","(","T_text","+","1",",","1",")",".","alpha","(","float",")",":","Alpha","to","control","the","speed",".","use_teacher_forcing","(","bool",")",":","Whether","to","use","teacher","forcing",".","If","true",",","groundtruth","of","duration",",","pitch","and","energy","will","be","used",".","Returns",":","Dict","[","str",",","Tensor","]",":","Output","dict","including","the","following","items",":","*","feat_gen","(","Tensor",")",":","Output","sequence","of","features","(","T_feats",",","odim",")",".","*","duration","(","Tensor",")",":","Duration","sequence","(","T_text","+","1",",",")",".","*","pitch","(","Tensor",")",":","Pitch","sequence","(","T_text","+","1",",",")",".","*","energy","(","Tensor",")",":","Energy","sequence","(","T_text","+","1",",",")","."]
code: def inference(
      self,
      text: torch.Tensor,
      feats: Optional[torch.Tensor] = None,
      durations: Optional[torch.Tensor] = None,
      spembs: torch.Tensor = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      pitch: Optional[torch.Tensor] = None,
      energy: Optional[torch.Tensor] = None,
      alpha: float = 1.0,
      use_teacher_forcing: bool = False,
  ) -> Dict[str, torch.Tensor]:
      """Generate the sequence of features given the sequences of characters.
  
      Args:
          text (LongTensor): Input sequence of characters (T_text,).
          feats (Optional[Tensor): Feature sequence to extract style (N, idim).
          durations (Optional[Tensor): Groundtruth of duration (T_text + 1,).
          spembs (Optional[Tensor): Speaker embedding vector (spk_embed_dim,).
          sids (Optional[Tensor]): Speaker ID (1,).
          lids (Optional[Tensor]): Language ID (1,).
          pitch (Optional[Tensor]): Groundtruth of token-avg pitch (T_text + 1, 1).
          energy (Optional[Tensor]): Groundtruth of token-avg energy (T_text + 1, 1).
          alpha (float): Alpha to control the speed.
          use_teacher_forcing (bool): Whether to use teacher forcing.
              If true, groundtruth of duration, pitch and energy will be used.
  
      Returns:
          Dict[str, Tensor]: Output dict including the following items:
              * feat_gen (Tensor): Output sequence of features (T_feats, odim).
              * duration (Tensor): Duration sequence (T_text + 1,).
              * pitch (Tensor): Pitch sequence (T_text + 1,).
              * energy (Tensor): Energy sequence (T_text + 1,).
  
      """
      x, y = text, feats
      spemb, d, p, e = spembs, durations, pitch, energy
  
      # add eos at the last of sequence
      x = F.pad(x, [0, 1], "constant", self.eos)
  
      # setup batch axis
      ilens = torch.tensor(
          [x.shape[0]], dtype=torch.long, device=x.device
      )
      xs, ys = x.unsqueeze(0), None
      if y is not None:
          ys = y.unsqueeze(0)
      if spemb is not None:
          spembs = spemb.unsqueeze(0)
  
      if use_teacher_forcing:
          # use groundtruth of duration, pitch, and energy
          ds, ps, es = d.unsqueeze(0), p.unsqueeze(0), e.unsqueeze(0)
          _, outs, d_outs, p_outs, e_outs = self._forward(
              xs,
              ilens,
              ys,
              ds=ds,
              ps=ps,
              es=es,
              spembs=spembs,
              sids=sids,
              lids=lids,
          )  # (1, T_feats, odim)
      else:
          _, outs, d_outs, p_outs, e_outs = self._forward(
              xs,
              ilens,
              ys,
              spembs=spembs,
              sids=sids,
              lids=lids,
              is_inference=True,
              alpha=alpha,
          )  # (1, T_feats, odim)
  
      return dict(
          feat_gen=outs[0],
          duration=d_outs[0],
          pitch=p_outs[0],
          energy=e_outs[0],
      )
  
imports: import logging
  from typing import Dict, Optional, Sequence, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.torch_utils.initialize import initialize
  from espnet2.tts.abs_tts import AbsTTS
  from espnet2.tts.fastspeech2.loss import FastSpeech2Loss
  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.fastspeech.length_regulator import LengthRegulator
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, make_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  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 4 for calling the FastSpeech2 obj's underlying member method code with example usage: obj.inference(text, feats, durations, spembs, sids, lids, pitch, energy, alpha, use_teacher_forcing) and returns: dict