Skip to content

Add JavaScript (WebAssembly) example for ZipVoice TTS - #3341

Merged
csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:js-wasm-zipvoice-tts
Mar 18, 2026
Merged

csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:js-wasm-zipvoice-tts

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Mar 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added a Node.js example demonstrating ZipVoice zero-shot offline TTS for Chinese and English.
  • Tests

    • Expanded offline TTS test suite to run additional model scenarios with automated setup, execution, and cleanup.
  • Documentation

    • Added documentation and step-by-step run instructions for the new offline TTS example and tests.

@csukuangfj
csukuangfj requested a review from Copilot March 18, 2026 03:23
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 18, 2026
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5379711c-ab08-497d-b068-074393259db9

📥 Commits

Reviewing files that changed from the base of the PR and between 224b706 and e6f98b7.

📒 Files selected for processing (1)
  • nodejs-examples/test-offline-tts-zipvoice-zh-en.js

📝 Walkthrough

Walkthrough

Adds offline ZipVoice and several Kokoro/Matcha TTS test steps to CI, a new Node.js offline ZipVoice TTS example script, and README documentation describing the ZipVoice offline TTS test and run commands.

Changes

Cohort / File(s) Summary
CI Test Automation
.github/scripts/test-nodejs-npm.sh
Adds offline TTS model download, extraction, test execution, WAV listing, and cleanup blocks for ZipVoice, Kokoro (multi-lang & en) and Matcha models, and downloads of corresponding ONNX vocoder files.
Documentation
nodejs-examples/README.md
Adds a Text-to-speech subsection documenting test-offline-tts-zipvoice-zh-en.js, including intent, transcript-audio alignment note, and exact model download + run commands.
ZipVoice TTS Test Script
nodejs-examples/test-offline-tts-zipvoice-zh-en.js
New Node.js example that initializes an offline sherpa-onnx ZipVoice TTS instance, loads a reference waveform/text, builds a generationConfig, runs generateWithConfig, writes test-zipvoice-zh-en.wav, and releases resources.

Sequence Diagram(s)

sequenceDiagram
  participant CI as CI runner
  participant Remote as Model host (storage)
  participant FS as Filesystem
  participant Node as Node.js test
  participant Lib as sherpa-onnx runtime

  CI->>Remote: download model tarballs & ONNX files
  Remote-->>CI: tarballs/onnx files
  CI->>FS: extract tarballs, place models
  CI->>Node: invoke test script (node test-offline-tts-zipvoice-zh-en.js)
  Node->>Lib: initialize offline TTS with model paths
  Node->>Lib: generate audio (generationConfig with ref wave/text)
  Lib-->>Node: generated WAV bytes
  Node->>FS: write WAV file(s)
  CI->>FS: list WAVs, then remove extracted models/onnx
  CI-->>Remote: (cleanup complete)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I nibbled models, zipped with glee,
I hopped through scripts, made WAVs for three,
Offline voices, zh and en in tow,
Little paws clicked run — listen, they glow! 🎶

🚥 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/WebAssembly example for ZipVoice TTS, which is reflected in the new test script and documentation.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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, 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 introduces a new JavaScript example for ZipVoice Text-to-Speech, enabling users to perform zero-shot TTS in both Chinese and English within a Node.js environment. The changes include the addition of the example script, its integration into the CI/CD testing pipeline, and comprehensive documentation to guide users on its execution and model setup. This expands the available TTS demonstrations and showcases the capabilities of ZipVoice within the sherpa-onnx ecosystem.

Highlights

  • New JavaScript Example: Added a new JavaScript example (test-offline-tts-zipvoice-zh-en.js) demonstrating offline ZipVoice Text-to-Speech (TTS) for Chinese and English.
  • Automated Testing Integration: Integrated the new ZipVoice TTS example into the Node.js test script (.github/scripts/test-nodejs-npm.sh) for automated testing and model download.
  • Documentation Update: Updated the nodejs-examples/README.md to provide clear instructions on how to set up and run the new ZipVoice TTS example.
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.

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

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 new Node.js (WebAssembly-backed) example demonstrating ZipVoice zero-shot TTS for Chinese/English, and wires it into the Node.js examples documentation and CI smoke test flow.

Changes:

  • Add test-offline-tts-zipvoice-zh-en.js example that generates audio using generateWithConfig() with ZipVoice reference audio/text.
  • Document download + run steps for the new example in nodejs-examples/README.md.
  • Extend GitHub CI Node.js npm test script to download the required ZipVoice/vocoder assets and execute the example.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
nodejs-examples/test-offline-tts-zipvoice-zh-en.js New ZipVoice zh-en zero-shot TTS example using a prompt wav + transcript and generateWithConfig().
nodejs-examples/README.md Adds a section describing how to run the new ZipVoice TTS example and download model artifacts.
.github/scripts/test-nodejs-npm.sh CI: downloads ZipVoice model + vocoder, runs the new example, then cleans up downloaded artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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 introduces a new JavaScript example for ZipVoice TTS, complete with the necessary test script modifications and documentation updates. My review focuses on enhancing the code quality of the new example file. I've provided a suggestion to use const for variables that are not reassigned, which is a JavaScript best practice for improving code robustness and clarity.

