speechbrain.lobes.models.HifiGAN 模块
HiFi-GAN 的神经网络模块:用于高效高保真语音合成的生成对抗网络
更多详情请见:https://arxiv.org/pdf/2010.05646.pdf, https://arxiv.org/abs/2406.10735
- 作者
Jarod Duret 2021
王英志 2022
摘要
类
创建判别器损失摘要 |
|
HiFiGAN 周期性判别器 从输入波形中获取每 P 个值并应用一系列卷积。注意:如果周期为 2,则波形 = [1, 2, 3, 4, 5, 6 ...] --> [1, 3, 5 ...] --> 卷积 -> 分数,特征。 |
|
HiFiGAN 尺度判别器。 |
|
创建生成器损失摘要并为不同损失应用权重 |
|
封装 MPD 和 MSD 的 HiFiGAN 判别器。 |
|
具有多感受野融合 (MRF) 的 HiFiGAN 生成器 |
|
HiFiGAN 论文 (https://arxiv.org/pdf/2010.05646.pdf) 中描述的频谱图 L1 损失。注意:与 L2 损失相比,L1 损失有助于学习细节。 |
|
均方判别器损失 训练判别器将真实样本分类为 1,将生成器合成的样本分类为 0。 |
|
均方生成器损失 训练生成器通过将样本质量更新为几乎等于 1 的值来欺骗判别器。 |
|
计算特征匹配损失,这是一种学习到的相似性度量,通过判别器对真实样本和生成样本之间的特征差异来衡量(Larsen 等人,2016 年;Kumar 等人,2019 年)。 |
|
HiFiGAN 多周期判别器 (MPD) |
|
HiFiGAN 多尺度判别器。 |
|
多尺度 STFT 损失。 |
|
残差块类型 1,每个卷积块中有 3 个卷积层。 |
|
残差块类型 2,每个卷积块中有 2 个卷积层。 |
|
STFT 损失。 |
|
UnitHiFiGAN 生成器将离散语音 token 作为输入。 |
|
受 FastSpeech2 启发的方差预测器 |
函数
音频信号的动态范围压缩 |
|
计算原始音频信号的 Mel 频谱图 |
|
处理给定批次的 code,提取连续唯一元素及其相关特征。 |
|
计算输入短重叠窗口的傅里叶变换 |
参考
- speechbrain.lobes.models.HifiGAN.dynamic_range_compression(x, C=1, clip_val=1e-05)[source]
音频信号的动态范围压缩
- speechbrain.lobes.models.HifiGAN.mel_spectogram(sample_rate, hop_length, win_length, n_fft, n_mels, f_min, f_max, power, normalized, norm, mel_scale, compression, audio)[source]
计算原始音频信号的 Mel 频谱图
- 参数:
sample_rate (int) – 音频信号的采样率。
hop_length (int) – STFT 窗口之间的跳长。
win_length (int) – 窗口大小。
n_fft (int) – FFT 大小。
n_mels (int) – 梅尔滤波器组数量。
f_min (float) – 最小频率。
f_max (float) – 最大频率。
power (float) – 幅度频谱图的指数。
normalized (bool) – 是否在 stft 后按幅度归一化。
norm (str or None) – 如果为 “slaney”,则将三角梅尔权重除以梅尔带的宽度。
mel_scale (str) – 使用的尺度:“htk” 或 “slaney”。
compression (bool) – 是否进行动态范围压缩。
audio (torch.tensor) – 输入音频信号。
- 返回类型:
梅尔频谱图
- speechbrain.lobes.models.HifiGAN.process_duration(code, code_feat)[source]
处理给定批次的 code,提取连续唯一元素及其相关特征。
- 参数:
code (torch.Tensor (批次, 时间)) – code 索引张量。
code_feat (torch.Tensor (批次, 时间, 通道)) – code 特征张量。
- 返回:
uniq_code_feat_filtered (torch.Tensor (批次, 时间)) – 连续唯一 code 的特征。
mask (torch.Tensor (批次, 时间)) – 唯一 code 的填充掩码。
uniq_code_count (torch.Tensor (n)) – 唯一 code 的计数。
示例
>>> code = torch.IntTensor([[40, 18, 18, 10]]) >>> code_feat = torch.rand([1, 4, 128]) >>> out_tensor, mask, uniq_code = process_duration(code, code_feat) >>> out_tensor.shape torch.Size([1, 1, 128]) >>> mask.shape torch.Size([1, 1]) >>> uniq_code.shape torch.Size([1])
- class speechbrain.lobes.models.HifiGAN.ResBlock1(channels, kernel_size=3, dilation=(1, 3, 5))[source]
基类:
Module
残差块类型 1,每个卷积块中有 3 个卷积层。
- class speechbrain.lobes.models.HifiGAN.ResBlock2(channels, kernel_size=3, dilation=(1, 3))[source]
基类:
Module
残差块类型 2,每个卷积块中有 2 个卷积层。
- class speechbrain.lobes.models.HifiGAN.HifiganGenerator(in_channels, out_channels, resblock_type, resblock_dilation_sizes, resblock_kernel_sizes, upsample_kernel_sizes, upsample_initial_channel, upsample_factors, inference_padding=5, cond_channels=0, conv_post_bias=True)[source]
基类:
Module
具有多感受野融合 (MRF) 的 HiFiGAN 生成器
- 参数:
in_channels (int) – 输入张量通道数。
out_channels (int) – 输出张量通道数。
resblock_type (str) –
ResBlock
类型。‘1’ 或 ‘2’。resblock_dilation_sizes (List[List[int]]) –
ResBlock
中每层的膨胀值列表。resblock_kernel_sizes (List[int]) – 每个
ResBlock
的核大小列表。upsample_kernel_sizes (List[int]) – 每个转置卷积的核大小列表。
upsample_initial_channel (int) – 第一个上采样层的通道数。每个连续的上采样层此值都会除以 2。
upsample_factors (List[int]) – 每个上采样层的上采样因子(步长)。
inference_padding (int) – 推理时应用于输入的常量填充。默认为 5。
cond_channels (int) – 如果提供,在 forward 的开始添加一个卷积层。
conv_post_bias (bool) – 是否在最终卷积层添加偏置项。
示例
>>> inp_tensor = torch.rand([4, 80, 33]) >>> hifigan_generator= HifiganGenerator( ... in_channels = 80, ... out_channels = 1, ... resblock_type = "1", ... resblock_dilation_sizes = [[1, 3, 5], [1, 3, 5], [1, 3, 5]], ... resblock_kernel_sizes = [3, 7, 11], ... upsample_kernel_sizes = [16, 16, 4, 4], ... upsample_initial_channel = 512, ... upsample_factors = [8, 8, 2, 2], ... ) >>> out_tensor = hifigan_generator(inp_tensor) >>> out_tensor.shape torch.Size([4, 1, 8448])
- class speechbrain.lobes.models.HifiGAN.VariancePredictor(encoder_embed_dim, var_pred_hidden_dim, var_pred_kernel_size, var_pred_dropout)[source]
基类:
Module
受 FastSpeech2 启发的方差预测器
- 参数:
示例
>>> inp_tensor = torch.rand([4, 80, 128]) >>> duration_predictor = VariancePredictor( ... encoder_embed_dim = 128, ... var_pred_hidden_dim = 128, ... var_pred_kernel_size = 3, ... var_pred_dropout = 0.5, ... ) >>> out_tensor = duration_predictor (inp_tensor) >>> out_tensor.shape torch.Size([4, 80])
- class speechbrain.lobes.models.HifiGAN.UnitHifiganGenerator(in_channels, out_channels, resblock_type, resblock_dilation_sizes, resblock_kernel_sizes, upsample_kernel_sizes, upsample_initial_channel, upsample_factors, inference_padding=5, cond_channels=0, conv_post_bias=True, vocab_size=100, embedding_dim=128, attn_dim=128, duration_predictor=False, var_pred_hidden_dim=128, var_pred_kernel_size=3, var_pred_dropout=0.5, multi_speaker=False, normalize_speaker_embeddings=False, skip_token_embedding=False, pooling_type='attention')[source]
基类:
HifiganGenerator
UnitHiFiGAN 生成器接收离散语音 token 作为输入。该生成器适用于支持码率可伸缩性训练。更多详情请参阅:https://arxiv.org/abs/2406.10735。
- 参数:
in_channels (int) – 输入张量通道数。
out_channels (int) – 输出张量通道数。
resblock_type (str) –
ResBlock
类型。‘1’ 或 ‘2’。resblock_dilation_sizes (List[List[int]]) –
ResBlock
中每层的膨胀值列表。resblock_kernel_sizes (List[int]) – 每个
ResBlock
的核大小列表。upsample_kernel_sizes (List[int]) – 每个转置卷积的核大小列表。
upsample_initial_channel (int) – 第一个上采样层的通道数。每个连续的上采样层此值都会除以 2。
upsample_factors (List[int]) – 每个上采样层的上采样因子(步长)。
inference_padding (int) – 推理时应用于输入的常量填充。默认为 5。
cond_channels (int) – 是否在前面添加卷积层
conv_post_bias (bool) – 是否在最后一个卷积层添加偏置
vocab_size (int) – 嵌入字典的大小。
embedding_dim (int) – 每个嵌入向量的大小。
attn_dim (int) – 注意力维度的大小。
duration_predictor (bool) – 启用时长预测模块。
var_pred_hidden_dim (int) – 时长预测器卷积层的隐藏通道大小。
var_pred_kernel_size (int) – 时长预测器每层卷积核的大小。
var_pred_dropout (float) – 时长预测器每层的 dropout 概率。
multi_speaker (bool) – 启用多说话人训练。
normalize_speaker_embeddings (bool) – 启用说话人嵌入归一化。
skip_token_embedding (bool) – 在连续输入情况下是否跳过嵌入层。
pooling_type (str, optional) – 使用的池化类型。必须是 ["attention", "sum", "none"] 之一。对于可伸缩声码器,默认为 "attention"。
示例
>>> inp_tensor = torch.randint(0, 100, (4, 10, 1)) >>> unit_hifigan_generator= UnitHifiganGenerator( ... in_channels = 128, ... out_channels = 1, ... resblock_type = "1", ... resblock_dilation_sizes = [[1, 3, 5], [1, 3, 5], [1, 3, 5]], ... resblock_kernel_sizes = [3, 7, 11], ... upsample_kernel_sizes = [11, 8, 8, 4, 4], ... upsample_initial_channel = 512, ... upsample_factors = [5, 4, 4, 2, 2], ... vocab_size = 100, ... embedding_dim = 128, ... duration_predictor = True, ... var_pred_hidden_dim = 128, ... var_pred_kernel_size = 3, ... var_pred_dropout = 0.5, ... ) >>> out_tensor, _ = unit_hifigan_generator(inp_tensor) >>> out_tensor.shape torch.Size([4, 1, 3200])
- class speechbrain.lobes.models.HifiGAN.DiscriminatorP(period, kernel_size=5, stride=3)[source]
基类:
Module
HiFiGAN 周期判别器。从输入波形中每隔 P 个值取一个值,并应用卷积堆栈。注意:
如果 period 是 2,波形 = [1, 2, 3, 4, 5, 6 …] –> [1, 3, 5 … ] –> 卷积 –> 分数,特征
- class speechbrain.lobes.models.HifiGAN.MultiPeriodDiscriminator[source]
基类:
Module
HiFiGAN 多周期判别器 (MPD),是
PeriodDiscriminator
的封装,用于在不同周期应用。建议周期使用质数,以减少各个判别器之间的重叠。
- class speechbrain.lobes.models.HifiGAN.DiscriminatorS(use_spectral_norm=False)[source]
基类:
Module
HiFiGAN 尺度判别器。它类似于
MelganDiscriminator
,但在论文中解释了一种特定的架构。这里没有使用 SpeechBrain CNN 封装器,因为谱范数(spectral_norm)不常使用。- 参数:
use_spectral_norm (bool) – 如果为
True
,则切换到谱范数而不是权重范数。
- class speechbrain.lobes.models.HifiGAN.MultiScaleDiscriminator[source]
基类:
Module
HiFiGAN 多尺度判别器。类似于 MultiScaleMelganDiscriminator,但根据论文专门为 HiFiGAN 定制。
- class speechbrain.lobes.models.HifiGAN.HifiganDiscriminator[source]
基类:
Module
封装 MPD 和 MSD 的 HiFiGAN 判别器。
示例
>>> inp_tensor = torch.rand([4, 1, 8192]) >>> hifigan_discriminator= HifiganDiscriminator() >>> scores, feats = hifigan_discriminator(inp_tensor) >>> len(scores) 8 >>> len(feats) 8
- speechbrain.lobes.models.HifiGAN.stft(x, n_fft, hop_length, win_length, window_fn='hann_window')[source]
计算输入短重叠窗口的傅里叶变换
- class speechbrain.lobes.models.HifiGAN.STFTLoss(n_fft, hop_length, win_length)[source]
基类:
Module
STFT 损失。输入生成的和真实的波形被转换为频谱图,并与 L1 损失和谱收敛损失进行比较。它源自 ParallelWaveGAN 论文 https://arxiv.org/pdf/1910.11480.pdf
- class speechbrain.lobes.models.HifiGAN.MultiScaleSTFTLoss(n_ffts=(1024, 2048, 512), hop_lengths=(120, 240, 50), win_lengths=(600, 1200, 240))[source]
基类:
Module
多尺度 STFT 损失。输入生成的和真实的波形被转换为频谱图,并与 L1 损失和谱收敛损失进行比较。它源自 ParallelWaveGAN 论文 https://arxiv.org/pdf/1910.11480.pdf
- class speechbrain.lobes.models.HifiGAN.L1SpecLoss(sample_rate=22050, hop_length=256, win_length=24, n_mel_channels=80, n_fft=1024, n_stft=513, mel_fmin=0.0, mel_fmax=8000.0, mel_normalized=False, power=1.0, norm='slaney', mel_scale='slaney', dynamic_range_compression=True)[source]
基类:
Module
HiFiGAN 论文 (https://arxiv.org/pdf/2010.05646.pdf) 中描述的频谱图 L1 损失。注意:与 L2 损失相比,L1 损失有助于学习细节。
- 参数:
sample_rate (int) – 音频信号的采样率。
hop_length (int) – STFT 窗口之间的跳长。
win_length (int) – 窗口大小。
n_mel_channels (int) – mel 滤波器组数量。
n_fft (int) – FFT 大小。
n_stft (int) – STFT 大小。
mel_fmin (float) – 最小频率。
mel_fmax (float) – 最大频率。
mel_normalized (bool) – STFT 后是否按幅度进行归一化。
power (float) – 幅度频谱图的指数。
norm (str or None) – 如果为 “slaney”,则将三角梅尔权重除以梅尔带的宽度。
mel_scale (str) – 使用的尺度:“htk” 或 “slaney”。
dynamic_range_compression (bool) – 是否进行动态范围压缩。
- class speechbrain.lobes.models.HifiGAN.MSEGLoss(*args, **kwargs)[source]
基类:
Module
均方生成器损失 训练生成器通过将样本质量更新为几乎等于 1 的值来欺骗判别器。
- class speechbrain.lobes.models.HifiGAN.MelganFeatureLoss[source]
基类:
Module
计算特征匹配损失,这是一种学习到的相似性度量,通过判别器对真实样本和生成样本之间的特征差异来衡量(Larsen 等人,2016 年;Kumar 等人,2019 年)。
- class speechbrain.lobes.models.HifiGAN.MSEDLoss[source]
基类:
Module
均方判别器损失 训练判别器将真实样本分类为 1,将生成器合成的样本分类为 0。
- class speechbrain.lobes.models.HifiGAN.GeneratorLoss(stft_loss=None, stft_loss_weight=0, mseg_loss=None, mseg_loss_weight=0, feat_match_loss=None, feat_match_loss_weight=0, l1_spec_loss=None, l1_spec_loss_weight=0, mseg_dur_loss=None, mseg_dur_loss_weight=0)[source]
基类:
Module
创建生成器损失摘要并为不同损失应用权重
- 参数:
stft_loss (object) – stft 损失对象
stft_loss_weight (float) – STFT 损失权重
mseg_loss (object) – mseg 损失对象
mseg_loss_weight (float) – mseg 损失权重
feat_match_loss (object) – 特征匹配损失对象
feat_match_loss_weight (float) – 特征匹配损失权重
l1_spec_loss (object) – L1 频谱图损失对象
l1_spec_loss_weight (float) – L1 频谱图损失权重
mseg_dur_loss (object) – mseg 时长损失对象
mseg_dur_loss_weight (float) – mseg 时长损失权重