快捷方式

Tacotron2

class torchaudio.models.Tacotron2(mask_padding: bool = False, n_mels: int = 80, n_symbol: int = 148, n_frames_per_step: int = 1, symbol_embedding_dim: int = 512, encoder_embedding_dim: int = 512, encoder_n_convolution: int = 3, encoder_kernel_size: int = 5, decoder_rnn_dim: int = 1024, decoder_max_step: int = 2000, decoder_dropout: float = 0.1, decoder_early_stopping: bool = True, attention_rnn_dim: int = 1024, attention_hidden_dim: int = 128, attention_location_n_filter: int = 32, attention_location_kernel_size: int = 31, attention_dropout: float = 0.1, prenet_dim: int = 256, postnet_n_convolution: int = 5, postnet_kernel_size: int = 5, postnet_embedding_dim: int = 512, gate_threshold: float = 0.5)[source]

Tacotron2 模型,源自 Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions [Shen 等人, 2018],基于 Nvidia Deep Learning Examples 的实现。

另请参阅

参数:
  • mask_padding (bool, 可选) – 使用掩码填充 (默认值: False)。

  • n_mels (int, 可选) – Mel Bin 的数量 (默认值: 80)。

  • n_symbol (int, 可选) – 输入文本的符号数量 (默认值: 148)。

  • n_frames_per_step (int, 可选) – 每步处理的帧数,仅支持 1 (默认值: 1)。

  • symbol_embedding_dim (int, 可选) – 输入嵌入维度 (默认值: 512)。

  • encoder_n_convolution (int, 可选) – 编码器卷积层数量 (默认值: 3)。

  • encoder_kernel_size (int, 可选) – 编码器核大小 (默认值: 5)。

  • encoder_embedding_dim (int, 可选) – 编码器嵌入维度 (默认值: 512)。

  • decoder_rnn_dim (int, 可选) – 解码器 LSTM 的单元数量 (默认值: 1024)。

  • decoder_max_step (int, 可选) – 输出 Mel 谱图的最大数量 (默认值: 2000)。

  • decoder_dropout (float, 可选) – 解码器 LSTM 的 Dropout 概率 (默认值: 0.1)。

  • decoder_early_stopping (bool, 可选) – 在所有样本完成后继续解码 (默认值: True)。

  • attention_rnn_dim (int, 可选) – 注意力 LSTM 的单元数量 (默认值: 1024)。

  • attention_hidden_dim (int, 可选) – 注意力隐藏表示的维度 (默认值: 128)。

  • attention_location_n_filter (int, 可选) – 注意力模型的滤波器数量 (默认值: 32)。

  • attention_location_kernel_size (int, 可选) – 注意力模型的核大小 (默认值: 31)。

  • attention_dropout (float, 可选) – 注意力 LSTM 的 Dropout 概率 (默认值: 0.1)。

  • prenet_dim (int, 可选) – Prenet 层中的 ReLU 单元数量 (默认值: 256)。

  • postnet_n_convolution (int, 可选) – Postnet 卷积层数量 (默认值: 5)。

  • postnet_kernel_size (int, 可选) – Postnet 核大小 (默认值: 5)。

  • postnet_embedding_dim (int, 可选) – Postnet 嵌入维度 (默认值: 512)。

  • gate_threshold (float, 可选) – 停止标记的概率阈值 (默认值: 0.5)。

使用 Tacotron2 的教程
Text-to-Speech with Tacotron2

使用 Tacotron2 进行文本转语音

使用 Tacotron2 进行文本转语音

方法

forward

Tacotron2.forward(tokens: Tensor, token_lengths: Tensor, mel_specgram: Tensor, mel_specgram_lengths: Tuple[Tensor]) Tuple[Tensor, Tensor, Tensor, Tensor][source]

将输入通过 Tacotron2 模型。这处于教师强制模式,通常用于训练。

输入 tokens 应使用零填充至 token_lengths 的最大长度。输入 mel_specgram 应使用零填充至 mel_specgram_lengths 的最大长度。

参数:
  • tokens (Tensor) – Tacotron2 的输入标记,形状为 (n_batch, max of token_lengths)

  • token_lengths (Tensor) – tokens 中每个样本的有效长度,形状为 (n_batch, )

  • mel_specgram (Tensor) – 目标 Mel 谱图,形状为 (n_batch, n_mels, max of mel_specgram_lengths)

  • mel_specgram_lengths (Tensor) – 每个 Mel 谱图的长度,形状为 (n_batch, )

返回:

Tensor

Postnet 之前的 Mel 谱图,形状为 (n_batch, n_mels, max of mel_specgram_lengths)

Tensor

Postnet 之后的 Mel 谱图,形状为 (n_batch, n_mels, max of mel_specgram_lengths)

Tensor

每个时间步的停止标记输出,形状为 (n_batch, max of mel_specgram_lengths)

Tensor

来自解码器的注意力权重序列,形状为 (n_batch, max of mel_specgram_lengths, max of token_lengths)

返回类型:

[Tensor, Tensor, Tensor, Tensor]

infer

Tacotron2.infer(tokens: Tensor, lengths: Optional[Tensor] = None) Tuple[Tensor, Tensor, Tensor][source]

使用 Tacotron2 进行推理。输入是一批编码后的句子 (tokens) 及其对应的长度 (lengths)。输出是生成的 Mel 谱图、其对应的长度以及来自解码器的注意力权重。

输入 tokens 应使用零填充至 lengths 的最大长度。

参数:
  • tokens (Tensor) – Tacotron2 的输入标记,形状为 (n_batch, max of lengths)

  • lengths (TensorNone, 可选) – tokens 中每个样本的有效长度,形状为 (n_batch, )。如果为 None,则假定所有标记都有效。默认值:None

返回:

Tensor

预测的 Mel 谱图,形状为 (n_batch, n_mels, max of mel_specgram_lengths)

Tensor

预测的 Mel 谱图的长度,形状为 (n_batch, )

Tensor

来自解码器的注意力权重序列,形状为 (n_batch, max of mel_specgram_lengths, max of lengths)

返回类型:

(Tensor, Tensor, Tensor)

文档

查阅 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得问题解答

查看资源