class_docstr: XiaoiceSing module for Singing Voice Synthesis.
  
  This is a module of XiaoiceSing. A high-quality singing voice synthesis system which
  employs an integrated network for spectrum, F0 and duration modeling. It follows the
  main architecture of FastSpeech while proposing some singing-specific design:
      1) Add features from musical score (e.g.note pitch and length)
      2) Add a residual connection in F0 prediction to attenuate off-key issues
      3) The duration of all the phonemes in a musical note is accumulated to
      calculate the syllable duration loss for rhythm enhancement (syllable loss)
  .. _`XiaoiceSing: A High-Quality and Integrated Singing Voice Synthesis System`:
      https://arxiv.org/pdf/2006.06261.pdf
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[LongTensor]): Groundtruth of duration (T_text + 1,).
      label (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of padded label ids (Tmax).
      melody (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of padded melody (Tmax).
      pitch (FloatTensor): Batch of padded f0 (B, Tmax).
      duration (Optional[Dict]): key is "lab", "score_phn" or "score_syb";
          value (LongTensor): Batch of padded duration (Tmax).
      slur (LongTensor): Batch of padded slur (B, Tmax).
      spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
      sids (Optional[Tensor]): Speaker ID (1,).
      lids (Optional[Tensor]): Language ID (1,).
      alpha (float): Alpha to control the speed.
  
  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,).
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","[","LongTensor","]",")",":","Groundtruth","of","duration","(","T_text","+","1",",",")",".","label","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","padded","label","ids","(","Tmax",")",".","melody","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","padded","melody","(","Tmax",")",".","pitch","(","FloatTensor",")",":","Batch","of","padded","f0","(","B",",","Tmax",")",".","duration","(","Optional","[","Dict","]",")",":","key","is","``","lab","''",",","``","score_phn","''","or","``","score_syb","''",";","value","(","LongTensor",")",":","Batch","of","padded","duration","(","Tmax",")",".","slur","(","LongTensor",")",":","Batch","of","padded","slur","(","B",",","Tmax",")",".","spembs","(","Optional","[","Tensor","]",")",":","Speaker","embedding","(","spk_embed_dim",",",")",".","sids","(","Optional","[","Tensor","]",")",":","Speaker","ID","(","1",",",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","ID","(","1",",",")",".","alpha","(","float",")",":","Alpha","to","control","the","speed",".","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",",",")","."]
code: def inference(
      self,
      text: torch.Tensor,
      feats: Optional[torch.Tensor] = None,
      label: Optional[Dict[str, torch.Tensor]] = None,
      melody: Optional[Dict[str, torch.Tensor]] = None,
      pitch: Optional[torch.Tensor] = None,
      duration: Optional[Dict[str, torch.Tensor]] = None,
      slur: Optional[Dict[str, torch.Tensor]] = None,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      use_teacher_forcing: torch.Tensor = False,
      joint_training: 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[LongTensor]): Groundtruth of duration (T_text + 1,).
          label (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of padded label ids (Tmax).
          melody (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of padded melody (Tmax).
          pitch (FloatTensor): Batch of padded f0 (B, Tmax).
          duration (Optional[Dict]): key is "lab", "score_phn" or "score_syb";
              value (LongTensor): Batch of padded duration (Tmax).
          slur (LongTensor): Batch of padded slur (B, Tmax).
          spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
          sids (Optional[Tensor]): Speaker ID (1,).
          lids (Optional[Tensor]): Language ID (1,).
          alpha (float): Alpha to control the speed.
  
      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,).
      """
  
      label = label["score"]
      midi = melody["score"]
      if joint_training:
          duration_ = duration["lab"]
      else:
          duration_ = duration["score_phn"]
      ds = duration["lab"]
  
      label_emb = self.phone_encode_layer(label)
      midi_emb = self.midi_encode_layer(midi)
      duration_emb = self.duration_encode_layer(duration_)
      input_emb = label_emb + midi_emb + duration_emb
  
      x_masks = None  # self._source_mask(label_lengths)
      hs, _ = self.encoder(input_emb, x_masks)  # (B, T_text, adim)
  
      # 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)
      if spembs is not None:
          spembs = spembs.unsqueeze(0)
  
      # integrate speaker embedding
      if self.spk_embed_dim is not None:
          hs = self._integrate_with_spk_embed(hs, spembs)
  
      # forward duration predictor and length regulator
      d_masks = (
          None  # make_pad_mask(label_lengths).to(input_emb.device)
      )
      d_outs = self.duration_predictor.inference(
          hs, d_masks
      )  # (B, T_text)
      d_outs_int = torch.floor(d_outs + 0.5).to(
          dtype=torch.long
      )  # (B, T_text)
  
      logging.info(f"ds: {ds}")
      logging.info(f"ds.shape: {ds.shape}")
      logging.info(f"d_outs: {d_outs}")
      logging.info(f"d_outs.shape: {d_outs.shape}")
  
      # use duration model output
      hs = self.length_regulator(hs, d_outs_int)  # (B, T_feats, adim)
  
      # forward decoder
      h_masks = None  # self._source_mask(feats_lengths)
      zs, _ = self.decoder(hs, h_masks)  # (B, T_feats, adim)
      before_outs, _, _ = (
          self.linear_projection(zs)
          .view((zs.size(0), -1, self.odim + 2))
          .split_with_sizes([self.odim, 1, 1], dim=2)
      )
      # (B, T_feats, odim), (B, T_feats, 1), (B, T_feats, 1)
  
      # postnet -> (B, Lmax//r * r, odim)
      if self.postnet is None:
          after_outs = before_outs
      else:
          after_outs = before_outs + self.postnet(
              before_outs.transpose(1, 2)
          ).transpose(1, 2)
  
      return dict(feat_gen=after_outs[0], prob=None, att_w=None)
  
imports: import logging
  from typing import Dict, Optional, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.svs.abs_svs import AbsSVS
  from espnet2.svs.xiaoice.loss import XiaoiceSing2Loss
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.torch_utils.initialize import initialize
  from espnet.nets.pytorch_backend.conformer.encoder import Encoder
  from espnet.nets.pytorch_backend.e2e_tts_fastspeech import FeedForwardTransformerLoss
  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 3 for calling the XiaoiceSing obj's underlying member method code with example usage: obj.inference(text, feats, label, melody, pitch, duration, slur, spembs, sids, lids, use_teacher_forcing, joint_training) and returns: dict