Repository navigation
Add JavaScript API (node-addon) for Moonshine v2 models - #3242
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 significantly enhances the Node.js addon by integrating comprehensive support for Moonshine v2 automatic speech recognition models. It provides developers with a new JavaScript API to leverage these models for non-streaming ASR, accompanied by a practical example and robust automated testing to validate the new functionality. 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
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR adds Moonshine v2 ASR model support to sherpa-onnx by introducing a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 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 support for Moonshine v2 models to the Node.js addon, including updates to the C++ implementation, a new JavaScript example, documentation changes, and a new CI test case. The changes are well-structured and follow existing patterns. I have a few suggestions to improve code maintainability in the test script, documentation, and the new example file by reducing code repetition and using const where appropriate.
| echo "----------Moonshine v2----------" | ||
| 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_asr_non_streaming_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 repetition, consider using a variable for the model name. This makes it easier to update the model version in the future.
| echo "----------Moonshine v2----------" | |
| 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_asr_non_streaming_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" | |
| echo "----------Moonshine v2----------" | |
| 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_asr_non_streaming_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_asr_non_streaming_moonshine_v2.js |
There was a problem hiding this comment.
For better readability and maintainability, consider using a variable for the model name. Also, using curl -SL -O instead of wget would be more consistent with the CI test script (.github/scripts/test-nodejs-addon-npm.sh).
| 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_asr_non_streaming_moonshine_v2.js | |
| 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_asr_non_streaming_moonshine_v2.js |
|
|
||
| // Please download test files from | ||
| // https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models | ||
| const config = { |
| let start = Date.now(); | ||
| const stream = recognizer.createStream(); | ||
| const wave = sherpa_onnx.readWave(waveFilename); | ||
| stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples}); | ||
|
|
||
| recognizer.decode(stream); | ||
| const result = recognizer.getResult(stream); | ||
| let stop = Date.now(); |
There was a problem hiding this comment.
The variables start and stop are not reassigned. It's a good practice to declare them with const to enforce immutability.
| let start = Date.now(); | |
| const stream = recognizer.createStream(); | |
| const wave = sherpa_onnx.readWave(waveFilename); | |
| stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples}); | |
| recognizer.decode(stream); | |
| const result = recognizer.getResult(stream); | |
| let stop = Date.now(); | |
| const start = Date.now(); | |
| const stream = recognizer.createStream(); | |
| const wave = sherpa_onnx.readWave(waveFilename); | |
| stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples}); | |
| recognizer.decode(stream); | |
| const result = recognizer.getResult(stream); | |
| const stop = Date.now(); |
There was a problem hiding this comment.
Pull request overview
Adds a Node.js addon example and CI coverage for running Offline ASR with Moonshine v2 models, and updates the HarmonyOS N-API config parser to support the Moonshine v2 mergedDecoder field.
Changes:
- Add a new Node.js example script for Moonshine v2 offline (non-streaming) ASR.
- Document the new example in
nodejs-addon-examples/README.md. - Extend CI script to download a Moonshine v2 model bundle and run the new example.
- Update HarmonyOS non-streaming ASR config parsing and cleanup to include
mergedDecoder/merged_decoder.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| nodejs-addon-examples/test_asr_non_streaming_moonshine_v2.js | New Moonshine v2 offline ASR example using encoder + mergedDecoder. |
| nodejs-addon-examples/README.md | Lists the new example and adds run instructions for Moonshine v2. |
| harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-asr.cc | Adds parsing and freeing of Moonshine v2 mergedDecoder configuration. |
| .github/scripts/test-nodejs-addon-npm.sh | Downloads Moonshine v2 model tarball and runs the new Node.js example in CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo "----------Moonshine v2----------" | ||
| 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_asr_non_streaming_moonshine_v2.js | ||
|
|
||
| rm -rf sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27 |
There was a problem hiding this comment.
This script downloads and extracts a third-party tarball into the repo root and then runs node ./test_asr_non_streaming_moonshine_v2.js, which can be overwritten by files contained in the archive. If an attacker ever gains control over the release asset at this URL, they can ship a test_asr_non_streaming_moonshine_v2.js (or similar executable) inside the tarball, have it overwrite the local script during tar xvf, and achieve arbitrary code execution in CI with access to repository secrets. To mitigate this, pin downloads to immutable, integrity-checked artifacts, extract into a dedicated directory and only use expected model files, and ensure downloaded archives cannot overwrite scripts that are subsequently executed.
Summary by CodeRabbit
New Features
Documentation
Tests