-
Notifications
You must be signed in to change notification settings - Fork 69
feat[notask|api]: add LavaSR speech enhancement support to TTS plugin #1310
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
63d7ef8
feat: Update TTS to 0.8.0 and its usage
c673493
Add missing models
b01faba
Set multilingual to false
71b403f
fix: Update tts version
ishanvohra2 a0db998
feat(sdk)[api]: add LavaSR speech enhancement support to TTS plugin
8bdf8c4
Merge branch 'main' into feat/sdk-lavasr-tts-support
29ff9df
chore(sdk): merge main, bump tts-onnx to 0.8.3, update model constants
521a374
fix: address PR review feedback for LavaSR TTS enhancement
5bfed4f
Merge branch 'main' into feat/sdk-lavasr-tts-support
3824ae0
Merge branch 'main' into feat/sdk-lavasr-tts-support
sharmaraju352 3068254
Merge branch 'main' into feat/sdk-lavasr-tts-support
sharmaraju352 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,132 @@ | ||
| import { | ||
| loadModel, | ||
| textToSpeech, | ||
| unloadModel, | ||
| type ModelProgressUpdate, | ||
| TTS_TOKENIZER_EN_CHATTERBOX, | ||
| TTS_SPEECH_ENCODER_EN_CHATTERBOX_FP32, | ||
| TTS_EMBED_TOKENS_EN_CHATTERBOX_FP32, | ||
| TTS_CONDITIONAL_DECODER_EN_CHATTERBOX_FP32, | ||
| TTS_LANGUAGE_MODEL_EN_CHATTERBOX_FP32, | ||
| TTS_ENHANCER_BACKBONE_LAVASR_FP32, | ||
| TTS_ENHANCER_SPEC_HEAD_LAVASR_FP32, | ||
| TTS_DENOISER_LAVASR_FP32, | ||
| } from "@qvac/sdk"; | ||
| import { | ||
| createWav, | ||
| playAudio, | ||
| int16ArrayToBuffer, | ||
| createWavHeader, | ||
| } from "./utils"; | ||
|
|
||
| // A/B comparison: Chatterbox TTS with and without LavaSR neural speech enhancement. | ||
| // Produces two WAV files so you can hear the difference. | ||
| // Usage: node chatterbox-enhanced.js <referenceAudioSrc> | ||
| // LavaSR models are loaded from the QVAC Registry automatically. | ||
| const [referenceAudioSrc] = process.argv.slice(2); | ||
|
|
||
| if (!referenceAudioSrc) { | ||
| console.error("Usage: node chatterbox-enhanced.js <referenceAudioSrc>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const CHATTERBOX_SAMPLE_RATE = 24000; | ||
| const ENHANCED_SAMPLE_RATE = 48000; | ||
| const SYNTHESIS_TEXT = | ||
| "Hello! This sentence is synthesized twice, once at standard quality and once with LavaSR neural enhancement, so you can hear the difference."; | ||
|
|
||
| const chatterboxConfig = { | ||
| ttsEngine: "chatterbox" as const, | ||
| language: "en" as const, | ||
| ttsTokenizerSrc: TTS_TOKENIZER_EN_CHATTERBOX.src, | ||
| ttsSpeechEncoderSrc: TTS_SPEECH_ENCODER_EN_CHATTERBOX_FP32.src, | ||
| ttsEmbedTokensSrc: TTS_EMBED_TOKENS_EN_CHATTERBOX_FP32.src, | ||
| ttsConditionalDecoderSrc: TTS_CONDITIONAL_DECODER_EN_CHATTERBOX_FP32.src, | ||
| ttsLanguageModelSrc: TTS_LANGUAGE_MODEL_EN_CHATTERBOX_FP32.src, | ||
| referenceAudioSrc, | ||
| }; | ||
|
|
||
| function onProgress(progress: ModelProgressUpdate) { | ||
| console.log(progress); | ||
| } | ||
|
|
||
| function saveAndPlay(samples: number[], sampleRate: number, filename: string) { | ||
| createWav(samples, sampleRate, filename); | ||
| console.log(`Saved ${filename}`); | ||
| const audioData = int16ArrayToBuffer(samples); | ||
| const wavBuffer = Buffer.concat([ | ||
| createWavHeader(audioData.length, sampleRate), | ||
| audioData, | ||
| ]); | ||
| playAudio(wavBuffer); | ||
| } | ||
|
|
||
| try { | ||
| // --- Pass 1: Raw Chatterbox (no enhancer) --- | ||
| console.log("\n--- Pass 1: Raw Chatterbox (24 kHz) ---\n"); | ||
|
|
||
| const rawModelId = await loadModel({ | ||
| modelSrc: TTS_TOKENIZER_EN_CHATTERBOX.src, | ||
| modelType: "tts", | ||
| modelConfig: chatterboxConfig, | ||
| onProgress, | ||
| }); | ||
|
|
||
| const rawResult = textToSpeech({ | ||
| modelId: rawModelId, | ||
| text: SYNTHESIS_TEXT, | ||
| inputType: "text", | ||
| stream: false, | ||
| }); | ||
|
|
||
| const rawBuffer = await rawResult.buffer; | ||
| console.log(`Raw TTS complete. ${rawBuffer.length} samples @ ${CHATTERBOX_SAMPLE_RATE} Hz`); | ||
| saveAndPlay(rawBuffer, CHATTERBOX_SAMPLE_RATE, "tts-raw-output.wav"); | ||
|
|
||
| await unloadModel({ modelId: rawModelId }); | ||
| console.log("Raw model unloaded.\n"); | ||
|
|
||
| // --- Pass 2: Chatterbox + LavaSR enhancement --- | ||
| console.log("--- Pass 2: Chatterbox + LavaSR enhancement (48 kHz) ---\n"); | ||
|
|
||
| const enhancedModelId = await loadModel({ | ||
| modelSrc: TTS_TOKENIZER_EN_CHATTERBOX.src, | ||
| modelType: "tts", | ||
| modelConfig: { | ||
| ...chatterboxConfig, | ||
| enhancer: { | ||
| type: "lavasr", | ||
| enhance: true, | ||
| denoise: true, | ||
| backboneSrc: TTS_ENHANCER_BACKBONE_LAVASR_FP32.src, | ||
| specHeadSrc: TTS_ENHANCER_SPEC_HEAD_LAVASR_FP32.src, | ||
| denoiserSrc: TTS_DENOISER_LAVASR_FP32.src, | ||
| }, | ||
| }, | ||
| onProgress, | ||
| }); | ||
|
|
||
| const enhancedResult = textToSpeech({ | ||
| modelId: enhancedModelId, | ||
| text: SYNTHESIS_TEXT, | ||
| inputType: "text", | ||
| stream: false, | ||
| }); | ||
|
|
||
| const enhancedBuffer = await enhancedResult.buffer; | ||
| console.log(`Enhanced TTS complete. ${enhancedBuffer.length} samples @ ${ENHANCED_SAMPLE_RATE} Hz`); | ||
| saveAndPlay(enhancedBuffer, ENHANCED_SAMPLE_RATE, "tts-enhanced-output.wav"); | ||
|
|
||
| await unloadModel({ modelId: enhancedModelId }); | ||
| console.log("Enhanced model unloaded."); | ||
|
|
||
| console.log("\n--- Done ---"); | ||
| console.log("Compare the two files:"); | ||
| console.log(" tts-raw-output.wav -- 24 kHz standard Chatterbox"); | ||
| console.log(" tts-enhanced-output.wav -- 48 kHz with LavaSR enhancement"); | ||
|
|
||
| process.exit(0); | ||
| } catch (error) { | ||
| console.error("❌ Error:", error); | ||
| process.exit(1); | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually needed to be public export ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem to be used anywhere and I don't see obvious use for it