Skip to content

Commit 8e68265

Browse files
authored
Update kaldi-native-fbank. (k2-fsa#2259)
Now it supports FFT of an even number, not necessarily a power of 2.
1 parent d8b5a58 commit 8e68265

9 files changed

Lines changed: 28 additions & 16 deletions

cmake/kaldi-native-fbank.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function(download_kaldi_native_fbank)
22
include(FetchContent)
33

4-
set(kaldi_native_fbank_URL "https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.21.1.tar.gz")
5-
set(kaldi_native_fbank_URL2 "https://hf-mirror.com/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/kaldi-native-fbank-1.21.1.tar.gz")
6-
set(kaldi_native_fbank_HASH "SHA256=37c1aa230b00fe062791d800d8fc50aa3de215918d3dce6440699e67275d859e")
4+
set(kaldi_native_fbank_URL "https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.21.2.tar.gz")
5+
set(kaldi_native_fbank_URL2 "https://hf-mirror.com/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/kaldi-native-fbank-1.21.2.tar.gz")
6+
set(kaldi_native_fbank_HASH "SHA256=f4bd7d53fe8aeaecc4eda9680c72696bb86bf74e86371d81aacacd6f4ca3914d")
77

88
set(KALDI_NATIVE_FBANK_BUILD_TESTS OFF CACHE BOOL "" FORCE)
99
set(KALDI_NATIVE_FBANK_BUILD_PYTHON OFF CACHE BOOL "" FORCE)
@@ -12,11 +12,11 @@ function(download_kaldi_native_fbank)
1212
# If you don't have access to the Internet,
1313
# please pre-download kaldi-native-fbank
1414
set(possible_file_locations
15-
$ENV{HOME}/Downloads/kaldi-native-fbank-1.21.1.tar.gz
16-
${CMAKE_SOURCE_DIR}/kaldi-native-fbank-1.21.1.tar.gz
17-
${CMAKE_BINARY_DIR}/kaldi-native-fbank-1.21.1.tar.gz
18-
/tmp/kaldi-native-fbank-1.21.1.tar.gz
19-
/star-fj/fangjun/download/github/kaldi-native-fbank-1.21.1.tar.gz
15+
$ENV{HOME}/Downloads/kaldi-native-fbank-1.21.2.tar.gz
16+
${CMAKE_SOURCE_DIR}/kaldi-native-fbank-1.21.2.tar.gz
17+
${CMAKE_BINARY_DIR}/kaldi-native-fbank-1.21.2.tar.gz
18+
/tmp/kaldi-native-fbank-1.21.2.tar.gz
19+
/star-fj/fangjun/download/github/kaldi-native-fbank-1.21.2.tar.gz
2020
)
2121

2222
foreach(f IN LISTS possible_file_locations)

cmake/sherpa-onnx-static-no-tts.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Cflags: -I"${includedir}"
2222
# Note: -lcargs is required only for the following file
2323
# https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c
2424
# We add it here so that users don't need to specify -lcargs when compiling decode-file-c-api.c
25-
Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fst -lkaldi-native-fbank-core -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@
25+
Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@

cmake/sherpa-onnx-static.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Cflags: -I"${includedir}"
2222
# Note: -lcargs is required only for the following file
2323
# https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c
2424
# We add it here so that users don't need to specify -lcargs when compiling decode-file-c-api.c
25-
Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@
25+
Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@

scripts/nemo/GigaAM/test-onnx-ctc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def create_fbank():
1818
opts.frame_opts.preemph_coeff = 0
1919
opts.frame_opts.window_type = "hann"
2020

21-
# Even though GigaAM uses 400 for fft, here we use 512
22-
# since kaldi-native-fbank only supports fft for power of 2.
23-
opts.frame_opts.round_to_power_of_two = True
21+
opts.frame_opts.round_to_power_of_two = False
2422

2523
opts.mel_opts.low_freq = 0
2624
opts.mel_opts.high_freq = 8000

scripts/nemo/GigaAM/test-onnx-rnnt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def create_fbank():
1919
opts.frame_opts.preemph_coeff = 0
2020
opts.frame_opts.window_type = "hann"
2121

22-
# Even though GigaAM uses 400 for fft, here we use 512
23-
# since kaldi-native-fbank only supports fft for power of 2.
24-
opts.frame_opts.round_to_power_of_two = True
22+
opts.frame_opts.round_to_power_of_two = False
2523

2624
opts.mel_opts.low_freq = 0
2725
opts.mel_opts.high_freq = 8000

sherpa-onnx/csrc/features.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class FeatureExtractor::Impl {
197197
opts_.frame_opts.remove_dc_offset = config_.remove_dc_offset;
198198
opts_.frame_opts.preemph_coeff = config_.preemph_coeff;
199199
opts_.frame_opts.window_type = config_.window_type;
200+
opts_.frame_opts.round_to_power_of_two = config_.round_to_power_of_two;
200201

201202
opts_.mel_opts.num_bins = config_.feature_dim;
202203

@@ -216,6 +217,7 @@ class FeatureExtractor::Impl {
216217
mfcc_opts_.frame_opts.remove_dc_offset = config_.remove_dc_offset;
217218
mfcc_opts_.frame_opts.preemph_coeff = config_.preemph_coeff;
218219
mfcc_opts_.frame_opts.window_type = config_.window_type;
220+
mfcc_opts_.frame_opts.round_to_power_of_two = config_.round_to_power_of_two;
219221

220222
mfcc_opts_.mel_opts.num_bins = config_.feature_dim;
221223

sherpa-onnx/csrc/features.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct FeatureExtractorConfig {
7979

8080
bool is_mfcc = false;
8181

82+
bool round_to_power_of_two = true;
83+
8284
std::string ToString() const;
8385

8486
void Register(ParseOptions *po);

sherpa-onnx/csrc/offline-recognizer-ctc-impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class OfflineRecognizerCtcImpl : public OfflineRecognizerImpl {
109109
config_.feat_config.preemph_coeff = 0;
110110
config_.feat_config.window_type = "hann";
111111
config_.feat_config.feature_dim = 64;
112+
113+
// see
114+
// https://github.com/salute-developers/GigaAM/blob/main/gigaam/preprocess.py#L68
115+
//
116+
// GigaAM uses n_fft 400
117+
config_.feat_config.round_to_power_of_two = false;
112118
} else {
113119
config_.feat_config.low_freq = 0;
114120
config_.feat_config.high_freq = 0;

sherpa-onnx/csrc/offline-recognizer-transducer-nemo-impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
156156
config_.feat_config.preemph_coeff = 0;
157157
config_.feat_config.window_type = "hann";
158158
config_.feat_config.feature_dim = 64;
159+
160+
// see
161+
// https://github.com/salute-developers/GigaAM/blob/main/gigaam/preprocess.py#L68
162+
//
163+
// GigaAM uses n_fft 400
164+
config_.feat_config.round_to_power_of_two = false;
159165
} else {
160166
config_.feat_config.low_freq = 0;
161167
// config_.feat_config.high_freq = 8000;

0 commit comments

Comments
 (0)