Repository navigation
Add JavaScript API (WebAssembly) for Moonshine v2 models - #3241
Conversation
Summary of ChangesHello, 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 expands the Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
📝 WalkthroughWalkthroughAdds Moonshine v2 mergedDecoder support to WASM bindings, a Node.js offline test and docs, and CI steps to download/extract/run Moonshine v2 (and FireRedASR CTC) offline tests; also tightens several example scripts' variable declarations. Changes
Sequence Diagram(s)sequenceDiagram
participant CI as CI Script
participant Host as Model Host (releases)
participant Runner as Node.js Runner
participant WASM as sherpa-onnx WASM
participant FS as Local FS/WAV
CI->>Host: download Moonshine v2 model archive
Host-->>CI: tar.gz
CI->>FS: extract model files
CI->>Runner: run test-offline-moonshine-v2.js
Runner->>WASM: load model files (encoder, mergedDecoder, tokens)
Runner->>FS: read test WAV
Runner->>WASM: feed waveform -> decode
WASM-->>Runner: decoded text
Runner-->>CI: exit (log output)
CI->>FS: cleanup extracted files
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request adds JavaScript API support for Moonshine v2 models, including a new test example and updates to the build/test scripts. The changes look good overall. I've provided a few suggestions to improve the new test script and example code by using constants/variables for repeated strings and fixing variable declarations. These changes will enhance maintainability and code quality.
| recognizer = createOfflineRecognizer(); | ||
| stream = recognizer.createStream(); |
There was a problem hiding this comment.
Variables recognizer and stream are being assigned without being declared with var, let, or const. This makes them global variables, which is generally considered bad practice. You should declare them with const since they are not reassigned.
| recognizer = createOfflineRecognizer(); | |
| stream = recognizer.createStream(); | |
| const recognizer = createOfflineRecognizer(); | |
| const stream = recognizer.createStream(); |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | ||
| tar xvf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | ||
| rm sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | ||
|
|
||
| node ./test-offline-moonshine-v2.js | ||
|
|
||
| rm -rf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27 |
There was a problem hiding this comment.
To improve maintainability and reduce the chance of typos, you can store the model name in a variable and reuse it.
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | |
| tar xvf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | |
| rm sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | |
| node ./test-offline-moonshine-v2.js | |
| rm -rf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27 | |
| MODEL_NAME="sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27" | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${MODEL_NAME}.tar.bz2 | |
| tar xvf ${MODEL_NAME}.tar.bz2 | |
| rm ${MODEL_NAME}.tar.bz2 | |
| node ./test-offline-moonshine-v2.js | |
| rm -rf ${MODEL_NAME} |
| wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | ||
| tar xvf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | ||
| rm sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | ||
|
|
||
| node ./test-offline-moonshine-v2.js |
There was a problem hiding this comment.
To make the script easier to read and maintain, consider using a variable for the model name.
| wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | |
| tar xvf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | |
| rm sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27.tar.bz2 | |
| node ./test-offline-moonshine-v2.js | |
| MODEL_NAME="sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27" | |
| wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${MODEL_NAME}.tar.bz2 | |
| tar xvf ${MODEL_NAME}.tar.bz2 | |
| rm ${MODEL_NAME}.tar.bz2 | |
| node ./test-offline-moonshine-v2.js |
| let modelConfig = { | ||
| moonshine: { | ||
| encoder: | ||
| './sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27/encoder_model.ort', |
There was a problem hiding this comment.
The model directory path './sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27' is repeated in this file (lines 9, 11, 13, 27). It would be better to define it as a constant at the top of the file to improve maintainability and avoid potential typos. For example: const modelDir = './sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27'; and then use it like ${modelDir}/encoder_model.ort.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
nodejs-examples/test-offline-moonshine-v2.js (1)
23-24: Addconstdeclarations to avoid implicit globals.The
recognizerandstreamvariables are assigned withoutconstorlet, creating implicit global variables. This works but is not best practice.Suggested fix
-recognizer = createOfflineRecognizer(); -stream = recognizer.createStream(); +const recognizer = createOfflineRecognizer(); +const stream = recognizer.createStream();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nodejs-examples/test-offline-moonshine-v2.js` around lines 23 - 24, The variables recognizer and stream are being assigned without declarations, creating implicit globals; update the code where createOfflineRecognizer() and recognizer.createStream() are called to declare them with const (e.g., const recognizer = createOfflineRecognizer(); const stream = recognizer.createStream();) so they become local constants and avoid polluting the global scope.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@nodejs-examples/test-offline-moonshine-v2.js`:
- Around line 23-24: The variables recognizer and stream are being assigned
without declarations, creating implicit globals; update the code where
createOfflineRecognizer() and recognizer.createStream() are called to declare
them with const (e.g., const recognizer = createOfflineRecognizer(); const
stream = recognizer.createStream();) so they become local constants and avoid
polluting the global scope.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.github/scripts/test-nodejs-npm.shnodejs-examples/README.mdnodejs-examples/test-offline-moonshine-v2.jswasm/asr/sherpa-onnx-asr.jswasm/nodejs/sherpa-onnx-wasm-nodejs.cc
There was a problem hiding this comment.
Pull request overview
Adds WebAssembly/JavaScript surface support for Moonshine v2 offline decoding by wiring the new merged_decoder field through the WASM config plumbing and providing a Node.js example + CI exercise.
Changes:
- Extend Moonshine offline model config in WASM Node.js glue and JS initializer to include
mergedDecoder/merged_decoder. - Add a Node.js example for Moonshine v2 merged-decoder usage and document how to run it.
- Update the Node.js npm CI script to download a Moonshine v2 model and run the new example.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wasm/nodejs/sherpa-onnx-wasm-nodejs.cc | Updates struct size assertion and prints merged_decoder in offline recognizer config dump. |
| wasm/asr/sherpa-onnx-asr.js | Adds mergedDecoder allocation/packing into the WASM Moonshine config and default config field. |
| nodejs-examples/test-offline-moonshine-v2.js | New Node.js example showing Moonshine v2 decoding using encoder + mergedDecoder. |
| nodejs-examples/README.md | Documents how to download the Moonshine v2 model and run the new example. |
| .github/scripts/test-nodejs-npm.sh | CI coverage: downloads Moonshine v2 model, runs the new example, and cleans up. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| recognizer = createOfflineRecognizer(); | ||
| stream = recognizer.createStream(); |
There was a problem hiding this comment.
recognizer and stream are assigned without const/let, which creates implicit globals in non-strict mode (and will throw in strict mode). Declare them (e.g., const recognizer = ..., const stream = ...) to avoid polluting the global scope and to keep the example robust across runtimes/tooling.
| recognizer = createOfflineRecognizer(); | |
| stream = recognizer.createStream(); | |
| const recognizer = createOfflineRecognizer(); | |
| const stream = recognizer.createStream(); |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
nodejs-examples/test-online-paraformer-microphone-mic.js (2)
2-4: Minor: Line-wrapped require statement looks unusual.While functionally correct, the line-wrapped
require('mic')with the trailing comment spanning multiple lines is unconventional. Consider keeping the require on a single line with the comment on a separate line for better readability.📝 Suggested format
-const mic = require( - 'mic'); // It uses `mic` for better compatibility, do check its - // [npm](https://www.npmjs.com/package/mic) before running it. +// It uses `mic` for better compatibility, do check its +// npm page (https://www.npmjs.com/package/mic) before running it. +const mic = require('mic');🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nodejs-examples/test-online-paraformer-microphone-mic.js` around lines 2 - 4, The require call for the mic module is line-wrapped and the long trailing comment reduces readability; change the statement that assigns the mic variable so it uses a single-line require (mic = require('mic')) and move the explanatory npm comment to its own preceding line so the require remains concise and the comment stays clear; update the occurrence that sets const mic to use this single-line form and separate the comment above it.
80-91: Consider using English comments for consistency.The file mixes English and Chinese comments (e.g.,
显示历史句子,显示当前正在识别的内容). For consistency with the rest of the codebase and to aid contributors who may not read Chinese, consider translating these to English.📝 Suggested translation
- // 显示历史句子 + // Display past sentences if (currentSession.sentences.length > 0) { console.log('Recognized Sentences:'); currentSession.sentences.forEach((sentence, index) => { console.log(`[${sentence.timestamp}] ${index + 1}. ${sentence.text}`); }); console.log('------------------------'); } - // 显示当前正在识别的内容 + // Display currently recognizing content if (currentSession.currentText) { console.log('Recognizing:', currentSession.currentText); }Also at line 120:
- debug: false, // 关闭调试输出 + debug: false, // Disable debug outputAnd at line 164:
- // 检查是否需要开始新会话 + // Check if we need to start a new session🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nodejs-examples/test-online-paraformer-microphone-mic.js` around lines 80 - 91, Replace Chinese inline comments with English equivalents for consistency: change the comment above the currentSession.sentences block (originally "显示历史句子") to an English comment like "Display recognized sentences" and change the comment before currentSession.currentText (originally "显示当前正在识别的内容") to "Display currently recognizing text"; also scan this file for other Chinese comments (e.g., other comments near currentSession usage) and translate them to English so all comments are consistently in English.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@nodejs-examples/test-online-paraformer-microphone-mic.js`:
- Around line 2-4: The require call for the mic module is line-wrapped and the
long trailing comment reduces readability; change the statement that assigns the
mic variable so it uses a single-line require (mic = require('mic')) and move
the explanatory npm comment to its own preceding line so the require remains
concise and the comment stays clear; update the occurrence that sets const mic
to use this single-line form and separate the comment above it.
- Around line 80-91: Replace Chinese inline comments with English equivalents
for consistency: change the comment above the currentSession.sentences block
(originally "显示历史句子") to an English comment like "Display recognized sentences"
and change the comment before currentSession.currentText (originally
"显示当前正在识别的内容") to "Display currently recognizing text"; also scan this file for
other Chinese comments (e.g., other comments near currentSession usage) and
translate them to English so all comments are consistently in English.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
nodejs-examples/test-offline-fire-red-asr.jsnodejs-examples/test-offline-moonshine-v2.jsnodejs-examples/test-offline-moonshine.jsnodejs-examples/test-offline-speech-enhancement-gtcrn.jsnodejs-examples/test-offline-whisper.jsnodejs-examples/test-online-paraformer-microphone-mic.js
🚧 Files skipped from review as they are similar to previous changes (1)
- nodejs-examples/test-offline-moonshine-v2.js
Summary by CodeRabbit
New Features
Documentation
Tests
Style