Comment on lines +6 to +25
let zipvoice = {
encoder: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/encoder.int8.onnx',
decoder: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/decoder.int8.onnx',
tokens: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/tokens.txt',
lexicon: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/lexicon.txt',
dataDir: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/espeak-ng-data',
vocoder: './vocos_24khz.onnx',
};

let offlineTtsModelConfig = {
offlineTtsZipVoiceModelConfig: zipvoice,
numThreads: 1,
debug: 1, // set it to 1 to see verbose logs; 0 to disable logs
provider: 'cpu',
};

let offlineTtsConfig = {
offlineTtsModelConfig: offlineTtsModelConfig,
maxNumSentences: 1,
};

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 zipvoice, offlineTtsModelConfig, and offlineTtsConfig are not reassigned within this function. It is a best practice in modern JavaScript to use const for variables that do not change, as it prevents accidental reassignment and makes the code easier to reason about.

Suggested change
let zipvoice = {
encoder: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/encoder.int8.onnx',
decoder: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/decoder.int8.onnx',
tokens: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/tokens.txt',
lexicon: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/lexicon.txt',
dataDir: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/espeak-ng-data',
vocoder: './vocos_24khz.onnx',
};
let offlineTtsModelConfig = {
offlineTtsZipVoiceModelConfig: zipvoice,
numThreads: 1,
debug: 1, // set it to 1 to see verbose logs; 0 to disable logs
provider: 'cpu',
};
let offlineTtsConfig = {
offlineTtsModelConfig: offlineTtsModelConfig,
maxNumSentences: 1,
};
const zipvoice = {
encoder: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/encoder.int8.onnx',
decoder: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/decoder.int8.onnx',
tokens: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/tokens.txt',
lexicon: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/lexicon.txt',
dataDir: './sherpa-onnx-zipvoice-distill-int8-zh-en-emilia/espeak-ng-data',
vocoder: './vocos_24khz.onnx',
};
const offlineTtsModelConfig = {
offlineTtsZipVoiceModelConfig: zipvoice,
numThreads: 1,
debug: 1, // set it to 1 to see verbose logs; 0 to disable logs
provider: 'cpu',
};
const offlineTtsConfig = {
offlineTtsModelConfig: offlineTtsModelConfig,
maxNumSentences: 1,
};

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

🧹 Nitpick comments (1)
nodejs-examples/test-offline-tts-zipvoice-zh-en.js (1)

48-52: Guard tts.free() with finally for failure-safe cleanup.

If generateWithConfig() or save() throws, cleanup is skipped. Wrap lifecycle in try/finally.

♻️ Proposed fix
-const tts = createOfflineTts();
-const audio = tts.generateWithConfig(text, generationConfig);
-tts.save('./test-zipvoice-zh-en.wav', audio);
-console.log('Saved to test-zipvoice-zh-en.wav successfully.');
-tts.free();
+let tts;
+try {
+  tts = createOfflineTts();
+  const audio = tts.generateWithConfig(text, generationConfig);
+  tts.save('./test-zipvoice-zh-en.wav', audio);
+  console.log('Saved to test-zipvoice-zh-en.wav successfully.');
+} finally {
+  tts?.free();
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nodejs-examples/test-offline-tts-zipvoice-zh-en.js` around lines 48 - 52, The
code calls createOfflineTts(), then generateWithConfig() and save(), but
tts.free() is unconditional and skipped if an exception occurs; wrap the
lifecycle of the TTS instance in a try/finally so that createOfflineTts() -> try
{ const audio = tts.generateWithConfig(text, generationConfig); tts.save(...); }
finally { tts.free(); } ensuring the TTS instance (tts) is freed even when
generateWithConfig or save throws; reference createOfflineTts,
generateWithConfig, save, and free to locate and modify the block.
🤖 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-tts-zipvoice-zh-en.js`:
- Around line 48-52: The code calls createOfflineTts(), then
generateWithConfig() and save(), but tts.free() is unconditional and skipped if
an exception occurs; wrap the lifecycle of the TTS instance in a try/finally so
that createOfflineTts() -> try { const audio = tts.generateWithConfig(text,
generationConfig); tts.save(...); } finally { tts.free(); } ensuring the TTS
instance (tts) is freed even when generateWithConfig or save throws; reference
createOfflineTts, generateWithConfig, save, and free to locate and modify the
block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56f7483f-b9ab-4dff-a745-e7611e6eed5b

📥 Commits

Reviewing files that changed from the base of the PR and between cc02b69 and 224b706.

📒 Files selected for processing (3)
  • .github/scripts/test-nodejs-npm.sh
  • nodejs-examples/README.md
  • nodejs-examples/test-offline-tts-zipvoice-zh-en.js

@csukuangfj
csukuangfj merged commit dbaf894 into k2-fsa:master Mar 18, 2026
1 check was pending
@csukuangfj
csukuangfj deleted the js-wasm-zipvoice-tts branch March 18, 2026 04:04
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