class_docstr: Tacotron2 module for end-to-end text-to-speech.
  
  This is a module of Spectrogram prediction network in Tacotron2 described
  in `Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions`_,
  which converts the sequence of characters into the sequence of Mel-filterbanks.
  
  .. _`Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions`:
     https://arxiv.org/abs/1712.05884
class_docstr_tok: ["Tacotron2","module","for","end-to-end","text-to-speech",".","This","is","a","module","of","Spectrogram","prediction","network","in","Tacotron2","described","in","`","Natural","TTS","Synthesis","by","Conditioning","WaveNet","on","Mel","Spectrogram","Predictions","`","_",",","which","converts","the","sequence","of","characters","into","the","sequence","of","Mel-filterbanks",".","..","_","`","Natural","TTS","Synthesis","by","Conditioning","WaveNet","on","Mel","Spectrogram","Predictions","`",":","https",":","\/\/arxiv.org\/abs\/1712.05884"]
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).
      spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
      sids (Optional[Tensor]): Speaker ID (1,).
      lids (Optional[Tensor]): Language ID (1,).
      threshold (float): Threshold in inference.
      minlenratio (float): Minimum length ratio in inference.
      maxlenratio (float): Maximum length ratio in inference.
      use_att_constraint (bool): Whether to apply attention constraint.
      backward_window (int): Backward window in attention constraint.
      forward_window (int): Forward window in attention constraint.
      use_teacher_forcing (bool): Whether to use teacher forcing.
  
  Returns:
      Dict[str, Tensor]: Output dict including the following items:
          * feat_gen (Tensor): Output sequence of features (T_feats, odim).
          * prob (Tensor): Output sequence of stop probabilities (T_feats,).
          * att_w (Tensor): Attention weights (T_feats, T).
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",")",".","spembs","(","Optional","[","Tensor","]",")",":","Speaker","embedding","(","spk_embed_dim",",",")",".","sids","(","Optional","[","Tensor","]",")",":","Speaker","ID","(","1",",",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","ID","(","1",",",")",".","threshold","(","float",")",":","Threshold","in","inference",".","minlenratio","(","float",")",":","Minimum","length","ratio","in","inference",".","maxlenratio","(","float",")",":","Maximum","length","ratio","in","inference",".","use_att_constraint","(","bool",")",":","Whether","to","apply","attention","constraint",".","backward_window","(","int",")",":","Backward","window","in","attention","constraint",".","forward_window","(","int",")",":","Forward","window","in","attention","constraint",".","use_teacher_forcing","(","bool",")",":","Whether","to","use","teacher","forcing",".","Returns",":","Dict","[","str",",","Tensor","]",":","Output","dict","including","the","following","items",":","*","feat_gen","(","Tensor",")",":","Output","sequence","of","features","(","T_feats",",","odim",")",".","*","prob","(","Tensor",")",":","Output","sequence","of","stop","probabilities","(","T_feats",",",")",".","*","att_w","(","Tensor",")",":","Attention","weights","(","T_feats",",","T",")","."]
code: def inference(
      self,
      text: torch.Tensor,
      feats: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      threshold: float = 0.5,
      minlenratio: float = 0.0,
      maxlenratio: float = 10.0,
      use_att_constraint: bool = False,
      backward_window: int = 1,
      forward_window: int = 3,
      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).
          spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
          sids (Optional[Tensor]): Speaker ID (1,).
          lids (Optional[Tensor]): Language ID (1,).
          threshold (float): Threshold in inference.
          minlenratio (float): Minimum length ratio in inference.
          maxlenratio (float): Maximum length ratio in inference.
          use_att_constraint (bool): Whether to apply attention constraint.
          backward_window (int): Backward window in attention constraint.
          forward_window (int): Forward window in attention constraint.
          use_teacher_forcing (bool): Whether to use teacher forcing.
  
      Returns:
          Dict[str, Tensor]: Output dict including the following items:
              * feat_gen (Tensor): Output sequence of features (T_feats, odim).
              * prob (Tensor): Output sequence of stop probabilities (T_feats,).
              * att_w (Tensor): Attention weights (T_feats, T).
  
      """
      x = text
      y = feats
      spemb = spembs
  
      # add eos at the last of sequence
      x = F.pad(x, [0, 1], "constant", self.eos)
  
      # inference with teacher forcing
      if use_teacher_forcing:
          assert (
              feats is not None
          ), "feats must be provided with teacher forcing."
  
          xs, ys = x.unsqueeze(0), y.unsqueeze(0)
          spembs = None if spemb is None else spemb.unsqueeze(0)
          ilens = x.new_tensor([xs.size(1)]).long()
          olens = y.new_tensor([ys.size(1)]).long()
          outs, _, _, att_ws = self._forward(
              xs=xs,
              ilens=ilens,
              ys=ys,
              olens=olens,
              spembs=spembs,
              sids=sids,
              lids=lids,
          )
  
          return dict(feat_gen=outs[0], att_w=att_ws[0])
  
      # inference
      h = self.enc.inference(x)
      if self.use_gst:
          style_emb = self.gst(y.unsqueeze(0))
          h = h + style_emb
      if self.spks is not None:
          sid_emb = self.sid_emb(sids.view(-1))
          h = h + sid_emb
      if self.langs is not None:
          lid_emb = self.lid_emb(lids.view(-1))
          h = h + lid_emb
      if self.spk_embed_dim is not None:
          hs, spembs = h.unsqueeze(0), spemb.unsqueeze(0)
          h = self._integrate_with_spk_embed(hs, spembs)[0]
      out, prob, att_w = self.dec.inference(
          h,
          threshold=threshold,
          minlenratio=minlenratio,
          maxlenratio=maxlenratio,
          use_att_constraint=use_att_constraint,
          backward_window=backward_window,
          forward_window=forward_window,
      )
  
      return dict(feat_gen=out, prob=prob, att_w=att_w)
  
file_path: espnet/espnet2/tts/tacotron2/tacotron2.py
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.tts.abs_tts import AbsTTS
  from espnet2.tts.gst.style_encoder import StyleEncoder
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import GuidedAttentionLoss, Tacotron2Loss
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.rnn.attentions import AttForward, AttForwardTA, AttLoc
  from espnet.nets.pytorch_backend.tacotron2.decoder import Decoder
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
label_desc: Use image node_id 4 for calling the Tacotron2 obj's underlying member method code with example usage: obj.inference(text, feats, spembs, sids, lids, threshold, minlenratio, maxlenratio, use_att_constraint, backward_window, forward_window, use_teacher_forcing) and returns: dict, dict