def func(tensor): cmn_window = 600 min_cmn_window = 100 center = False norm_vars = False a = torch.tensor([[-1.915875792503357, 1.147700309753418], [1.8242558240890503, 1.3869990110397339]], device=tensor.device, dtype=tensor.dtype) return F.sliding_window_cmn(a, cmn_window, min_cmn_window, center, norm_vars)
def forward(self, waveform: Tensor) -> Tensor: r""" Args: waveform (Tensor): Tensor of audio of dimension (..., time). Returns: Tensor: Tensor of audio of dimension (..., time). """ cmn_waveform = F.sliding_window_cmn( waveform, self.cmn_window, self.min_cmn_window, self.center, self.norm_vars) return cmn_waveform
def test_sliding_window_cmn(self): """sliding_window_cmn should be numerically compatible with apply-cmvn-sliding""" kwargs = { 'cmn_window': 600, 'min_cmn_window': 100, 'center': False, 'norm_vars': False, } tensor = torch.randn(40, 10, dtype=self.dtype, device=self.device) result = F.sliding_window_cmn(tensor, **kwargs) command = ['apply-cmvn-sliding'] + _convert_args(**kwargs) + ['ark:-', 'ark:-'] kaldi_result = _run_kaldi(command, 'ark', tensor) self.assert_equal(result, expected=kaldi_result)
def test_sliding_window_cmn(self): """sliding_window_cmn should be numerically compatible with apply-cmvn-sliding""" kwargs = { 'cmn_window': 600, 'min_cmn_window': 100, 'center': False, 'norm_vars': False, } tensor = torch.randn(40, 10) result = F.sliding_window_cmn(tensor, **kwargs) command = ['apply-cmvn-sliding'] + _convert_args(**kwargs) + ['ark:-', 'ark:-'] kaldi_result = _run_kaldi(command, 'ark', tensor) torch.testing.assert_allclose(result, kaldi_result)