Skip to content

Add Java/Kotlin API and Android support for ten-vad - #2389

Merged
csukuangfj merged 4 commits into
k2-fsa:masterfrom
csukuangfj:jni-api-ten-vad
Jul 12, 2025
Merged

csukuangfj merged 4 commits into
k2-fsa:masterfrom
csukuangfj:jni-api-ten-vad

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Jul 12, 2025 •

Copy link
Copy Markdown
Collaborator

You can find the Android APK for ten-vad at
https://k2-fsa.github.io/sherpa/onnx/vad/apk.html

Screenshot 2025-07-12 at 18 28 51

Summary by CodeRabbit

  • New Features

    • Added support for a new "ten-vad" voice activity detection (VAD) model in Java and Kotlin APIs, including configuration options and example scripts.
    • Introduced a Java example and shell script to demonstrate removing silence using the ten-vad model.
  • Bug Fixes

    • Corrected typographical errors in variable names and script filenames related to "silence".
  • Documentation

    • Updated download URLs for VAD models across documentation, usage messages, and example scripts to point to the latest source.
    • Improved instructions and added references for the new ten-vad model in relevant documentation.
  • Chores

    • Enhanced build scripts to support APK generation for both silero_vad and ten-vad models.

@csukuangfj
csukuangfj requested a review from Copilot July 12, 2025 10:29
@coderabbitai

coderabbitai Bot commented Jul 12, 2025 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

This change introduces support for the "ten-vad" voice activity detection model across Java, Kotlin, JNI, and CI workflows. It adds new configuration classes, a Java example, build and run scripts, and updates documentation. Additionally, download URLs for the silero VAD model are updated throughout the codebase to point to the k2-fsa GitHub releases.

Changes

