Repository navigation
Add JavaScript API for FunASR Nano (node-addon) - #3026
Conversation
📝 WalkthroughWalkthroughThis pull request adds support for the FunASR Nano model to sherpa-onnx. Changes include C++ configuration parsing for the new model type, a Node.js example script demonstrating its usage, CI test integration, and documentation updates describing the feature. Changes
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
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🔇 Additional comments (8)
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 |
Summary of ChangesHello @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 Sherpa ONNX Node.js addon by integrating the FunASR Nano model for non-streaming automatic speech recognition. The changes provide a complete solution, from the underlying C++ bindings that manage model configuration to a user-friendly JavaScript API and a clear example, making it straightforward for developers to leverage FunASR Nano in their Node.js applications. This enhancement broadens the range of supported ASR models and improves the overall utility of the addon. Highlights
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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for FunASR Nano models to the Node.js addon, including C++ bindings, a new JavaScript example, CI test script updates, and documentation. The changes are well-integrated, especially the C++ part which correctly handles memory management. I've provided a few suggestions to enhance the shell script and JavaScript example for better maintainability by reducing hardcoded, repeated strings.
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| tar xvf sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| rm sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
|
|
||
| node ./test_asr_non_streaming_funasr_nano.js | ||
| rm -rf sherpa-onnx-funasr-nano-int8-2025-12-30 |
There was a problem hiding this comment.
To improve script robustness and maintainability, it's better to chain commands that depend on each other with &&. This ensures that the script will stop if a command fails. Also, using a variable for the model name avoids repetition and makes it easier to update.
Consider adding set -e at the top of your script to make it exit immediately if a command exits with a non-zero status.
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | |
| tar xvf sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | |
| rm sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | |
| node ./test_asr_non_streaming_funasr_nano.js | |
| rm -rf sherpa-onnx-funasr-nano-int8-2025-12-30 | |
| MODEL_NAME="sherpa-onnx-funasr-nano-int8-2025-12-30" | |
| 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_funasr_nano.js | |
| rm -rf "${MODEL_NAME}" |
| wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| tar xvf sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| rm sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
|
|
||
| node ./test_asr_non_streaming_funasr_nano.js |
There was a problem hiding this comment.
For better maintainability and to avoid repeating the long model filename, consider introducing a variable in this example script. This makes it easier to update the model version in the future.
For example:
MODEL_NAME="sherpa-onnx-funasr-nano-int8-2025-12-30"
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_asr_non_streaming_funasr_nano.js| const config = { | ||
| 'featConfig': { | ||
| 'sampleRate': 16000, | ||
| 'featureDim': 80, | ||
| }, | ||
| 'modelConfig': { | ||
| 'funasrNano': { | ||
| 'encoderAdaptor': | ||
| './sherpa-onnx-funasr-nano-int8-2025-12-30/encoder_adaptor.int8.onnx', | ||
| 'llm': './sherpa-onnx-funasr-nano-int8-2025-12-30/llm.int8.onnx', | ||
| 'embedding': | ||
| './sherpa-onnx-funasr-nano-int8-2025-12-30/embedding.int8.onnx', | ||
| 'tokenizer': './sherpa-onnx-funasr-nano-int8-2025-12-30/Qwen3-0.6B', | ||
| }, | ||
| 'tokens': '', | ||
| 'numThreads': 2, | ||
| 'provider': 'cpu', | ||
| 'debug': 1, | ||
| } | ||
| }; | ||
|
|
||
| const waveFilename = | ||
| './sherpa-onnx-funasr-nano-int8-2025-12-30/test_wavs/lyrics.wav'; |
There was a problem hiding this comment.
The model directory path is hardcoded in multiple places. To improve maintainability, it's a good practice to define it as a constant and reuse it. This makes it much easier to update the model version in the future.
For example:
const modelDir = './sherpa-onnx-funasr-nano-int8-2025-12-30';
const config = {
'featConfig': {
'sampleRate': 16000,
'featureDim': 80,
},
'modelConfig': {
'funasrNano': {
'encoderAdaptor': `${modelDir}/encoder_adaptor.int8.onnx`,
'llm': `${modelDir}/llm.int8.onnx`,
'embedding': `${modelDir}/embedding.int8.onnx`,
'tokenizer': `${modelDir}/Qwen3-0.6B`,
},
'tokens': '',
'numThreads': 2,
'provider': 'cpu',
'debug': 1,
}
};
const waveFilename = `${modelDir}/test_wavs/lyrics.wav`;
Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.