Add emotion_id input to offline VITS TTS - #3849
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughVITS TTS now accepts ChangesVITS emotion support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant TTSCLI
participant OfflineTtsVitsImpl
participant OfflineTtsVitsModel
TTSCLI->>OfflineTtsVitsImpl: provide emotion_id through GenerationConfig
OfflineTtsVitsImpl->>OfflineTtsVitsImpl: validate emotion_id
OfflineTtsVitsImpl->>OfflineTtsVitsModel: Run with emotion_id
OfflineTtsVitsModel->>OfflineTtsVitsModel: create emotion tensor when supported
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
9860cb0 to
a79b056
Compare
|
Pleasr add it to the generation config extra field. The change is very small.and you don't need to change so many files. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/dotnet/OfflineTtsGenerationConfig.cs`:
- Line 138: Add a managed EmotionId field to OfflineTtsGenerationConfig and
update its ToNative conversion to assign that value to NativeStruct.EmotionId,
preserving the existing configuration mapping so .NET callers can select
non-zero emotions.
In `@wasm/tts/sherpa-onnx-tts.js`:
- Around line 762-763: Update generate’s genConfig construction to include
config.emotionId, defaulting with nullish semantics to 0 before passing it to
initSherpaOnnxGenerationConfig, so generate({text, emotionId}) propagates the
requested emotion ID.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e633017b-b50e-4467-8282-445229f0c3a5
📒 Files selected for processing (8)
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dartscripts/dotnet/OfflineTtsGenerationConfig.cssherpa-onnx/pascal-api/sherpa_onnx.passherpa-onnx/rust/sherpa-onnx-sys/src/tts.rssherpa-onnx/rust/sherpa-onnx/src/tts.rsswift-api-examples/SherpaOnnx.swiftwasm/tts/sherpa-onnx-tts.jswasm/tts/sherpa-onnx-wasm-main-tts.cc
Hmm, I see what you mean. Yeah, we can mimick what we already do with "lang". Ok, I'll push another patch soon. |
a79b056 to
39c45ab
Compare
|
Done. Added |
|
The failing checks are unrelated to this change. Ready for review. Thank you. |
39c45ab to
3289bb5
Compare
csukuangfj
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
|
Tks @csukuangfj |
Motivation
There are several TTS models that offer emotion selection. However, the current input shape for offline TTS is:
Note that there is no emotion input tensor parameter available. This forces the user who wants to use multi-emotion models, such as
ai4bharat/vits_rasa_13, to export the model with a baked emotion (i.e. the emotion is immutable after the export).So, to fully take advantage of the multi-emotion models, we would want to export it as intended: with the emotion being an input tensor of its own, namely
emotion_id.As of 6897144, if we export it with the
emotion_idinput tensor, and attempt to do TTS withsherpa-onnx-offline-tts, we would see the following error:... [with T = onnxruntime::Tensor] Missing Input: emotion_idThis PR adds
emotion_idas the optional 7th input tensor to offline VITS TTS to allow for emotion selection. This feature is only enabled when the model's metadata hasnum_emotions > 0and theONNXexport has theemotion_idinput tensor. That is to say that it's completely ignored, if either condition is not met.Notes:
sherpa-onnx-offline-ttsCLI flag:--emotion-idExample Usage
Here is an example of how we vary the emotion using sherpa-onnx-vits-rasa-13 (my published
ONNXexport of ai4bharat/vits_rasa_13)Here is a sample output with only the
emotion_idvarying:Summary by CodeRabbit
--emotion-idcommand-line option.