File(s) Change Summary
java-api-examples/TenVadRemoveSilence.java
java-api-examples/run-ten-vad-remove-silence.sh
Added a new Java example and shell script for running silence removal with the ten-vad model.
sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/TenVadModelConfig.java Introduced a new Java class for ten-vad model configuration using the Builder pattern.
sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/VadModelConfig.java Added tenVadModelConfig field and builder support to VadModelConfig.
sherpa-onnx/kotlin-api/Vad.kt Added TenVadModelConfig data class and support for ten-vad in VadModelConfig and configuration function.
sherpa-onnx/java-api/Makefile Included TenVadModelConfig.java in the Java API build process.
sherpa-onnx/jni/voice-activity-detector.cc Extended JNI config extraction to support ten-vad configuration.
java-api-examples/README.md Documented new run-ten-vad-remove-slience.sh command in the VAD section.
.github/workflows/run-java-test.yaml Added CI steps for ten-vad silence removal and improved cleanup; fixed script name typos.
scripts/apk/build-apk-vad.sh Updated silero_vad.onnx URL, added APK build steps for ten-vad, and handled model/parameter switching.
go-api-examples/vad-asr-paraformer/main.go
go-api-examples/vad-asr-paraformer/run.sh
Updated silero_vad.onnx download URL in comments and scripts.
go-api-examples/vad-asr-whisper/main.go
go-api-examples/vad-asr-whisper/run.sh
Updated silero_vad.onnx download URL in comments and scripts.
go-api-examples/vad-speaker-identification/main.go
go-api-examples/vad-speaker-identification/run.sh
Updated silero_vad.onnx download URL in comments and scripts.
go-api-examples/vad-spoken-language-identification/main.go
go-api-examples/vad-spoken-language-identification/run.sh
Updated silero_vad.onnx download URL in comments and scripts.
python-api-examples/*vad*.py Updated silero_vad.onnx download URLs in documentation/comments for all VAD-related Python scripts.
sherpa-onnx/csrc/sherpa-onnx-vad*.cc Updated silero_vad.onnx download URLs in usage messages and example commands.
sherpa-onnx/csrc/keyword-spotter-transducer-impl.h Fixed typo: renamed trailing_slience → trailing_silence.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant JavaApp as TenVadRemoveSilence.java
    participant JNI
    participant NativeLib as C++ VAD Core

    User->>JavaApp: Run TenVadRemoveSilence (with ten-vad.onnx)
    JavaApp->>JNI: Initialize Vad with TenVadModelConfig
    JNI->>NativeLib: Pass ten-vad config to C++ core
    JavaApp->>JavaApp: Read and process audio in windows
    JavaApp->>JNI: Feed audio window to Vad
    JNI->>NativeLib: Process window for speech segments
    NativeLib-->>JNI: Return detected segments
    JNI-->>JavaApp: Return detected segments
    JavaApp->>JavaApp: Collect and concatenate speech segments
    JavaApp->>JavaApp: Save output audio without silence
    JavaApp->>JNI: Release Vad resources
Loading

Possibly related PRs

  • Add Go API for ten-vad #2384: Adds Go API support for the ten-vad model, similar to the Java/Kotlin support in this PR.
  • Support ten vad #2377: Implements core support for the ten-vad model, including configuration, model class, and build integration, directly related to this PR's language bindings.
  • Add C API for ten-vad #2379: Adds C API and examples for the ten-vad model, complementing the Java/Kotlin and CI changes in this PR.

Poem

A ten-vad hop, a silence drop,
Java and Kotlin join the hop!
New configs bloom, the tests all run,
URLs refreshed for everyone.
Now rabbits code with glee and pride—
Ten-vad’s here, with ears open wide!
🐰🎶


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8ce73 and 57b74ae.

📒 Files selected for processing (35)
  • .github/workflows/run-java-test.yaml (1 hunks)
  • go-api-examples/vad-asr-paraformer/main.go (1 hunks)
  • go-api-examples/vad-asr-paraformer/run.sh (1 hunks)
  • go-api-examples/vad-asr-whisper/main.go (1 hunks)
  • go-api-examples/vad-asr-whisper/run.sh (1 hunks)
  • go-api-examples/vad-speaker-identification/main.go (1 hunks)
  • go-api-examples/vad-speaker-identification/run.sh (1 hunks)
  • go-api-examples/vad-spoken-language-identification/main.go (1 hunks)
  • go-api-examples/vad-spoken-language-identification/run.sh (1 hunks)
  • java-api-examples/README.md (1 hunks)
  • java-api-examples/TenVadRemoveSilence.java (1 hunks)
  • java-api-examples/run-ten-vad-remove-silence.sh (1 hunks)
  • python-api-examples/simulate-streaming-sense-voice-microphone.py (1 hunks)
  • python-api-examples/speaker-identification-with-vad-dynamic.py (1 hunks)
  • python-api-examples/speaker-identification-with-vad-non-streaming-asr-alsa.py (1 hunks)
  • python-api-examples/speaker-identification-with-vad-non-streaming-asr.py (1 hunks)
  • python-api-examples/speaker-identification-with-vad.py (1 hunks)
  • python-api-examples/vad-alsa.py (1 hunks)
  • python-api-examples/vad-microphone.py (1 hunks)
  • python-api-examples/vad-remove-non-speech-segments-alsa.py (1 hunks)
  • python-api-examples/vad-remove-non-speech-segments-from-file.py (1 hunks)
  • python-api-examples/vad-remove-non-speech-segments.py (1 hunks)
  • python-api-examples/vad-with-non-streaming-asr.py (1 hunks)
  • scripts/apk/build-apk-vad.sh (2 hunks)
  • sherpa-onnx/csrc/keyword-spotter-transducer-impl.h (1 hunks)
  • sherpa-onnx/csrc/sherpa-onnx-vad-alsa-offline-asr.cc (1 hunks)
  • sherpa-onnx/csrc/sherpa-onnx-vad-alsa.cc (1 hunks)
  • sherpa-onnx/csrc/sherpa-onnx-vad-microphone-offline-asr.cc (1 hunks)
  • sherpa-onnx/csrc/sherpa-onnx-vad-microphone.cc (1 hunks)
  • sherpa-onnx/csrc/sherpa-onnx-vad.cc (1 hunks)
  • sherpa-onnx/java-api/Makefile (1 hunks)
  • sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/TenVadModelConfig.java (1 hunks)
  • sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/VadModelConfig.java (4 hunks)
  • sherpa-onnx/jni/voice-activity-detector.cc (2 hunks)
  • sherpa-onnx/kotlin-api/Vad.kt (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the new ten-vad model across Kotlin, Java, JNI, Android builds, and examples.

  • Introduce TenVadModelConfig in Kotlin and Java APIs and wire it through JNI.
  • Extend Android build script and CI to produce APKs with ten-vad.
  • Provide Java example and scripts for ten-vad-based silence removal.

Reviewed Changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sherpa-onnx/kotlin-api/Vad.kt Added TenVadModelConfig and integrated it into getVadModelConfig
sherpa-onnx/jni/voice-activity-detector.cc JNI parsing for TenVadModelConfig fields
sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/VadModelConfig.java Added builder and accessor for TenVadModelConfig
sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/TenVadModelConfig.java New Java class for ten-vad configuration
sherpa-onnx/java-api/Makefile Included TenVadModelConfig.java in the Java API build
scripts/apk/build-apk-vad.sh Updated Android APK build to include ten-vad model
.github/workflows/run-java-test.yaml CI job to run the ten-vad remove-silence example
java-api-examples/run-ten-vad-remove-slience.sh Demo script for running the ten-vad silence removal example
java-api-examples/TenVadRemoveSilence.java Java example illustrating silence removal via ten-vad
Comments suppressed due to low confidence (3)

sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/TenVadModelConfig.java:55

  • Default windowSize (256) differs from the Kotlin default (512). Align defaults across languages to maintain a consistent API.
        private int windowSize = 256;

sherpa-onnx/java-api/src/com/k2fsa/sherpa/onnx/TenVadModelConfig.java:54

  • Default minSpeechDuration (0.5f) is inconsistent with the Kotlin default (0.25F). Consider unifying this value across both APIs.
        private float minSpeechDuration = 0.5f;

sherpa-onnx/kotlin-api/Vad.kt:129

  • The new case for type = 1 (ten-vad) in getVadModelConfig lacks unit tests. Add tests to verify that ten-vad configurations are built and parsed correctly.
        1 -> {

@@ -0,0 +1,39 @@
#!/usr/bin/env bash

Copilot AI Jul 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script filename and references to 'slience' are misspelled. Rename to 'run-ten-vad-remove-silence.sh' and update occurrences to 'silence'.

Copilot uses AI. Check for mistakes.
# Now for ten-vad
git checkout .
pushd android/SherpaOnnxVad/app/src/main/java/com/k2fsa/sherpa/onnx
sed -i.bak s/"type = 0/type = 1/" ./MainActivity.kt

Copilot AI Jul 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Modifying source with sed can be fragile. Consider using a build flag or configuration to switch model types instead of in-place edits.

Copilot uses AI. Check for mistakes.
@csukuangfj
csukuangfj merged commit b376ad3 into k2-fsa:master Jul 12, 2025
@csukuangfj
csukuangfj deleted the jni-api-ten-vad branch July 12, 2025 11:55
@coderabbitai coderabbitai Bot mentioned this pull request Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants