Skip to content

Add Dart API for ten-vad - #2386

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:dart-api-ten-vad
Jul 12, 2025
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:dart-api-ten-vad

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Jul 12, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for a new voice activity detection (VAD) model configuration ("tenVad") in the Dart and Flutter APIs.
    • Introduced a new command-line tool for processing audio files using the "tenVad" VAD model.
    • Provided a shell script to automate running the new "tenVad" example, including model and audio file setup.
  • Chores

    • Updated test scripts to incorporate the new "tenVad" functionality in the workflow.

@coderabbitai

coderabbitai Bot commented Jul 12, 2025 •

Copy link
Copy Markdown

Walkthrough

This change adds support for a new "ten-vad" voice activity detection (VAD) model in the Dart and Flutter bindings. It introduces new configuration structs, updates the VAD configuration data structures, implements a Dart example for ten-vad, and adds scripts to automate testing and usage of the new model.

Changes

File(s) Change Summary
flutter/sherpa_onnx/lib/src/vad.dart, flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart Added TenVadModelConfig class and related struct; extended VAD config to support ten-vad; updated factory and serialization logic.
dart-api-examples/vad/bin/ten-vad.dart Added a new Dart CLI example for running ten-vad VAD on a WAV file.
dart-api-examples/vad/run-ten-vad.sh Added shell script to automate setup and execution of the ten-vad Dart example.
.github/scripts/test-dart.sh Updated script to run ten-vad example and adjust workflow order.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script (run-ten-vad.sh)
    participant DartApp (ten-vad.dart)
    participant SherpaONNX
    User->>Script (run-ten-vad.sh): Execute script
    Script->>Script: Ensure model & audio files are present
    Script->>DartApp: Run ten-vad.dart with args
    DartApp->>SherpaONNX: Initialize VAD with ten-vad config
    DartApp->>DartApp: Read input WAV, process in chunks
    DartApp->>SherpaONNX: Feed audio chunks to VAD
    SherpaONNX-->>DartApp: Return detected speech segments
    DartApp->>DartApp: Collect & concatenate speech segments
    DartApp->>DartApp: Write output WAV file
    DartApp->>Script: Print output file info
    Script->>User: Display WAV file details
Loading

Possibly related PRs

  • k2-fsa/sherpa-onnx#2383: Adds support for the "ten-vad" model by extending VAD configurations and native bindings, directly related to this PR's changes.
  • k2-fsa/sherpa-onnx#2384: Adds "ten-vad" support to Go bindings, paralleling this PR's Dart/Flutter integration for the same model.
  • k2-fsa/sherpa-onnx#2379: Adds C API support and examples for "ten-vad", which underpins the Dart/Flutter binding changes in this PR.

Poem

A ten-second VAD, so spry and new,
Dart and Flutter now join the crew!
With configs and scripts, the bunny hops in,
Detecting the speech, let the WAVs begin.
🐰🎤
From code to sound, this leap is rad—
Hooray for the ten-vad!


📜 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 6e20ccc.

📒 Files selected for processing (5)
  • .github/scripts/test-dart.sh (1 hunks)
  • dart-api-examples/vad/bin/ten-vad.dart (1 hunks)
  • dart-api-examples/vad/run-ten-vad.sh (1 hunks)
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart (2 hunks)
  • flutter/sherpa_onnx/lib/src/vad.dart (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: ubuntu-latest
🔇 Additional comments (8)
.github/scripts/test-dart.sh (1)

7-12: LGTM! Good test workflow integration.

The reorganization to run VAD tests earlier and the addition of the new ten-vad script follows the existing pattern and ensures comprehensive testing of both VAD models.

dart-api-examples/vad/run-ten-vad.sh (1)

1-23: LGTM! Well-structured automation script.

The script follows the established pattern for example automation with proper error handling, dependency management, and conditional file downloads.

flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart (2)

490-508: LGTM! Proper FFI struct definition.

The SherpaOnnxTenVadModelConfig struct correctly mirrors the existing SileroVadModelConfig with identical field types and annotations, enabling proper native interop for the ten-vad model.


523-523: Good integration of the new VAD model.

The addition of the tenVad field properly extends the existing VAD configuration structure to support multiple VAD models.

dart-api-examples/vad/bin/ten-vad.dart (1)

9-83: LGTM! Well-implemented VAD example application.

The implementation correctly follows the VAD processing workflow:

  • Proper argument validation and configuration setup
  • Sample rate verification (16kHz requirement)
  • Chunked processing using the configured window size
  • Correct detection and segment extraction logic
  • Proper resource cleanup with vad.free()

The algorithm appropriately handles both real-time detection and final flushing to ensure all speech segments are captured.

flutter/sherpa_onnx/lib/src/vad.dart (3)

52-94: LGTM! Well-structured TenVadModelConfig class.

The implementation correctly mirrors SileroVadModelConfig with appropriate default values. The different windowSize default (256 vs 512) is suitable for the ten-vad model characteristics.


103-103: Good integration of tenVad configuration.

The VadModelConfig class properly incorporates the new tenVad field across constructor, JSON serialization, and string representation.

Also applies to: 117-119, 128-128, 137-137


220-237: Correct native struct configuration and memory management.

The implementation properly configures both VAD models in the native struct and ensures proper memory cleanup by freeing both model pointers.

Also applies to: 251-252

✨ 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.

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

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 “tenVad” voice activity detection model to the Dart and Flutter APIs, updates FFI bindings, and extends the CI and example scripts to exercise the new functionality.

  • Introduces TenVadModelConfig and integrates it into VadModelConfig and VoiceActivityDetector
  • Extends FFI struct bindings to include SherpaOnnxTenVadModelConfig
  • Adds a shell script and CI updates to run the new ten-vad example

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
flutter/sherpa_onnx/lib/src/vad.dart Added TenVadModelConfig, wired it into VadModelConfig, VoiceActivityDetector, and JSON methods
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart Added FFI struct SherpaOnnxTenVadModelConfig and updated SherpaOnnxVadModelConfig binding
dart-api-examples/vad/run-ten-vad.sh New example script to download models/audio and run the ten-vad demo
.github/scripts/test-dart.sh Updated CI script to invoke the ten-vad example alongside existing tests
Comments suppressed due to low confidence (3)

flutter/sherpa_onnx/lib/src/vad.dart:52

  • Consider adding unit tests for TenVadModelConfig.fromJson and toJson to validate serialization and deserialization of each field.
class TenVadModelConfig {

flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart:523

  • The tenVad field is declared after debug, which may not match the native C struct layout. Ensure the Dart FFI struct fields are in the exact same order as the C definition (likely immediately after sileroVad).
  external SherpaOnnxTenVadModelConfig tenVad;

flutter/sherpa_onnx/lib/src/vad.dart:218

  • Wrap native memory allocations and assignments in a try/finally block to ensure all allocated pointers (e.g., modelPtr, tenVadModelPtr) are freed even if an exception occurs.
    final c = calloc<SherpaOnnxVadModelConfig>();

Comment thread flutter/sherpa_onnx/lib/src/vad.dart
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