Repository navigation
Support ten vad #2377
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
Merged
Support ten vad #2377
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions
4
cxx-api-examples/zipformer-transducer-simulate-streaming-microphone-cxx-api.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
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
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
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,111 @@ | ||
| // sherpa-onnx/csrc/ten-vad-model-config.cc | ||
| // | ||
| // Copyright (c) 2025 Xiaomi Corporation | ||
|
|
||
| #include "sherpa-onnx/csrc/ten-vad-model-config.h" | ||
|
|
||
| #include "sherpa-onnx/csrc/file-utils.h" | ||
| #include "sherpa-onnx/csrc/macros.h" | ||
|
|
||
| namespace sherpa_onnx { | ||
|
|
||
| void TenVadModelConfig::Register(ParseOptions *po) { | ||
| po->Register("ten-vad-model", &model, "Path to TEN VAD ONNX model."); | ||
|
|
||
| po->Register("ten-vad-threshold", &threshold, | ||
| "Speech threshold. TEN VAD outputs speech probabilities for " | ||
| "each audio chunk, probabilities ABOVE this value are " | ||
| "considered as SPEECH. It is better to tune this parameter for " | ||
| "each dataset separately, but lazy " | ||
| "0.5 is pretty good for most datasets."); | ||
|
|
||
| po->Register("ten-vad-min-silence-duration", &min_silence_duration, | ||
| "In seconds. In the end of each speech chunk wait for " | ||
| "--ten-vad-min-silence-duration seconds before separating it"); | ||
|
|
||
| po->Register("ten-vad-min-speech-duration", &min_speech_duration, | ||
| "In seconds. In the end of each silence chunk wait for " | ||
| "--ten-vad-min-speech-duration seconds before separating it"); | ||
|
|
||
| po->Register( | ||
| "ten-vad-max-speech-duration", &max_speech_duration, | ||
| "In seconds. If a speech segment is longer than this value, then we " | ||
| "increase the threshold to 0.9. After finishing detecting the segment, " | ||
| "the threshold value is reset to its original value."); | ||
|
|
||
| po->Register( | ||
| "ten-vad-window-size", &window_size, | ||
| "In samples. Audio chunks of --ten-vad-window-size samples are fed " | ||
| "to the ten VAD model. WARNING! Please use 160 or 256 "); | ||
| } | ||
|
|
||
| bool TenVadModelConfig::Validate() const { | ||
| if (model.empty()) { | ||
| SHERPA_ONNX_LOGE("Please provide --ten-vad-model"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!FileExists(model)) { | ||
| SHERPA_ONNX_LOGE("TEN vad model file '%s' does not exist", model.c_str()); | ||
| return false; | ||
| } | ||
|
|
||
| if (threshold < 0.01) { | ||
| SHERPA_ONNX_LOGE( | ||
| "Please use a larger value for --ten-vad-threshold. Given: %f", | ||
| threshold); | ||
| return false; | ||
| } | ||
|
|
||
| if (threshold >= 1) { | ||
| SHERPA_ONNX_LOGE( | ||
| "Please use a smaller value for --ten-vad-threshold. Given: %f", | ||
| threshold); | ||
| return false; | ||
| } | ||
|
|
||
| if (min_silence_duration <= 0) { | ||
| SHERPA_ONNX_LOGE( | ||
| "Please use a larger value for --ten-vad-min-silence-duration. " | ||
| "Given: " | ||
| "%f", | ||
| min_silence_duration); | ||
| return false; | ||
| } | ||
|
|
||
| if (min_speech_duration <= 0) { | ||
| SHERPA_ONNX_LOGE( | ||
| "Please use a larger value for --ten-vad-min-speech-duration. " | ||
| "Given: " | ||
| "%f", | ||
| min_speech_duration); | ||
| return false; | ||
| } | ||
|
|
||
| if (max_speech_duration <= 0) { | ||
| SHERPA_ONNX_LOGE( | ||
| "Please use a larger value for --ten-vad-max-speech-duration. " | ||
| "Given: " | ||
| "%f", | ||
| max_speech_duration); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
csukuangfj marked this conversation as resolved.
|
||
|
|
||
| std::string TenVadModelConfig::ToString() const { | ||
| std::ostringstream os; | ||
|
|
||
| os << "TenVadModelConfig("; | ||
| os << "model=\"" << model << "\", "; | ||
| os << "threshold=" << threshold << ", "; | ||
| os << "min_silence_duration=" << min_silence_duration << ", "; | ||
| os << "min_speech_duration=" << min_speech_duration << ", "; | ||
| os << "max_speech_duration=" << max_speech_duration << ", "; | ||
| os << "window_size=" << window_size << ")"; | ||
|
|
||
| return os.str(); | ||
| } | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // sherpa-onnx/csrc/ten-vad-model-config.h | ||
| // | ||
| // Copyright (c) 2025 Xiaomi Corporation | ||
| #ifndef SHERPA_ONNX_CSRC_TEN_VAD_MODEL_CONFIG_H_ | ||
| #define SHERPA_ONNX_CSRC_TEN_VAD_MODEL_CONFIG_H_ | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "sherpa-onnx/csrc/parse-options.h" | ||
|
|
||
| namespace sherpa_onnx { | ||
|
|
||
| struct TenVadModelConfig { | ||
| std::string model; | ||
|
|
||
| // threshold to classify a segment as speech | ||
| // | ||
| // If the predicted probability of a segment is larger than this | ||
| // value, then it is classified as speech. | ||
| float threshold = 0.5; | ||
|
|
||
| float min_silence_duration = 0.5; // in seconds | ||
|
|
||
| float min_speech_duration = 0.25; // in seconds | ||
|
|
||
| // 160 or 256 | ||
| int32_t window_size = 256; // in samples | ||
|
|
||
| // If a speech segment is longer than this value, then we increase | ||
| // the threshold to 0.9. After finishing detecting the segment, | ||
| // the threshold value is reset to its original value. | ||
| float max_speech_duration = 20; // in seconds | ||
|
|
||
| TenVadModelConfig() = default; | ||
|
|
||
| void Register(ParseOptions *po); | ||
|
|
||
| bool Validate() const; | ||
|
|
||
| std::string ToString() const; | ||
| }; | ||
|
|
||
| } // namespace sherpa_onnx | ||
|
|
||
| #endif // SHERPA_ONNX_CSRC_TEN_VAD_MODEL_CONFIG_H_ |
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.
Uh oh!
There was an error while loading. Please reload this page.