Skip to content

Add JavaScript API (WebAssembly) for Google MedAsr model - #2954

Merged
csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:javascript-wasm-medasr
Dec 29, 2025
Merged

csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:javascript-wasm-medasr

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Dec 29, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for MedASR CTC model, enabling offline speech-to-text recognition capabilities.
  • Tests

    • Introduced test scripts demonstrating MedASR model decoding with sample audio files.
  • Documentation

    • Updated guides with MedASR model setup instructions and execution examples.

✏️ Tip: You can customize this high-level summary in your review settings.

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

coderabbitai Bot commented Dec 29, 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

Walkthrough

Adds support for MedASR (Medical Speech Recognition) CTC models to sherpa-onnx by introducing a new Node.js test script for offline MedASR decoding, corresponding documentation, and WASM/JavaScript configuration structures with memory handling. CI tests are extended to validate MedASR and other model scenarios. A lexicon entry is removed from the TTS test configuration.

Changes

Cohort / File(s) Summary
CI & Test Scripts
.github/scripts/test-nodejs-npm.sh
Extended test workflow to download, extract, and run tests for MedASR CTC int8 model and omnilingual 1600-language CTC model, with cleanup steps for both scenarios.
Node.js Examples
nodejs-examples/test-offline-medasr-ctc.js
New offline MedASR recognizer test script that configures a MedASR CTC int8 model, reads WAV input, performs decoding, and outputs recognized text.
Documentation
nodejs-examples/README.md
Added documentation sections describing MedASR CTC model decoding workflow, including model tarball reference and example run commands.
TTS Configuration
nodejs-examples/test-offline-tts-matcha-en.js
Removed unused lexicon configuration entry from offline TTS Matcha model setup.
WASM ASR Config
wasm/asr/sherpa-onnx-asr.js
Introduced initSherpaOnnxOfflineMedAsrCtcModelConfig() function and extended offline model configuration pipeline to handle MedASR memory allocation, heap sizing, and config object composition.
WASM Node.js Binding
wasm/nodejs/sherpa-onnx-wasm-nodejs.cc
Added static_assert validation for SherpaOnnxOfflineMedAsrCtcModelConfig size and integrated MedASR config output to PrintOfflineRecognizerConfig.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through medical speech,
MedASR models now within reach,
WASM configs dance with careful care,
Tests validated, warnings laid bare,
Recognition flows, healing's made fair! 🏥✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding JavaScript/WebAssembly API support for Google MedAsr model, which is evident from the new files (test-offline-medasr-ctc.js), WASM bindings (sherpa-onnx-asr.js), C++ integration (sherpa-onnx-wasm-nodejs.cc), and documentation updates.
✨ 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: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13b8b84 and 462425d.

📒 Files selected for processing (6)
  • .github/scripts/test-nodejs-npm.sh
  • nodejs-examples/README.md
  • nodejs-examples/test-offline-medasr-ctc.js
  • nodejs-examples/test-offline-tts-matcha-en.js
  • wasm/asr/sherpa-onnx-asr.js
  • wasm/nodejs/sherpa-onnx-wasm-nodejs.cc
💤 Files with no reviewable changes (1)
  • nodejs-examples/test-offline-tts-matcha-en.js
🧰 Additional context used
🧬 Code graph analysis (2)
wasm/asr/sherpa-onnx-asr.js (1)
nodejs-examples/test-offline-medasr-ctc.js (1)
  • config (10-17)
wasm/nodejs/sherpa-onnx-wasm-nodejs.cc (1)
wasm/asr/sherpa-onnx-asr.js (1)
  • medasr (1169-1170)

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 the Google MedAsr model. This addition allows developers to leverage the MedAsr model for offline speech recognition directly within Node.js applications. The changes encompass the necessary configuration handling, a practical usage example, and updates to the automated testing pipeline to ensure robustness.

Highlights

  • Google MedAsr Model Support: Introduced a new JavaScript (WebAssembly) API for the Google MedAsr model, enabling its use within Node.js environments.
  • New Node.js Example: Added a new Node.js example, test-offline-medasr-ctc.js, demonstrating how to perform offline speech recognition using the MedAsr CTC model.
  • CI Script Update: The CI script for Node.js NPM tests has been updated to include downloading, testing, and cleaning up the MedAsr model, ensuring continuous validation of the new functionality.
  • WebAssembly Configuration Integration: Modified the core WebAssembly JavaScript and C++ files to properly handle the configuration and memory management for the new MedAsr model.
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 JavaScript API support for the Google MedASR model, including a new Node.js example, updates to the CI test script, and necessary changes to the WebAssembly bindings. The implementation is consistent with the existing codebase structure. My review includes a couple of suggestions for improving script efficiency and code cleanliness in the new example file. Overall, the changes look good.

Comment on lines +12 to +14
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2
tar xvf sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2
rm sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2

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

For efficiency and simplicity, you can download and extract the model in a single command by piping curl to tar. This avoids writing the compressed archive to disk.

Suggested change
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2
tar xvf sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2
rm sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2
curl -SL https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-medasr-ctc-en-int8-2025-12-25.tar.bz2 | tar xvjf -

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

These modules (fs, Readable from stream, and wav) are imported but not used in this file. It's good practice to remove unused imports to keep the code clean and reduce the module's dependency footprint.

@csukuangfj
csukuangfj merged commit a53d9ee into k2-fsa:master Dec 29, 2025
1 check passed
@csukuangfj
csukuangfj deleted the javascript-wasm-medasr branch December 29, 2025 04:50
@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