Skip to content

Add APIs for Online NeMo CTC models - #2454

Merged
csukuangfj merged 12 commits into
k2-fsa:masterfrom
csukuangfj:online-nemo-ctc
Aug 7, 2025
Merged

csukuangfj merged 12 commits into
k2-fsa:masterfrom
csukuangfj:online-nemo-ctc

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Aug 6, 2025 •

Copy link
Copy Markdown
Collaborator

Fixes #2452

CC @yagarwal1307

Summary by CodeRabbit

  • New Features

    • Added support for configuring Nemo CTC models in online speech recognition across multiple platforms and APIs.
    • Introduced new configuration options for Nemo CTC models in user-facing model configuration interfaces.
  • Bug Fixes

    • Improved memory management for model configuration fields to prevent potential leaks.
  • Documentation

    • Enhanced printed output and labels for model configuration details to improve clarity.

@coderabbitai

coderabbitai Bot commented Aug 6, 2025 •

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This change introduces support for the Nemo CTC model configuration in the online recognizer C API and its associated bindings. New structs and fields for Nemo CTC are added across C, C++, C#, Swift, JavaScript (WASM), and Harmony OS layers, enabling initialization, configuration, and memory management of this model type without altering existing logic.

Changes

Cohort / File(s) Change Summary
C API: Structs and Implementation
sherpa-onnx/c-api/c-api.h, sherpa-onnx/c-api/c-api.cc
Added SherpaOnnxOnlineNemoCtcModelConfig struct and nemo_ctc field to SherpaOnnxOnlineModelConfig. Updated config assignment and initialization to support Nemo CTC.
C++ API: Structs and Assignment
sherpa-onnx/c-api/cxx-api.h, sherpa-onnx/c-api/cxx-api.cc
Added OnlineNemoCtcModelConfig struct and nemo_ctc field to OnlineModelConfig; assigned Nemo CTC model in recognizer creation.
WASM/JS API
wasm/asr/sherpa-onnx-asr.js, wasm/asr/sherpa-onnx-wasm-main-asr.cc
Refactored to support nemoCtc config: added initialization, memory management, and selection logic for Nemo CTC model; updated print and static assertions for new struct.
Swift API Example
swift-api-examples/SherpaOnnx.swift
Added function to create Nemo CTC model config; updated online model config to accept Nemo CTC as a parameter and include it in the returned struct.
C#/.NET API
scripts/dotnet/OnlineNemoCtcModelConfig.cs, scripts/dotnet/OnlineModelConfig.cs
Introduced OnlineNemoCtcModelConfig struct; added and initialized NemoCtc field in OnlineModelConfig.
Harmony OS / ETS
harmony-os/SherpaOnnxHar/sherpa_onnx/Index.ets, harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets
Added OnlineNemoCtcModelConfig class; included nemo_ctc property in OnlineModelConfig; updated export list to include new config.
Flutter/Dart API
flutter/sherpa_onnx/lib/src/online_recognizer.dart, flutter/sherpa_onnx/lib/src/keyword_spotter.dart, flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
Added OnlineNemoCtcModelConfig class and field in OnlineModelConfig; integrated native pointer allocation and freeing for nemoCtc.model in recognizer and keyword spotter; extended FFI bindings.
Go API
scripts/go/sherpa_onnx.go
Added OnlineNemoCtcModelConfig struct and field in OnlineModelConfig; updated recognizer and keyword spotter creation to handle Nemo CTC model string conversion and memory management.
Pascal API
sherpa-onnx/pascal-api/sherpa_onnx.pas
Added TSherpaOnnxOnlineNemoCtcModelConfig record and field in TSherpaOnnxOnlineModelConfig; updated recognizer constructor to initialize Nemo CTC model; added corresponding C-style records.
JNI (Java Native Interface)
sherpa-onnx/jni/online-recognizer.cc, sherpa-onnx/jni/keyword-spotter.cc
Refactored JNI code to extract online model config via a new helper function GetOnlineModelConfig that includes Nemo CTC config extraction; replaced inline extraction with function calls.
Miscellaneous
sherpa-onnx/jni/common.h, dotnet-examples/offline-decode-files/run-zipformer-ctc.sh
Minor formatting change in common.h and reduced audio files in shell script; unrelated to Nemo CTC support.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API_Binding (C#/Swift/JS/ETS)
    participant C_API
    participant Internal_Recognizer

    User->>API_Binding: Provide Nemo CTC model config
    API_Binding->>C_API: Initialize OnlineModelConfig with nemo_ctc
    C_API->>Internal_Recognizer: Pass nemo_ctc.model in config
    Internal_Recognizer-->>C_API: Recognizer created with Nemo CTC config
    C_API-->>API_Binding: Return recognizer handle
    API_Binding-->>User: Recognizer ready (Nemo CTC supported)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Add Nemo CTC model support to C API for online recognizer (#2452) ✅
Expose Nemo CTC model config in C API header and implementation (#2452) ✅
Enable initialization and passing of Nemo CTC config in all relevant API bindings (#2452) ✅

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Poem

A bunny hopped through fields of code,
Adding Nemo CTC to lighten the load.
From C to Swift, and JavaScript too,
Now online models know what to do!
With configs aligned and bindings anew,
This rabbit says, “Great job—thank you!”
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 519b686 and 926d7aa.

📒 Files selected for processing (2)
  • .github/scripts/test-nodejs-npm.sh (1 hunks)
  • wasm/kws/sherpa-onnx-kws.js (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/scripts/test-nodejs-npm.sh
🔇 Additional comments (2)
wasm/kws/sherpa-onnx-kws.js (2)

76-77: LGTM! Correct addition of separate CTC model configuration constants.

The separation of CTC model configurations into zipfomer2_ctc_len and nemo_ctc_len allows for independent handling of different CTC model types, which aligns with the PR objective of adding NeMo CTC model support.


79-80: Memory layout consistency confirmed via C++ static_assert.

The C/C++ code in wasm/asr/sherpa-onnx-wasm-main-asr.cc includes:

static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, "");
static_assert(sizeof(SherpaOnnxOnlineNemoCtcModelConfig)    == 1 * 4, "");
static_assert(
  sizeof(SherpaOnnxOnlineModelConfig) ==
    sizeof(SherpaOnnxOnlineTransducerModelConfig) +
    sizeof(SherpaOnnxOnlineParaformerModelConfig) +
    sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 9 * 4 +
    sizeof(SherpaOnnxOnlineNemoCtcModelConfig),
  ""
);

This guarantees at compile time that the JS calculation

transducer.len + paraformer_len + zipfomer2_ctc_len + nemo_ctc_len + 9 * 4

matches the C++ struct layout. No further verification is required.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@yagarwal1307

Copy link
Copy Markdown

One more thing

  • I see we have a support for OnlineWenetCtcModelConfig as well in csrc too. I think it would be great if we fix that right now only. Otherwise will have to raise another pr in the future

@yagarwal1307

Copy link
Copy Markdown

@csukuangfj Also currently im using the xcframework file in releases for it. Any chance I can get that, otherwise Ill have to change my code a lot for testing. Or we can write some sample swift program to test it independently

@csukuangfj

Copy link
Copy Markdown
Collaborator Author

You need to build it from source or wait for our next release.

If you can release a streaming wenet ctc model.with.reasonable accuracy, we can support it. Otherwise, you need to modify the code by yourself.

@yagarwal1307

Copy link
Copy Markdown

That makes sense. Ill try to build for the source then.
(Currently don't have a wenet model and aren't using it as well. I thought the code for it was missing by mistake so suggested the change.)
Thanks a lot for the help 😄!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
sherpa-onnx/pascal-api/sherpa_onnx.pas (1)

1342-1349: Fix casing inconsistency in string formatting.

Line 1343 uses lowercase 'nemoCtc' in the format string while line 1348 uses uppercase 'NemoCtc' for the field reference. For consistency and readability, use the same casing.

Apply this diff to fix the casing:

-    'nemoCtc := %s'),
+    'NemoCtc := %s'),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 915fcc0 and a11070f.

📒 Files selected for processing (11)
  • dotnet-examples/offline-decode-files/run-zipformer-ctc.sh (1 hunks)
  • flutter/sherpa_onnx/lib/src/keyword_spotter.dart (2 hunks)
  • flutter/sherpa_onnx/lib/src/online_recognizer.dart (6 hunks)
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart (2 hunks)
  • scripts/go/sherpa_onnx.go (4 hunks)
  • sherpa-onnx/c-api/c-api.cc (7 hunks)
  • sherpa-onnx/c-api/cxx-api.cc (2 hunks)
  • sherpa-onnx/jni/common.h (1 hunks)
  • sherpa-onnx/jni/keyword-spotter.cc (2 hunks)
  • sherpa-onnx/jni/online-recognizer.cc (2 hunks)
  • sherpa-onnx/pascal-api/sherpa_onnx.pas (7 hunks)
✅ Files skipped from review due to trivial changes (4)
  • sherpa-onnx/jni/common.h
  • dotnet-examples/offline-decode-files/run-zipformer-ctc.sh
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
  • flutter/sherpa_onnx/lib/src/keyword_spotter.dart
🚧 Files skipped from review as they are similar to previous changes (2)
  • sherpa-onnx/c-api/c-api.cc
  • sherpa-onnx/c-api/cxx-api.cc
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: the sherpa-onnx jni library files are stored in hugging face repository at https://huggingface.co/cs...
Learnt from: litongjava
PR: k2-fsa/sherpa-onnx#2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:23:50.237Z
Learning: The sherpa-onnx JNI library files are stored in Hugging Face repository at https://huggingface.co/csukuangfj/sherpa-onnx-libs under versioned directories like jni/1.12.7/, and the actual Windows JNI library filename is "sherpa-onnx-jni.dll" as defined in Core.java constants.

Applied to files:

  • sherpa-onnx/jni/keyword-spotter.cc
  • sherpa-onnx/jni/online-recognizer.cc
📚 Learning: in sherpa-onnx java api, the native library names in core.java (win_native_library_name = "sherpa-on...
Learnt from: litongjava
PR: k2-fsa/sherpa-onnx#2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:18:47.981Z
Learning: In sherpa-onnx Java API, the native library names in Core.java (WIN_NATIVE_LIBRARY_NAME = "sherpa-onnx-jni.dll", UNIX_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.so", MACOS_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.dylib") are copied directly from the compiled binary filenames and should not be changed to match other libraries' naming conventions.

Applied to files:

  • sherpa-onnx/jni/keyword-spotter.cc
  • sherpa-onnx/jni/online-recognizer.cc
⏰ 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). (80)
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
  • GitHub Check: ubuntu-latest
  • GitHub Check: ubuntu-22.04 node v21
  • GitHub Check: ubuntu-22.04 node v18
  • GitHub Check: ubuntu-22.04 node v22
  • GitHub Check: ubuntu-22.04 node v19
  • GitHub Check: ubuntu-24.04-arm
  • GitHub Check: windows-latest
  • GitHub Check: ubuntu-22.04
🔇 Additional comments (20)
scripts/go/sherpa_onnx.go (4)

80-82: LGTM!

The new OnlineNemoCtcModelConfig struct follows the same pattern as existing model configs like OnlineZipformer2CtcModelConfig, maintaining consistency in the codebase.


94-94: LGTM!

The NemoCtc field is correctly added to the OnlineModelConfig struct, maintaining consistency with other model configuration fields.


205-206: LGTM!

The NeMo CTC model configuration handling follows the established CGO pattern with proper memory management using C.CString and defer C.free.


1825-1826: LGTM!

The NeMo CTC model configuration handling in NewKeywordSpotter correctly follows the same pattern as in NewOnlineRecognizer, ensuring consistent API behavior.

sherpa-onnx/jni/keyword-spotter.cc (2)

12-13: LGTM!

The forward declaration for GetOnlineModelConfig properly enables code reuse by referencing the function implemented in online-recognizer.cc, following good C++ practices.


63-63: LGTM!

The refactoring successfully eliminates code duplication by replacing inline JNI model configuration extraction with a call to the centralized GetOnlineModelConfig function, improving maintainability while preserving functionality.

sherpa-onnx/jni/online-recognizer.cc (6)

13-40: LGTM!

The GetOnlineModelConfig function is well-implemented with proper JNI patterns. The transducer configuration extraction correctly uses GetStringUTFChars and ReleaseStringUTFChars for memory management.


41-57: LGTM!

The paraformer configuration extraction maintains consistency with the established JNI pattern, properly handling string conversion and memory cleanup.


59-71: LGTM!

The zipformer2 CTC configuration extraction correctly follows the established pattern with proper JNI field access and memory management.


73-83: LGTM!

The NeMo CTC model configuration extraction is properly implemented, following the same reliable JNI pattern as other model configurations. The field naming follows Java conventions correctly.


85-122: LGTM!

The remaining field extractions properly handle different JNI field types (strings, integers, booleans) with consistent memory management patterns. The provider field is correctly assigned to the nested provider_config.provider structure.


236-236: LGTM!

The refactoring successfully centralizes model configuration extraction into the dedicated GetOnlineModelConfig function, eliminating code duplication and improving maintainability while preserving all functionality.

sherpa-onnx/pascal-api/sherpa_onnx.pas (4)

168-171: LGTM!

The new TSherpaOnnxOnlineNemoCtcModelConfig record definition follows the established pattern of other model configurations in the codebase, with consistent naming and structure.


186-186: LGTM!

The NemoCtc field integration follows the same pattern as other model configuration fields in the record.


1325-1329: LGTM!

The ToString method implementation for TSherpaOnnxOnlineNemoCtcModelConfig is consistent with other similar model configurations.


1447-1447: LGTM!

The NemoCtc model initialization in the constructor correctly converts the Pascal string to PAnsiChar for the C API interface.

flutter/sherpa_onnx/lib/src/online_recognizer.dart (4)

89-108: LGTM!

The OnlineNemoCtcModelConfig class follows the established pattern of other model configuration classes with proper JSON serialization/deserialization and string representation methods.


115-115: LGTM!

The integration of the nemoCtc field into OnlineModelConfig is comprehensive and follows the established patterns for other model configurations, including proper handling in constructor, JSON serialization/deserialization, string representation, and field declaration.

Also applies to: 133-134, 147-147, 154-154, 167-167


363-364: LGTM!

The native memory allocation for the nemoCtc.model field correctly uses toNativeUtf8() and follows the established pattern for other model configurations.


409-409: LGTM!

The memory cleanup for nemoCtc.model is properly implemented and placed in the correct location to prevent memory leaks.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a11070f and 519b686.

📒 Files selected for processing (9)
  • dotnet-examples/offline-decode-files/Program.cs (1 hunks)
  • dotnet-examples/offline-decode-files/run-paraformer-itn.sh (1 hunks)
  • dotnet-examples/offline-decode-files/run-paraformer.sh (1 hunks)
  • go-api-examples/non-streaming-canary-decode-files/go.mod (0 hunks)
  • mfc-examples/NonStreamingSpeechRecognition/NonStreamingSpeechRecognitionDlg.cpp (1 hunks)
  • sherpa-onnx/csrc/rknn/silero-vad-model-rknn.cc (2 hunks)
  • sherpa-onnx/csrc/rknn/silero-vad-model-rknn.h (1 hunks)
  • sherpa-onnx/pascal-api/sherpa_onnx.pas (7 hunks)
  • sherpa-onnx/python/tests/test_offline_recognizer.py (1 hunks)
💤 Files with no reviewable changes (1)
  • go-api-examples/non-streaming-canary-decode-files/go.mod
✅ Files skipped from review due to trivial changes (4)
  • dotnet-examples/offline-decode-files/Program.cs
  • dotnet-examples/offline-decode-files/run-paraformer.sh
  • dotnet-examples/offline-decode-files/run-paraformer-itn.sh
  • mfc-examples/NonStreamingSpeechRecognition/NonStreamingSpeechRecognitionDlg.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • sherpa-onnx/pascal-api/sherpa_onnx.pas
🧰 Additional context used
🧬 Code Graph Analysis (1)
sherpa-onnx/csrc/rknn/silero-vad-model-rknn.h (1)
sherpa-onnx/csrc/rknn/silero-vad-model-rknn.cc (6)
  • Compute (398-400)
  • Compute (398-398)
  • samples (88-158)
  • samples (88-88)
  • samples (178-247)
  • samples (178-178)
🔇 Additional comments (3)
sherpa-onnx/csrc/rknn/silero-vad-model-rknn.h (1)

35-35: Inconsistent with PR objectives.

This change adds a Compute method to the Silero VAD model, but the PR is supposed to be about adding APIs for Online NeMo CTC models. This appears to be an unrelated change that should either be in a separate PR or the PR description should be updated to reflect the broader scope.

Likely an incorrect or invalid review comment.

sherpa-onnx/csrc/rknn/silero-vad-model-rknn.cc (2)

178-247: LGTM - Method relocation without logic changes.

The Run method has been relocated within the Impl class but the logic remains unchanged. The implementation correctly handles RKNN tensor setup, model execution, and result extraction.


398-400: LGTM - Clean delegation to internal implementation.

The Compute method provides a clean public interface by delegating to the internal Run method. The implementation is straightforward and consistent with the class design pattern.

Comment thread sherpa-onnx/python/tests/test_offline_recognizer.py
Comment thread sherpa-onnx/python/tests/test_offline_recognizer.py
Comment thread sherpa-onnx/python/tests/test_offline_recognizer.py
@csukuangfj
csukuangfj requested a review from Copilot August 7, 2025 01:06

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 Online NeMo CTC models across multiple platforms and APIs within the sherpa-onnx speech recognition framework. The changes introduce configuration structures and supporting code to handle NeMo CTC models alongside existing transducer, paraformer, and zipformer2 CTC model types.

Key changes include:

  • Addition of OnlineNemoCtcModelConfig structures across all language bindings and platforms
  • Integration of NeMo CTC configuration into existing online model configuration workflows
  • Updates to memory management and serialization routines to handle the new model type

Reviewed Changes

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

Show a summary per file
File Description
wasm/asr/sherpa-onnx-wasm-main-asr.cc Adds static assertion and printing support for NeMo CTC configuration
wasm/asr/sherpa-onnx-asr.js Implements JavaScript bindings and memory management for NeMo CTC models
swift-api-examples/SherpaOnnx.swift Adds Swift API support for NeMo CTC model configuration
sherpa-onnx/jni/online-recognizer.cc Refactors JNI code and adds NeMo CTC field extraction
sherpa-onnx/pascal-api/sherpa_onnx.pas Implements Pascal API structures and methods for NeMo CTC
sherpa-onnx/c-api/c-api.h Defines C API structures for NeMo CTC configuration
scripts/go/sherpa_onnx.go Adds Go language bindings for NeMo CTC models
scripts/dotnet/OnlineNemoCtcModelConfig.cs Creates .NET configuration class for NeMo CTC models
flutter/sherpa_onnx/lib/src/online_recognizer.dart Implements Flutter/Dart support for NeMo CTC configuration
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/StreamingAsr.ets Adds HarmonyOS TypeScript bindings for NeMo CTC


if ('ctc' in config) {
freeConfig(config.ctc, Module)
if ('zipformer2Ctc' in config) {

Copilot AI Aug 7, 2025

Copy link

Choose a reason for hiding this comment

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

The removed 'ctc' property check suggests this was renamed to 'zipformer2Ctc'. Ensure all references to the old 'ctc' property have been updated throughout the codebase to maintain consistency.

Copilot uses AI. Check for mistakes.
Comment on lines 305 to +310
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
offset += 4;

Module._CopyHeap(nemoCtc.ptr, nemoCtc.len, ptr + offset);
offset += nemoCtc.len;

Copilot AI Aug 7, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The nemoCtc configuration is copied after all other fields including tokensBufSize. This placement differs from the pattern where model configs are grouped together earlier in the structure. Consider moving this copy operation to be with other model configurations for better code organization.

Suggested change
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
offset += 4;
Module._CopyHeap(nemoCtc.ptr, nemoCtc.len, ptr + offset);
offset += nemoCtc.len;
Module._CopyHeap(nemoCtc.ptr, nemoCtc.len, ptr + offset);
offset += nemoCtc.len;
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
offset += 4;

Copilot uses AI. Check for mistakes.
@csukuangfj
csukuangfj merged commit 8ab5cba into k2-fsa:master Aug 7, 2025
@csukuangfj
csukuangfj deleted the online-nemo-ctc branch August 7, 2025 01:28
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.

C-api doesn't support nemo ctc for online recognizer

3 participants