Skip to content

Commit

Permalink
fix n_fft, win_length, f_min
Browse files Browse the repository at this point in the history
  • Loading branch information
michelwi committed Aug 24, 2023
1 parent d2c8a24 commit a01f7fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions i6_models/primitives/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LogMelFeatureExtractionV1Config(ModelConfiguration):
def __post_init__(self) -> None:
super().__post_init__()
assert self.f_max <= self.sample_rate // 2, "f_max can not be larger than half of the sample rate"
assert self.f_min > 0 and self.f_max > 0 and self.sample_rate > 0, "frequencies need to be positive"
assert self.f_min >= 0 and self.f_max > 0 and self.sample_rate > 0, "frequencies need to be positive"
assert self.win_size > 0 and self.hop_size > 0, "window settings need to be positive"
assert self.num_filters > 0, "number of filters needs to be positive"
assert self.hop_size <= self.win_size, "using a larger hop size than window size does not make sense"
Expand All @@ -58,6 +58,7 @@ class LogMelFeatureExtractionV1(nn.Module):
def __init__(self, cfg: LogMelFeatureExtractionV1Config):
super().__init__()
self.register_buffer("n_fft", torch.tensor(cfg.n_fft))
self.register_buffer("win_length", torch.tensor(int(cfg.win_size * cfg.sample_rate)))
self.register_buffer("window", torch.hann_window(int(cfg.win_size * cfg.sample_rate)))
self.register_buffer("hop_length", torch.tensor(int(cfg.hop_size * cfg.sample_rate)))
self.register_buffer("min_amp", torch.tensor(cfg.min_amp))
Expand All @@ -67,7 +68,7 @@ def __init__(self, cfg: LogMelFeatureExtractionV1Config):
torch.tensor(
filters.mel(
sr=cfg.sample_rate,
n_fft=int(cfg.sample_rate * cfg.win_size),
n_fft=cfg.n_fft,
n_mels=cfg.num_filters,
fmin=cfg.f_min,
fmax=cfg.f_max,
Expand All @@ -87,6 +88,7 @@ def forward(self, raw_audio, length) -> Tuple[torch.Tensor, torch.Tensor]:
raw_audio,
n_fft=self.n_fft,
hop_length=self.hop_length,
win_length=self.win_length,
window=self.window,
center=self.center,
pad_mode="constant",
Expand Down

0 comments on commit a01f7fa

Please sign in to comment.