Skip to content

Add JavaScript (WebAssembly) API for Omnilingual ASR CTC models - #2781

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:wasm-omnilingual
Nov 13, 2025
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:wasm-omnilingual

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Nov 13, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for omnilingual ASR CTC model enabling offline speech recognition across multiple languages.
  • Tests

    • Expanded test infrastructure with comprehensive scenarios for omnilingual ASR, keyword spotting, VAD, speech enhancement, and TTS models.
  • Documentation

    • Updated guides with setup instructions and execution steps for omnilingual ASR model testing.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 13, 2025
@coderabbitai

coderabbitai Bot commented Nov 13, 2025 •

Copy link
Copy Markdown

Walkthrough

This pull request adds Omnilingual ASR CTC model support to Sherpa-ONNX across multiple layers. Changes include a new Node.js example script, updated test automation, WASM configuration handling, and C++ binding updates to support the omnilingual model configuration alongside existing ASR models.

Changes

Cohort / File(s) Summary
Test and Documentation
.github/scripts/test-nodejs-npm.sh, nodejs-examples/README.md
Added model download and test execution automation for omnilingual ASR CTC and other models; documented the new test case with download links and execution commands.
New Example
nodejs-examples/test-offline-omnilingual-asr-ctc.js
New Node.js example script demonstrating offline omnilingual ASR CTC model usage: creates recognizer, loads WAV audio, performs decoding, outputs results, and frees resources.
WASM JavaScript Layer
wasm/asr/sherpa-onnx-asr.js
Added omnilingual ASR CTC model configuration support: new initialization function, updated offline model config to include omnilingual field with memory layout and buffer management.
WASM C++ Binding
wasm/nodejs/sherpa-onnx-wasm-nodejs.cc
Added size assertion for omnilingual ASR CTC config and extended offline model configuration to include omnilingual field with debug output support.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant JS as sherpa-onnx-asr.js
    participant Config as Model Config
    participant WASM as WASM Module
    
    App->>JS: initSherpaOnnxOfflineModelConfig(config)
    JS->>Config: Create omnilingual config
    Config-->>JS: omnilingual object
    JS->>WASM: Allocate memory buffer
    WASM-->>JS: Buffer with all model configs
    JS->>JS: Copy omnilingual data to buffer
    JS-->>App: Return config with omnilingual field
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Memory layout integration: Review wasm/asr/sherpa-onnx-asr.js to verify omnilingual config is correctly sized and positioned within the buffer alongside other model configs
  • Cross-layer consistency: Verify C++ binding wasm/nodejs/sherpa-onnx-wasm-nodejs.cc correctly reflects the JavaScript memory layout changes and size calculations
  • Integration points: Confirm freeConfig() properly cleans up omnilingual resources and initialization follows established patterns
  • Test coverage: Validate that test-offline-omnilingual-asr-ctc.js matches the pattern of existing ASR examples and uses correct model paths

Possibly related PRs

Suggested labels

size:M

Poem

🐰 A hopping update, swift and neat,
Omnilingual models now compete!
From WASM layers to Node.js test,
Sherpa-ONNX puts ASR to the quest—
Carrots of code make features complete! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding JavaScript/WebAssembly API support for Omnilingual ASR CTC models, which is reflected across all modified files including new test scripts, documentation, and WASM implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 634f4fd and f498fbd.

