feat(tts): support per-request instructions and params#10172
Merged
Conversation
The OpenAI-compatible TTS endpoint accepts an `instructions` field, but it was silently dropped at the HTTP->gRPC boundary: neither schema.TTSRequest nor the gRPC TTSRequest proto carried it, so backends could only read such a value from static YAML options (identical for every request). This blocked per-line emotion/style and, for Qwen3-TTS VoiceDesign, limited a model config to a single designed voice. Plumb a generic per-request instruction string end to end, plus an optional backend-specific params map: - proto: add `optional string instructions` and `map<string,string> params` to TTSRequest. - schema: add Instructions (maps OpenAI `instructions`) and Params (LocalAI extension) to schema.TTSRequest. - core: thread both through ModelTTS/ModelTTSStream via a newTTSRequest helper that attaches instructions only when non-empty (so backends can fall back to YAML when unset); forward them from the /v1/audio/speech handler. - qwen-tts: prefer the per-request instruction over the YAML `instruct` option (used by both mode detection and generation) and merge per-request params. - chatterbox: merge per-request params (coerced to float/int/bool) over YAML options into generate() kwargs. Fully backward compatible: empty instructions fall back to the YAML option and backends that don't support style/voice instructions ignore the field. Closes #10164 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:claude-opus-4-8 [Claude Code]
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #10164.
The OpenAI-compatible TTS endpoint (
POST /v1/audio/speech) accepts aninstructionsfield, but it was silently dropped at the HTTP→gRPC boundary: neitherschema.TTSRequestnor the gRPCTTSRequestproto carried it, so backends could only read such a value from static YAMLoptions(identical for every request). This blocked:This PR plumbs a generic per-request instruction string end to end, plus an optional backend-specific
paramsmap.Changes
backend/backend.proto): addoptional string instructions = 6andmap<string,string> params = 7toTTSRequest.core/schema/localai.go): addInstructions(maps the OpenAIinstructionsfield) andParams(LocalAI extension).core/backend/tts.go): thread both throughModelTTS/ModelTTSStreamvia anewTTSRequesthelper that attachesinstructionsonly when non-empty (so backends can fall back to YAML when unset). Forwarded from the/v1/audio/speechhandler; other callers (cli, elevenlabs, realtime) pass empty values.backend/python/qwen-tts/backend.py): prefer the per-request instruction over the YAMLinstructoption (used by both mode detection and generation) and merge per-requestparams.backend/python/chatterbox/backend.py): merge per-requestparams(coerced to float/int/bool) over YAML options intogenerate()kwargs.Backward compatibility
Fully compatible: empty
instructionsfalls back to the YAML option, and backends that don't support style/voice instructions simply ignore the field. Theparamsmap values arrive as strings and are coerced by the backend.Example
Testing
newTTSRequest(instructions attached/omitted, params forwarded/nil); updated existing ctx-propagation specs for the new signature.core/backend,core/schema,core/http/endpoints/localaitest suites pass.go vetandgolangci-lint --new-from-merge-base=masterclean (0 issues); both Python backendspy_compileclean.Assisted-by: Claude:claude-opus-4-8 [Claude Code]