hifigan
HiFi-GAN Vocoder Module
This module provides a HiFi-GAN vocoder implementation compatible with SpeechBrain's pretrained weights from HuggingFace Hub.
The implementation uses weight normalization as in the SpeechBrain checkpoint.
HiFiGAN
Bases: Module
HiFi-GAN Generator Module.
This implementation is compatible with SpeechBrain's pretrained weights. It uses weight normalization and the same architecture as the SpeechBrain model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input channels (mel spectrogram bins) |
80
|
|
out_channels
|
Number of output channels (1 for mono audio) |
1
|
|
resblock_type
|
Type of residual block ("1" or "2") |
'1'
|
|
resblock_dilation_sizes
|
Dilation sizes for residual blocks |
[[1, 3, 5], [1, 3, 5], [1, 3, 5]]
|
|
resblock_kernel_sizes
|
Kernel sizes for residual blocks |
[3, 7, 11]
|
|
upsample_kernel_sizes
|
Kernel sizes for upsampling layers |
[16, 16, 4, 4]
|
|
upsample_initial_channel
|
Initial number of channels after first conv |
512
|
|
upsample_factors
|
Upsampling factors for each layer |
[8, 8, 2, 2]
|
Source code in speechain/module/vocoder/hifigan.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
decode_batch(mel)
Decode mel spectrogram to waveform.
This method is compatible with SpeechBrain's interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mel
|
Mel spectrogram tensor of shape (batch, time, mel_channels) Note: SpeechBrain uses (batch, time, channels) format |
required |
Returns:
| Type | Description |
|---|---|
|
Audio waveform tensor |
Source code in speechain/module/vocoder/hifigan.py
forward(x)
Forward pass of HiFi-GAN generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Input mel spectrogram tensor of shape (batch, mel_channels, time) |
required |
Returns:
| Type | Description |
|---|---|
|
Audio waveform tensor of shape (batch, 1, time * product(upsample_factors)) |
Source code in speechain/module/vocoder/hifigan.py
from_pretrained(model_name='speechbrain/tts-hifigan-ljspeech', cache_dir=None, device=None)
classmethod
Load pretrained HiFi-GAN from HuggingFace Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
HuggingFace model name or path |
'speechbrain/tts-hifigan-ljspeech'
|
|
cache_dir
|
Directory to cache downloaded files |
None
|
|
device
|
Device to load model onto |
None
|
Returns:
| Type | Description |
|---|---|
|
Loaded HiFiGAN model |
Source code in speechain/module/vocoder/hifigan.py
remove_weight_norm()
Remove weight normalization from all layers.
Source code in speechain/module/vocoder/hifigan.py
ResBlock1
Bases: Module
Residual Block Type 1 for HiFi-GAN.
Source code in speechain/module/vocoder/hifigan.py
ResBlock2
Bases: Module
Residual Block Type 2 for HiFi-GAN.
Source code in speechain/module/vocoder/hifigan.py
get_padding(kernel_size, dilation=1)
load_hifigan_vocoder(checkpoint_path=None, model_name='speechbrain/tts-hifigan-ljspeech', device=None)
Load HiFi-GAN vocoder.
This function provides a simple interface to load the vocoder either from a local checkpoint or from HuggingFace Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path
|
Path to local checkpoint (optional) |
None
|
|
model_name
|
HuggingFace model name for download |
'speechbrain/tts-hifigan-ljspeech'
|
|
device
|
Device to load model onto |
None
|
Returns:
| Type | Description |
|---|---|
|
Loaded HiFiGAN model |