-
Notifications
You must be signed in to change notification settings - Fork 25
/
hubconf.py
78 lines (67 loc) · 2.88 KB
/
hubconf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
dependencies = ["torch", "torchaudio"]
URLS = {
"hifigan": "https://github.com/bshall/hifigan/releases/download/v0.1/hifigan-67926ec6.pt",
"hifigan-hubert-discrete": "https://github.com/bshall/hifigan/releases/download/v0.1/hifigan-hubert-discrete-bbad3043.pt",
"hifigan-hubert-soft": "https://github.com/bshall/hifigan/releases/download/v0.1/hifigan-hubert-soft-65f03469.pt",
}
import torch
from torch.nn.modules.utils import consume_prefix_in_state_dict_if_present
from hifigan.generator import HifiganGenerator
def _hifigan(
name: str,
pretrained: bool = True,
progress: bool = True,
map_location=None,
) -> HifiganGenerator:
hifigan = HifiganGenerator()
if pretrained:
checkpoint = torch.hub.load_state_dict_from_url(
URLS[name], map_location=map_location, progress=progress
)
consume_prefix_in_state_dict_if_present(checkpoint, "module.")
hifigan.load_state_dict(checkpoint)
hifigan.eval()
hifigan.remove_weight_norm()
return hifigan
def hifigan(
pretrained: bool = True,
progress: bool = True,
map_location=None,
) -> HifiganGenerator:
"""HiFiGAN Vocoder from from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
Args:
pretrained (bool): load pretrained weights into the model
progress (bool): show progress bar when downloading model
map_location: a function or a dict specifying how to remap storage locations (see torch.load)
"""
return _hifigan("hifigan", pretrained, progress, map_location)
def hifigan_hubert_soft(
pretrained: bool = True,
progress: bool = True,
map_location=None,
) -> HifiganGenerator:
"""HiFiGAN Vocoder from from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
Finetuned on spectrograms generated from the soft acoustic model.
Args:
pretrained (bool): load pretrained weights into the model
progress (bool): show progress bar when downloading model
map_location: a function or a dict specifying how to remap storage locations (see torch.load)
"""
return _hifigan(
"hifigan-hubert-soft", pretrained, progress, map_location=map_location
)
def hifigan_hubert_discrete(
pretrained: bool = True,
progress: bool = True,
map_location=None,
) -> HifiganGenerator:
"""HiFiGAN Vocoder from from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
Finetuned on spectrograms generated from the discrete acoustic model.
Args:
pretrained (bool): load pretrained weights into the model
progress (bool): show progress bar when downloading model
map_location: a function or a dict specifying how to remap storage locations (see torch.load)
"""
return _hifigan(
"hifigan-hubert-discrete", pretrained, progress, map_location=map_location
)