janitor

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

README.md (2597B)


      1 # Introduction
      2 
      3 Kaldi-compatible online fbank feature extractor without external dependencies.
      4 
      5 Tested on the following architectures and operating systems:
      6 
      7   - Linux
      8   - macOS
      9   - Windows
     10   - Android
     11   - x86
     12   - arm
     13   - aarch64
     14 
     15 # Usage
     16 
     17 See the following CMake-based speech recognition (i.e., text-to-speech) projects
     18 for its usage:
     19 
     20 - <https://github.com/k2-fsa/sherpa-ncnn>
     21   - Specifically, please have a look at <https://github.com/k2-fsa/sherpa-ncnn/blob/master/sherpa-ncnn/csrc/features.h>
     22 - <https://github.com/k2-fsa/sherpa-onnx>
     23 
     24 They use `kaldi-native-fbank` to compute fbank features for **real-time**
     25 speech recognition.
     26 
     27 # Python APIs
     28 
     29 First, please install `kaldi-native-fbank` by
     30 
     31 ```bash
     32 git clone https://github.com/csukuangfj/kaldi-native-fbank
     33 cd kaldi-native-fbank
     34 python3 setup.py install
     35 ```
     36 
     37 or use
     38 
     39 ```bash
     40 pip install kaldi-native-fbank
     41 ```
     42 
     43 To check that you have installed `kaldi-native-fbank` successfully, please use
     44 
     45 ```
     46 python3 -c "import kaldi_native_fbank; print(kaldi_native_fbank.__version__)"
     47 ```
     48 
     49 which should print the version you have installed.
     50 
     51 Please refer to
     52 
     53   - <https://github.com/csukuangfj/kaldi-native-fbank/blob/master/kaldi-native-fbank/python/tests/test_online_fbank.py>
     54   - <https://github.com/csukuangfj/kaldi-native-fbank/blob/master/kaldi-native-fbank/python/tests/test_online_mfcc.py>
     55 
     56 for usages.
     57 
     58 For easier reference, we post the above file below:
     59 
     60 ```python3
     61 #!/usr/bin/env python3
     62 
     63 import sys
     64 
     65 try:
     66     import kaldifeat
     67 except:
     68     print("Please install kaldifeat first")
     69     sys.exit(0)
     70 
     71 import kaldi_native_fbank as knf
     72 import torch
     73 
     74 
     75 def main():
     76     sampling_rate = 16000
     77     samples = torch.randn(16000 * 10)
     78 
     79     opts = kaldifeat.FbankOptions()
     80     opts.frame_opts.dither = 0
     81     opts.mel_opts.num_bins = 80
     82     opts.frame_opts.snip_edges = False
     83     opts.mel_opts.debug_mel = False
     84 
     85     online_fbank = kaldifeat.OnlineFbank(opts)
     86 
     87     online_fbank.accept_waveform(sampling_rate, samples)
     88 
     89     opts = knf.FbankOptions()
     90     opts.frame_opts.dither = 0
     91     opts.mel_opts.num_bins = 80
     92     opts.frame_opts.snip_edges = False
     93     opts.mel_opts.debug_mel = False
     94 
     95     fbank = knf.OnlineFbank(opts)
     96     fbank.accept_waveform(sampling_rate, samples.tolist())
     97 
     98     assert online_fbank.num_frames_ready == fbank.num_frames_ready
     99     for i in range(fbank.num_frames_ready):
    100         f1 = online_fbank.get_frame(i)
    101         f2 = torch.from_numpy(fbank.get_frame(i))
    102         assert torch.allclose(f1, f2, atol=1e-3), (i, (f1 - f2).abs().max())
    103 
    104 
    105 if __name__ == "__main__":
    106     torch.manual_seed(20220825)
    107     main()
    108     print("success")
    109 ```