pretrained.vocoder.hifigan
Defines a pre-trained HiFi-GAN vocoder model.
This vocoder can be used with TTS models that output mel spectrograms to synthesize audio.
from pretrained.vocoder import pretrained_vocoder
vocoder = pretrained_vocoder("hifigan")
- pretrained.vocoder.hifigan.cast_pretrained_hifigan_type(s: str) Literal['16000hz', '22050hz'] [source]
- pretrained.vocoder.hifigan.get(x, i)
- pretrained.vocoder.hifigan.init_hifigan_weights(m: Module, mean: float = 0.0, std: float = 0.01) None [source]
- class pretrained.vocoder.hifigan.ResBlock(channels: int, kernel_size: int = 3, dilation: tuple[int, int, int] = (1, 3, 5), lrelu_slope: float = 0.1)[source]
Bases:
Module
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor, state: list[tuple[tuple[torch.Tensor, int], tuple[torch.Tensor, int], tuple[torch.Tensor, torch.Tensor]]] | None) tuple[torch.Tensor, list[tuple[tuple[torch.Tensor, int], tuple[torch.Tensor, int], tuple[torch.Tensor, torch.Tensor]]]] [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class pretrained.vocoder.hifigan.HiFiGAN(sampling_rate: int, model_in_dim: int, upsample_kernel_sizes: list[int], upsample_rates: list[int], resblock_kernel_sizes: list[int] = [3, 7, 11], resblock_dilation_sizes: list[tuple[int, int, int]] = [(1, 3, 5), (1, 3, 5), (1, 3, 5)], upsample_initial_channel: int = 512, lrelu_slope: float = 0.1)[source]
Bases:
Module
Defines a HiFi-GAN model.
- Parameters:
sampling_rate – The sampling rate of the model.
model_in_dim – The input dimension of the model.
upsample_kernel_sizes – The kernel sizes of the upsampling layers.
upsample_rates – The upsample rates of each layer.
resblock_kernel_sizes – The kernel sizes of the ResBlocks.
resblock_dilation_sizes – The dilation sizes of the ResBlocks.
upsample_initial_channel – The initial channel of the upsampling layers.
lrelu_slope – The slope of the leaky ReLU.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor, state: tuple[tuple[torch.Tensor, int], list[tuple[torch.Tensor, int]], list[list[list[tuple[tuple[torch.Tensor, int], tuple[torch.Tensor, int], tuple[torch.Tensor, torch.Tensor]]]]], list[list[tuple[torch.Tensor, torch.Tensor]]], tuple[torch.Tensor, int]] | None = None) tuple[torch.Tensor, tuple[tuple[torch.Tensor, int], list[tuple[torch.Tensor, int]], list[list[list[tuple[tuple[torch.Tensor, int], tuple[torch.Tensor, int], tuple[torch.Tensor, torch.Tensor]]]]], list[list[tuple[torch.Tensor, torch.Tensor]]], tuple[torch.Tensor, int]]] [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- audio_to_mels() AudioToHifiGanMels [source]
- pretrained.vocoder.hifigan.pretrained_hifigan(key: str | Literal['16000hz', '22050hz'], *, pretrained: bool = True, keep_weight_norm: bool = False) HiFiGAN [source]
Loads the pretrained HiFi-GAN model.
- Parameters:
key – The key of the pretrained model.
pretrained – Whether to load the pretrained weights.
keep_weight_norm – Whether to keep the weight norm.
- Returns:
The pretrained HiFi-GAN model.
- class pretrained.vocoder.hifigan.AudioToHifiGanMels(sampling_rate: int, num_mels: int, n_fft: int, win_size: int, hop_size: int, fmin: int = 0, fmax: int = 8000)[source]
Bases:
Module
Defines a module to convert from a waveform to the mels used by HiFi-GAN.
The default parameters should be kept the same for pre-trained models.
- Parameters:
sampling_rate – The sampling rate of the audio.
num_mels – The number of mel bins.
n_fft – The number of FFT bins.
win_size – The window size.
fmin – The minimum frequency.
fmax – The maximum frequency.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- mel_basis: Tensor
- hann_window: Tensor
- forward(y: Tensor, center: bool = False) Tensor [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.