janitor

janitor
git clone https://git.prime8.dev/janitor.git
Log | Files | Refs | README | LICENSE

test_feature_window_function.py (718B)


      1 #!/usr/bin/env python3
      2 #
      3 # Copyright (c)  2022-2023  Xiaomi Corporation (authors: Fangjun Kuang)
      4 
      5 import kaldi_native_fbank as knf
      6 import torch
      7 
      8 
      9 def test_hann_window():
     10     opts = knf.FrameExtractionOptions()
     11     assert opts.samp_freq == 16000
     12     assert opts.frame_shift_ms == 10.0
     13     assert opts.frame_length_ms == 25.0
     14     opts.window_type = "hann"
     15 
     16     n = int((opts.samp_freq * opts.frame_length_ms) / 1000)
     17 
     18     window = knf.FeatureWindowFunction(opts)
     19     assert len(window.window) == n
     20     w = torch.tensor(window.window)
     21 
     22     t = torch.hann_window(n, periodic=True)
     23     assert torch.allclose(w, t, atol=1e-6), (w - t).abs().max()
     24 
     25 
     26 def main():
     27     test_hann_window()
     28 
     29 
     30 if __name__ == "__main__":
     31     main()