From a3bac19c5480de865603964b95bbbcc5a14d38ee Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Mon, 24 Jun 2024 21:52:54 +0800 Subject: [PATCH] fix a bug for wenet streaming model. (#1054) * fix a bug for wenet streaming model. The chunk shift was wrong. See https://github.com/wenet-e2e/wenet/blob/main/runtime/core/decoder/asr_model.cc#L15 and https://github.com/wenet-e2e/wenet/blob/main/runtime/core/decoder/asr_model.cc#L28 --- .github/workflows/test-build-wheel.yaml | 2 +- .github/workflows/test-pip-install.yaml | 2 +- scripts/wenet/test-onnx-streaming.py | 2 +- sherpa-onnx/csrc/online-wenet-ctc-model.cc | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-build-wheel.yaml b/.github/workflows/test-build-wheel.yaml index 91eaea01a..d2f860d51 100644 --- a/.github/workflows/test-build-wheel.yaml +++ b/.github/workflows/test-build-wheel.yaml @@ -132,7 +132,7 @@ jobs: export PATH=/c/hostedtoolcache/windows/Python/3.9.13/x64/bin:$PATH export PATH=/c/hostedtoolcache/windows/Python/3.10.11/x64/bin:$PATH export PATH=/c/hostedtoolcache/windows/Python/3.11.9/x64/bin:$PATH - export PATH=/c/hostedtoolcache/windows/Python/3.12.3/x64/bin:$PATH + export PATH=/c/hostedtoolcache/windows/Python/3.12.4/x64/bin:$PATH which sherpa-onnx sherpa-onnx --help diff --git a/.github/workflows/test-pip-install.yaml b/.github/workflows/test-pip-install.yaml index 998469cef..4032e8d24 100644 --- a/.github/workflows/test-pip-install.yaml +++ b/.github/workflows/test-pip-install.yaml @@ -107,7 +107,7 @@ jobs: export PATH=/c/hostedtoolcache/windows/Python/3.9.13/x64/bin:$PATH export PATH=/c/hostedtoolcache/windows/Python/3.10.11/x64/bin:$PATH export PATH=/c/hostedtoolcache/windows/Python/3.11.9/x64/bin:$PATH - export PATH=/c/hostedtoolcache/windows/Python/3.12.3/x64/bin:$PATH + export PATH=/c/hostedtoolcache/windows/Python/3.12.4/x64/bin:$PATH sherpa-onnx --help sherpa-onnx-keyword-spotter --help diff --git a/scripts/wenet/test-onnx-streaming.py b/scripts/wenet/test-onnx-streaming.py index cbf27b745..4730df0f4 100755 --- a/scripts/wenet/test-onnx-streaming.py +++ b/scripts/wenet/test-onnx-streaming.py @@ -143,7 +143,7 @@ def main(): (model.chunk_size - 1) * model.subsampling_factor + model.right_context + 1 ) chunk_length = int(chunk_length) - chunk_shift = int(model.required_cache_size) + chunk_shift = int(model.chunk_size * model.subsampling_factor) print(chunk_length, chunk_shift) num_frames = x.shape[0] diff --git a/sherpa-onnx/csrc/online-wenet-ctc-model.cc b/sherpa-onnx/csrc/online-wenet-ctc-model.cc index 50a7a10aa..793d4eb0c 100644 --- a/sherpa-onnx/csrc/online-wenet-ctc-model.cc +++ b/sherpa-onnx/csrc/online-wenet-ctc-model.cc @@ -97,7 +97,9 @@ class OnlineWenetCtcModel::Impl { right_context_ + 1; } - int32_t ChunkShift() const { return required_cache_size_; } + int32_t ChunkShift() const { + return config_.wenet_ctc.chunk_size * subsampling_factor_; + } OrtAllocator *Allocator() const { return allocator_; }