📒 Files selected for processing (5)
  • .github/scripts/test-nodejs-npm.sh (1 hunks)
  • nodejs-examples/README.md (1 hunks)
  • nodejs-examples/test-offline-omnilingual-asr-ctc.js (1 hunks)
  • wasm/asr/sherpa-onnx-asr.js (5 hunks)
  • wasm/nodejs/sherpa-onnx-wasm-nodejs.cc (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
wasm/nodejs/sherpa-onnx-wasm-nodejs.cc (1)
wasm/asr/sherpa-onnx-asr.js (1)
  • omnilingual (1139-1140)
wasm/asr/sherpa-onnx-asr.js (2)
nodejs-examples/test-offline-omnilingual-asr-ctc.js (1)
  • config (10-19)
sherpa-onnx/kotlin-api/OfflineRecognizer.kt (1)
  • transducer (77-97)
🔇 Additional comments (11)
wasm/nodejs/sherpa-onnx-wasm-nodejs.cc (3)

18-18: LGTM! Size assertion is correct.

The static_assert correctly validates that the omnilingual config contains a single pointer (4 bytes), consistent with other CTC model configs like Dolphin, Zipformer, and WeNet.


29-44: LGTM! Aggregate size calculation is correct.

The omnilingual config size is properly integrated into the total SherpaOnnxOfflineModelConfig size calculation, maintaining consistency with the memory layout.


76-147: LGTM! Configuration printing is consistent.

The omnilingual pointer declaration and print statements follow the established pattern used for other model configurations in this function.

nodejs-examples/README.md (2)

206-220: LGTM! Documentation follows established patterns.

The new omnilingual ASR test documentation is well-structured and consistent with other test sections in the README.


225-225: Good catch on the typo fix.

Correcting "Wenet" to "WeNet" aligns with the proper capitalization of the project name.

nodejs-examples/test-offline-omnilingual-asr-ctc.js (1)

1-37: LGTM! Test implementation is solid.

The test script correctly demonstrates omnilingual ASR CTC model usage, following established patterns from other offline recognizer tests. Configuration structure, resource management, and execution flow are all appropriate.

.github/scripts/test-nodejs-npm.sh (1)

12-18: LGTM! Test automation follows established patterns.

The omnilingual model download, test execution, and cleanup workflow is consistent with other model tests in this script. Proper resource cleanup is maintained.

wasm/asr/sherpa-onnx-asr.js (4)

58-60: LGTM! Memory cleanup is properly integrated.

The omnilingual config is correctly added to the recursive freeConfig function, ensuring proper memory deallocation.


762-777: LGTM! Init function follows established pattern.

The initSherpaOnnxOfflineOmnilingualAsrCtcModelConfig function correctly implements the same pattern as other single-pointer model configs (WenetCtc, ZipformerCtc, Dolphin, etc.).


1049-1053: LGTM! Default config initialization is correct.

The default omnilingual configuration follows the same pattern as other model configs, with an empty string default for the model path.


1139-1145: LGTM! Model config integration is complete and correct.

The omnilingual configuration is properly initialized, its size is included in the total length calculation, memory is correctly copied with proper offset tracking, and it's exposed in the returned object for resource management.

Also applies to: 1256-1257, 1264-1264


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @csukuangfj, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the capabilities of the JavaScript (WebAssembly) API by integrating support for Omnilingual ASR CTC models. This enhancement allows developers to perform offline speech recognition across a wide range of languages directly within Node.js environments, complete with a new example and updated testing infrastructure to ensure functionality.

Highlights

  • Omnilingual ASR CTC Model Support: Introduced JavaScript (WebAssembly) API support for Omnilingual ASR CTC models, enabling broader language coverage for speech recognition.
  • New Example Script: Added a new Node.js example script, test-offline-omnilingual-asr-ctc.js, to demonstrate how to use the new API for offline speech recognition.
  • Build System Integration: Updated the CI/CD test script (.github/scripts/test-nodejs-npm.sh) to automatically download, test, and clean up the Omnilingual ASR model, ensuring its functionality.
  • Documentation Update: The nodejs-examples/README.md file was updated to include clear instructions for running the new Omnilingual ASR example.
  • WASM API Enhancements: Modified the core WebAssembly API (wasm/asr/sherpa-onnx-asr.js and wasm/nodejs/sherpa-onnx-wasm-nodejs.cc) to correctly handle memory management and configuration for the new Omnilingual ASR models.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds support for Omnilingual ASR CTC models to the JavaScript/WebAssembly API. The changes are well-structured and consistently follow the existing patterns in the codebase, including updates to the test scripts, documentation, and the core JavaScript wrapper. My review includes a few suggestions to improve code maintainability and documentation clarity, such as using variables for long repeated filenames and removing unused code.

Comment on lines +12 to +18
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
tar xvf sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
rm sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2

node ./test-offline-omnilingual-asr-ctc.js

rm -rf sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The script repeats a long model filename and directory name, which makes it harder to read and maintain. Using a variable for these repeated strings would make the script cleaner and less error-prone. Additionally, the v flag in tar xvf is verbose for CI logs; xf is generally sufficient.

Suggested change
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
tar xvf sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
rm sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
node ./test-offline-omnilingual-asr-ctc.js
rm -rf sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12
MODEL_NAME="sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12"
curl -SL -O "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${MODEL_NAME}.tar.bz2"
tar xf "${MODEL_NAME}.tar.bz2"
rm "${MODEL_NAME}.tar.bz2"
node ./test-offline-omnilingual-asr-ctc.js
rm -rf "${MODEL_NAME}"

Comment thread nodejs-examples/README.md
## ./test-offline-omnilingual-asr-ctc.js

[./test-offline-omnilingual-asr-ctc.js](./test-offline-omnilingual-asr-ctc.js) demonstrates
how to decode a file with a Omnilingual ASR CTC model. In the code we use

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

There is a minor grammatical error. It should be "an Omnilingual" instead of "a Omnilingual".

Suggested change
how to decode a file with a Omnilingual ASR CTC model. In the code we use
how to decode a file with an Omnilingual ASR CTC model. In the code we use

Comment thread nodejs-examples/README.md
Comment on lines +215 to +219
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
tar xvf sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
rm sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2

node ./test-offline-omnilingual-asr-ctc.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The example commands repeat a very long filename, which can be hard to read and is prone to typos. Using a shell variable would make the example clearer and easier for users to adapt. Also, tar xvf is verbose; xf is sufficient.

Suggested change
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
tar xvf sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
rm sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12.tar.bz2
node ./test-offline-omnilingual-asr-ctc.js
MODEL_NAME="sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12"
wget "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${MODEL_NAME}.tar.bz2"
tar xf "${MODEL_NAME}.tar.bz2"
rm "${MODEL_NAME}.tar.bz2"
node ./test-offline-omnilingual-asr-ctc.js

Comment on lines +3 to +5
const fs = require('fs');
const {Readable} = require('stream');
const wav = require('wav');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The modules fs, stream (Readable), and wav are imported but are not used in this file. These unused imports should be removed to keep the code clean.

modelConfig: {
omnilingual: {
model:
'./sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12/model.int8.onnx',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The directory path './sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12' is hardcoded here and in other places in the file (lines 17 and 28). To improve maintainability, consider defining this path as a constant at the top of the file and reusing it. For example: const modelDir = './sherpa-onnx-omnilingual-asr-1600-languages-300M-ctc-int8-2025-11-12';

@csukuangfj
csukuangfj merged commit 7e71363 into k2-fsa:master Nov 13, 2025
1 of 2 checks passed
@csukuangfj
csukuangfj deleted the wasm-omnilingual branch November 13, 2025 10:12
@coderabbitai coderabbitai Bot mentioned this pull request Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant