Skip to content

Add JavaScript API (node-addon) for Moonshine v2 models - #3242

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:javascript-node-addon-moonshine-v2
Feb 28, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:javascript-node-addon-moonshine-v2

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Feb 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added Moonshine v2 model support for non-streaming automatic speech recognition with new configuration field for model decoder paths
  • Documentation

    • Added Moonshine v2 usage examples and step-by-step setup instructions
  • Tests

    • Added automated test flow and Node.js example for Moonshine v2 speech recognition

@csukuangfj
csukuangfj requested a review from Copilot February 28, 2026 04:13
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 28, 2026
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • Moonshine v2 Model Support: Enabled support for Moonshine v2 automatic speech recognition models within the Node.js addon, allowing for their use in non-streaming ASR tasks.
  • New JavaScript Example: Introduced a new JavaScript example (test_asr_non_streaming_moonshine_v2.js) to demonstrate how to perform non-streaming ASR using Moonshine v2 models.
  • Automated Testing Integration: Updated the CI/CD test script to include automated downloading, testing, and cleanup for Moonshine v2 models, ensuring the new API works as expected.
Changelog
  • .github/scripts/test-nodejs-addon-npm.sh
    • Added steps to download, extract, run, and clean up Moonshine v2 ASR models for automated testing.
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-asr.cc
    • Integrated the merged_decoder configuration for Moonshine v2 models.
    • Ensured proper memory deallocation for the newly added merged_decoder field.
  • nodejs-addon-examples/README.md
    • Documented the new test_asr_non_streaming_moonshine_v2.js example.
    • Added setup and execution instructions for the Moonshine v2 non-streaming ASR example.
  • nodejs-addon-examples/test_asr_non_streaming_moonshine_v2.js
    • Created a new JavaScript example file demonstrating non-streaming ASR using Moonshine v2 models.
Activity
  • No human activity (comments, reviews, etc.) has been recorded on this pull request yet.
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. ↩

@coderabbitai

coderabbitai Bot commented Feb 28, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8519d61 and 1b2a90c.

📒 Files selected for processing (4)
  • .github/scripts/test-nodejs-addon-npm.sh
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-asr.cc
  • nodejs-addon-examples/README.md
  • nodejs-addon-examples/test_asr_non_streaming_moonshine_v2.js

📝 Walkthrough

Walkthrough

The PR adds Moonshine v2 ASR model support to sherpa-onnx by introducing a merged_decoder field in the offline model configuration, creating a Node.js test script that demonstrates the new model variant, updating documentation with usage examples, and adding a CI test flow to validate the integration.

Changes

Cohort / File(s) Summary
Moonshine v2 C++ Configuration
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-asr.cc
Added initialization and cleanup handling for the merged_decoder field in the Moonshine model config structure.
Node.js Test & Documentation
nodejs-addon-examples/test_asr_non_streaming_moonshine_v2.js, nodejs-addon-examples/README.md
Introduced a complete non-streaming Moonshine v2 test script with configuration for encoder, tokens, and sample rate; added corresponding documentation section with download and execution instructions.
CI Test Flow
.github/scripts/test-nodejs-addon-npm.sh
Added a new test workflow that downloads the Moonshine v2 tiny-en quantized model, extracts it, runs the test script, and cleans up artifacts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

size:M

Poem

🐰 A Moonshine v2 hops into view,
With merged_decoder, shiny and new,
From C++ to Node we bound with delight,
Testing the model, getting it right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 a JavaScript/Node.js API for Moonshine v2 models, which is reflected across all modified files (test script, README documentation, shell script, and C++ configuration).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • 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

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

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

Comment on lines +13 to +20
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

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

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.

Suggested change
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}

Comment on lines +341 to +345
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

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 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).

Suggested change
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 = {

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 model directory path './sherpa-onnx-moonshine-tiny-en-quantized-2026-02-27' is repeated multiple times in this file (lines 14, 16, 18, 26). To improve maintainability, consider defining it as a constant at the top of the file and reusing it.

Comment on lines +30 to +37
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();

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 variables start and stop are not reassigned. It's a good practice to declare them with const to enforce immutability.

Suggested change
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();

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

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.

Comment on lines +13 to +20
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

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@csukuangfj
csukuangfj merged commit 7ec0c48 into k2-fsa:master Feb 28, 2026
5 checks passed
@csukuangfj
csukuangfj deleted the javascript-node-addon-moonshine-v2 branch February 28, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants