WaveRNN¶
- class torchaudio.models.WaveRNN(upsample_scales: List[int], n_classes: int, hop_length: int, n_res_block: int = 10, n_rnn: int = 512, n_fc: int = 512, kernel_size: int = 5, n_freq: int = 128, n_hidden: int = 128, n_output: int = 128)[源代码]¶
WaveRNN 模型,来自高效神经音频合成 [Kalchbrenner et al., 2018],基于 fatchord/WaveRNN 的实现。
原始实现引入于高效神经音频合成 [Kalchbrenner et al., 2018]。波形和频谱图的输入通道必须为 1。upsample_scales 的乘积必须等于 hop_length。
另请参阅
torchaudio.pipelines.Tacotron2TTSBundle
:带有预训练模型的 TTS pipeline。
- 参数:
upsample_scales – 升采样比例列表。
n_classes – 输出类别的数量。
hop_length – 连续帧起始点之间的样本数。
n_res_block – 堆栈中 ResBlock 的数量。(默认值:
10
)n_rnn – RNN 层的维度。(默认值:
512
)n_fc – 全连接层的维度。(默认值:
512
)kernel_size – 第一个 Conv1d 层中的内核大小。(默认值:
5
)n_freq – 频谱图中的频 bins 数量。(默认值:
128
)n_hidden – resblock 的隐藏维度数量。(默认值:
128
)n_output – melresnet 的输出维度数量。(默认值:
128
)
- 示例
>>> wavernn = WaveRNN(upsample_scales=[5,5,8], n_classes=512, hop_length=200) >>> waveform, sample_rate = torchaudio.load(file) >>> # waveform shape: (n_batch, n_channel, (n_time - kernel_size + 1) * hop_length) >>> specgram = MelSpectrogram(sample_rate)(waveform) # shape: (n_batch, n_channel, n_freq, n_time) >>> output = wavernn(waveform, specgram) >>> # output shape: (n_batch, n_channel, (n_time - kernel_size + 1) * hop_length, n_classes)
- 使用
WaveRNN
的教程
方法¶
forward¶
- WaveRNN.forward(waveform: Tensor, specgram: Tensor) Tensor [源代码]¶
通过 WaveRNN 模型传递输入。
- 参数:
waveform – WaveRNN 层的输入波形 (n_batch, 1, (n_time - kernel_size + 1) * hop_length)
specgram – WaveRNN 层的输入频谱图 (n_batch, 1, n_freq, n_time)
- 返回:
形状 (n_batch, 1, (n_time - kernel_size + 1) * hop_length, n_classes)
- 返回类型:
Tensor
infer¶
- WaveRNN.infer(specgram: Tensor, lengths: Optional[Tensor] = None) Tuple[Tensor, Optional[Tensor]] [源代码]¶
WaveRNN 的推理方法。
此函数目前仅支持多项式采样,这假设网络在交叉熵损失上进行训练。
- 参数:
specgram (Tensor) – 频谱图批次。形状:(n_batch, n_freq, n_time)。
lengths (Tensor 或 None, 可选) – 指示批次中每个音频的有效长度。形状:(batch, )。当
specgram
包含不同时长的频谱图时,通过提供lengths
参数,模型将计算相应的有效输出长度。如果为None
,则假定waveforms
中的所有音频都具有有效长度。默认值:None
。
- 返回:
- Tensor
推断出的波形,大小为 (n_batch, 1, n_time)。1 代表单通道。
- Tensor 或 None
如果提供了
lengths
参数,则返回形状为 (batch, ) 的 Tensor。它指示输出 Tensor 在时间轴上的有效长度。
- 返回类型:
(Tensor, Optional[Tensor])