-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix FunASR-Nano hallucinating text on silent audio #3921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
csukuangfj
merged 4 commits into
k2-fsa:master
from
kyo-zzz:fix/funasr-nano-silent-audio
Sep 8, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4ca697f
Fix FunASR-Nano hallucinating text on silent audio
kyo-zzz 6d0726c
Add a repeated non-uniform frame test case
kyo-zzz 9635386
Apply suggestion from @csukuangfj
csukuangfj 0cf9b9c
Merge branch 'master' into fix/funasr-nano-silent-audio
csukuangfj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl-test.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl-test.cc | ||
| // | ||
| // Copyright (c) 2026 kyo-zzz | ||
|
|
||
| #include "sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.h" | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace sherpa_onnx { | ||
|
|
||
| // Digital silence produces constant fbank frames (dither is disabled for this | ||
| // model family), so FunASRNanoAudioIsSilent() must report silence for them | ||
| // and signal for any varying content. DecodeStreams() uses this to return an | ||
| // empty transcript before hotwords/language prompt tokens can bias the LLM | ||
| // decoder into hallucinating text for silent audio, mirroring the Qwen3-ASR | ||
| // recognizer. | ||
| TEST(FunASRNanoAudioIsSilent, ConstantFramesAreSilence) { | ||
| // LFR stacks feature_dim*window floats per output frame; the values are | ||
| // identical for a constant input. | ||
| std::vector<float> features = {2.5f, 2.5f, 2.5f, 2.5f, 2.5f, 2.5f}; | ||
| EXPECT_TRUE(FunASRNanoAudioIsSilent(features.data(), features.size())); | ||
| } | ||
|
|
||
| TEST(FunASRNanoAudioIsSilent, RepeatedNonUniformFramesAreSignal) { | ||
| // alternating values still vary frame to frame, so this is signal | ||
| std::vector<float> features = {1.0f, 2.0f, 1.0f, 2.0f}; | ||
| EXPECT_FALSE(FunASRNanoAudioIsSilent(features.data(), features.size())); | ||
| } | ||
|
|
||
| TEST(FunASRNanoAudioIsSilent, VaryingFramesAreSignal) { | ||
| std::vector<float> features = {2.5f, 2.5f, -1.25f, 2.5f, 2.5f, 2.5f}; | ||
| EXPECT_FALSE(FunASRNanoAudioIsSilent(features.data(), features.size())); | ||
| } | ||
|
|
||
| TEST(FunASRNanoAudioIsSilent, ZerosAreSilence) { | ||
| std::vector<float> features(64, 0.0f); | ||
| EXPECT_TRUE(FunASRNanoAudioIsSilent(features.data(), features.size())); | ||
| } | ||
|
|
||
| TEST(FunASRNanoAudioIsSilent, SingleValueIsSilence) { | ||
| // A single frame carries no variation to inspect. | ||
| std::vector<float> features = {2.5f}; | ||
| EXPECT_TRUE(FunASRNanoAudioIsSilent(features.data(), features.size())); | ||
| } | ||
|
|
||
| TEST(FunASRNanoAudioIsSilent, EmptyInputIsNotSilence) { | ||
| // An empty input is handled by the caller (num_frames <= 0), not here. | ||
| float unused = 0; | ||
| EXPECT_FALSE(FunASRNanoAudioIsSilent(&unused, 0)); | ||
| } | ||
|
|
||
| } // namespace sherpa_onnx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Make silence detection frame-aware. The current API, implementation, and tests treat the flattened feature buffer as one repeated scalar. The stated contract requires detecting identical frame vectors.
sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.h#L31-L31: add frame count or frame width to the helper contract.sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.cc#L186-L187: compare each frame block with the first frame.sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.cc#L886-L887: pass the frame geometry already computed byDecodeStreams.sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl-test.cc#L22-L23: add a repeated non-uniform frame case.📍 Affects 3 files
sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.h#L31-L31(this comment)sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.cc#L186-L187sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl.cc#L886-L887sherpa-onnx/csrc/offline-recognizer-funasr-nano-impl-test.cc#L22-L23🤖 Prompt for AI Agents