janitor

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

test_online_fbank.py (1170B)


      1 #!/usr/bin/env python3
      2 
      3 import sys
      4 
      5 try:
      6     import kaldifeat
      7 except:
      8     print("Please install kaldifeat first")
      9     sys.exit(0)
     10 
     11 import kaldi_native_fbank as knf
     12 import torch
     13 
     14 
     15 def main():
     16     sampling_rate = 16000
     17     samples = torch.randn(16000 * 10)
     18 
     19     opts = kaldifeat.FbankOptions()
     20     opts.frame_opts.dither = 0
     21     opts.mel_opts.num_bins = 80
     22     opts.frame_opts.snip_edges = False
     23     opts.mel_opts.debug_mel = False
     24 
     25     online_fbank = kaldifeat.OnlineFbank(opts)
     26 
     27     online_fbank.accept_waveform(sampling_rate, samples)
     28 
     29     opts = knf.FbankOptions()
     30     opts.frame_opts.dither = 0
     31     opts.mel_opts.num_bins = 80
     32     opts.frame_opts.snip_edges = False
     33     opts.mel_opts.debug_mel = False
     34 
     35     fbank = knf.OnlineFbank(opts)
     36     fbank.accept_waveform(sampling_rate, samples.tolist())
     37 
     38     assert online_fbank.num_frames_ready == fbank.num_frames_ready
     39     for i in range(fbank.num_frames_ready):
     40         f1 = online_fbank.get_frame(i)
     41         f2 = torch.from_numpy(fbank.get_frame(i))
     42         assert torch.allclose(f1, f2, atol=1e-3), (i, (f1 - f2).abs().max())
     43 
     44 
     45 if __name__ == "__main__":
     46     torch.manual_seed(20220825)
     47     main()
     48     print("success")