-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.py
executable file
·66 lines (53 loc) · 1.71 KB
/
bench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import kaldifeat
import kaldi_native_fbank as knf
from ctypes import *
import time
import torch
c_float_p = POINTER(c_float)
knfc = simutil = CDLL("libknf.so")
knfc.knf_create.argtypes = [c_int, c_int]
knfc.knf_create.restype = c_void_p
knfc.knf_accept_waveform.argtypes = [c_void_p, c_int, c_float_p, c_int]
knfc.knf_num_frames_ready.argtypes = [c_void_p]
knfc.knf_get_frame.argtypes = [c_void_p, c_int]
knfc.knf_get_frame.restype = c_float_p
def main():
sampling_rate = 16000
samples = torch.randn(16000 * 1000)
samples.numpy()
# kaldi feat
opts = kaldifeat.FbankOptions()
opts.frame_opts.dither = 0
opts.mel_opts.num_bins = 80
opts.frame_opts.snip_edges = False
opts.mel_opts.debug_mel = False
opts.mel_opts.high_freq = -400
online_fbank = kaldifeat.OnlineFbank(opts)
start = time.time()
online_fbank.accept_waveform(sampling_rate, samples)
end = time.time()
print("kalifeat", end - start)
# knf
opts = knf.FbankOptions()
opts.frame_opts.dither = 0
opts.mel_opts.num_bins = 80
opts.frame_opts.snip_edges = False
opts.mel_opts.debug_mel = False
opts.mel_opts.high_freq = -400
fbank = knf.OnlineFbank(opts)
samples_list = samples.tolist()
start = time.time()
fbank.accept_waveform(sampling_rate, samples_list)
end = time.time()
print("kali-native-feat", end - start)
# knfc
k = knfc.knf_create(sampling_rate, 80)
start = time.time()
samples_ptr = samples.numpy().ctypes.data_as(c_float_p)
knfc.knf_accept_waveform(k, sampling_rate, samples_ptr, len(samples))
end = time.time()
print("knfc", end - start)
if __name__ == "__main__":
torch.manual_seed(20220825)
main()