-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add JavaScript (WebAssembly) API for PocketTTS #3163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) 2026 Xiaomi Corporation (authors: Fangjun Kuang) | ||
|
|
||
| const sherpa_onnx = require('sherpa-onnx'); | ||
|
|
||
| function createOfflineTts() { | ||
| let pocket = { | ||
| lmFlow: './sherpa-onnx-pocket-tts-int8-2026-01-26/lm_flow.int8.onnx', | ||
| lmMain: './sherpa-onnx-pocket-tts-int8-2026-01-26/lm_main.int8.onnx', | ||
| encoder: './sherpa-onnx-pocket-tts-int8-2026-01-26/encoder.onnx', | ||
| decoder: './sherpa-onnx-pocket-tts-int8-2026-01-26/decoder.int8.onnx', | ||
| textConditioner: | ||
| './sherpa-onnx-pocket-tts-int8-2026-01-26/text_conditioner.onnx', | ||
| vocabJson: './sherpa-onnx-pocket-tts-int8-2026-01-26/vocab.json', | ||
| tokenScoresJson: | ||
| './sherpa-onnx-pocket-tts-int8-2026-01-26/token_scores.json', | ||
| }; | ||
| let offlineTtsModelConfig = { | ||
| offlineTtsPocketModelConfig: pocket, | ||
| numThreads: 1, | ||
| debug: 1, // set it to 1 to see verbose logs; 0 to disable logs | ||
| provider: 'cpu', | ||
| }; | ||
|
|
||
| let offlineTtsConfig = { | ||
| offlineTtsModelConfig: offlineTtsModelConfig, | ||
| maxNumSentences: 1, | ||
| }; | ||
|
|
||
| return sherpa_onnx.createOfflineTts(offlineTtsConfig); | ||
| } | ||
|
|
||
| const referenceWaveFilename = | ||
| './sherpa-onnx-pocket-tts-int8-2026-01-26/test_wavs/bria.wav'; | ||
| const wave = sherpa_onnx.readWave(referenceWaveFilename); | ||
|
|
||
| const generationConfig = { | ||
| silenceScale: 0.2, | ||
| referenceAudio: wave.samples, | ||
| referenceSampleRate: wave.sampleRate, | ||
| numSteps: 5, | ||
| extra: {max_reference_audio_len: 12} | ||
| }; | ||
|
|
||
| const tts = createOfflineTts(); | ||
| const text = | ||
| 'Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.'; | ||
|
|
||
| const audio = tts.generateWithConfig(text, generationConfig); | ||
| tts.save('./test-pocket-en.wav', audio); | ||
| console.log('Saved to test-pocket-en.wav successfully.'); | ||
| tts.free(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.