MCPcopy Create free account
hub / github.com/espnet/espnet / inference

Method inference

espnet2/tts/prodiff/prodiff.py:704–787  ·  view source on GitHub ↗

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 duratio

(
        self,
        text: torch.Tensor,
        feats: Optional[torch.Tensor] = None,
        durations: Optional[torch.Tensor] = None,
        spembs: Optional[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,
    )

Source from the content-addressed store, hash-verified

702
703 @torch.no_grad()
704 def inference(
705 self,
706 text: torch.Tensor,
707 feats: Optional[torch.Tensor] = None,
708 durations: Optional[torch.Tensor] = None,
709 spembs: Optional[torch.Tensor] = None,
710 sids: Optional[torch.Tensor] = None,
711 lids: Optional[torch.Tensor] = None,
712 pitch: Optional[torch.Tensor] = None,
713 energy: Optional[torch.Tensor] = None,
714 alpha: float = 1.0,
715 use_teacher_forcing: bool = False,
716 ) -> Dict[str, torch.Tensor]:
717 """Generate the sequence of features given the sequences of characters.
718
719 Args:
720 text (LongTensor): Input sequence of characters (T_text,).
721 feats (Optional[Tensor): Feature sequence to extract style (N, idim).
722 durations (Optional[Tensor): Groundtruth of duration (T_text + 1,).
723 spembs (Optional[Tensor): Speaker embedding vector (spk_embed_dim,).
724 sids (Optional[Tensor]): Speaker ID (1,).
725 lids (Optional[Tensor]): Language ID (1,).
726 pitch (Optional[Tensor]): Groundtruth of token-avg pitch (T_text + 1, 1).
727 energy (Optional[Tensor]): Groundtruth of token-avg energy (T_text + 1, 1).
728 alpha (float): Alpha to control the speed.
729 use_teacher_forcing (bool): Whether to use teacher forcing.
730 If true, groundtruth of duration, pitch and energy will be used.
731
732 Returns:
733 Dict[str, Tensor]: Output dict including the following items:
734 * feat_gen (Tensor): Output sequence of features (T_feats, odim).
735 * duration (Tensor): Duration sequence (T_text + 1,).
736 * pitch (Tensor): Pitch sequence (T_text + 1,).
737 * energy (Tensor): Energy sequence (T_text + 1,).
738
739 """
740 x, y = text, feats
741 spemb, d, p, e = spembs, durations, pitch, energy
742
743 # add eos at the last of sequence
744 x = F.pad(x, [0, 1], "constant", self.eos)
745
746 # setup batch axis
747 ilens = torch.tensor([x.shape[0]], dtype=torch.long, device=x.device)
748 xs, ys = x.unsqueeze(0), None
749 if y is not None:
750 ys = y.unsqueeze(0)
751 if spemb is not None:
752 spembs = spemb.unsqueeze(0)
753
754 if use_teacher_forcing:
755 # use groundtruth of duration, pitch, and energy
756 ds, ps, es = d.unsqueeze(0), p.unsqueeze(0), e.unsqueeze(0)
757 _, outs, d_outs, p_outs, e_outs = self._forward(
758 xs,
759 ilens,
760 ys,
761 ds=ds,

Callers 3

test_prodiffFunction · 0.95
forwardMethod · 0.45
_forwardMethod · 0.45

Calls 1

_forwardMethod · 0.95

Tested by 1

test_prodiffFunction · 0.76