MCPcopy Create free account
hub / github.com/espnet/espnet / STFTDecoder

Class STFTDecoder

espnet2/enh/decoder/stft_decoder.py:10–199  ·  view source on GitHub ↗

STFT decoder for speech enhancement and separation

Source from the content-addressed store, hash-verified

8
9
10class STFTDecoder(AbsDecoder):
11 """STFT decoder for speech enhancement and separation"""
12
13 def __init__(
14 self,
15 n_fft: int = 512,
16 win_length: int = None,
17 hop_length: int = 128,
18 window="hann",
19 center: bool = True,
20 normalized: bool = False,
21 onesided: bool = True,
22 default_fs: int = 16000,
23 spec_transform_type: str = None,
24 spec_factor: float = 0.15,
25 spec_abs_exponent: float = 0.5,
26 ):
27 super().__init__()
28 self.stft = Stft(
29 n_fft=n_fft,
30 win_length=win_length,
31 hop_length=hop_length,
32 window=window,
33 center=center,
34 normalized=normalized,
35 onesided=onesided,
36 )
37
38 self.win_length = win_length if win_length else n_fft
39 self.n_fft = n_fft
40 self.hop_length = hop_length
41 self.window = window
42 self.center = center
43 self.default_fs = default_fs
44
45 # spec transform related. See equation (1) in paper
46 # 'Speech Enhancement and Dereverberation With Diffusion-Based Generative
47 # Models'. The default value of 0.15, 0.5 also come from the paper.
48 # spec_transform_type: "exponent", "log", or "none"
49 self.spec_transform_type = spec_transform_type
50 # the output specturm will be scaled with: spec * self.spec_factor
51 self.spec_factor = spec_factor
52 # the exponent factor used in the "exponent" transform
53 self.spec_abs_exponent = spec_abs_exponent
54
55 @torch.amp.autocast("cuda", enabled=False)
56 def forward(self, input: ComplexTensor, ilens: torch.Tensor, fs: int = None):
57 """Forward.
58
59 Args:
60 input (ComplexTensor): spectrum [Batch, T, (C,) F]
61 ilens (torch.Tensor): input lengths [Batch]
62 fs (int): sampling rate in Hz
63 If not None, reconfigure iSTFT window and hop lengths for a new
64 sampling rate while keeping their duration fixed.
65 """
66 if not isinstance(input, ComplexTensor) and (not torch.is_complex(input)):
67 raise TypeError("Only support complex tensors for stft decoder")

Callers 15

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
test_uses_forwardFunction · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…