快捷方式

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 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源