From 462b3cf994c093c25aaf2a10159b135e757959d0 Mon Sep 17 00:00:00 2001 From: Carlos Diosdado Date: Tue, 16 Jun 2026 15:34:37 -0600 Subject: [PATCH] feat(tts): add optional provider parameter to text_to_speech tool Adds an optional provider parameter to the text_to_speech tool that lets the model select a TTS provider per-call instead of always using the globally configured tts.provider. When provider is set, it bypasses the configured default and routes directly to the specified backend. When omitted (the default), the tool behaves exactly as before. Closes #47459 --- tools/tts_tool.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/tts_tool.py b/tools/tts_tool.py index 9ad3d2f1d291c..2167264fff532 100644 --- a/tools/tts_tool.py +++ b/tools/tts_tool.py @@ -2577,6 +2577,7 @@ def text_to_speech_tool( output_path: Optional[str] = None, speed: Optional[float] = None, instructions: Optional[str] = None, + provider: Optional[str] = None, ) -> str: """ Convert text to speech audio. @@ -2596,6 +2597,14 @@ def text_to_speech_tool( accent, whispering). Forwarded to the OpenAI backend (gpt-4o-mini-tts and OpenAI-compatible servers). Silently ignored by backends that don't support it. + provider: Optional TTS provider override. When set, bypasses the + configured ``tts.provider`` and uses this provider instead. + Accepts built-in names (``edge``, ``openai``, ``elevenlabs``, + ``minimax``, ``xai``, ``mistral``, ``gemini``, ``neutts``, + ``kittentts``, ``piper``), user-declared command provider names + from ``tts.providers.``, or plugin-registered provider + names. When ``None`` (the default), the configured provider + from ``tts.provider`` in config.yaml is used. Returns: str: JSON result with success, file_path, and optionally MEDIA tag. @@ -2619,7 +2628,12 @@ def text_to_speech_tool( clamped = max(0.25, min(4.0, float(speed))) tts_config = dict(tts_config) # shallow copy to avoid mutating the cache tts_config["speed"] = clamped - provider = _get_provider(tts_config) + + # Allow per-call provider override; fall back to the configured default. + if provider: + provider = provider.lower().strip() + else: + provider = _get_provider(tts_config) # User-declared command provider (type: command under tts.providers.) # resolves BEFORE the built-in dispatch. Built-in names short-circuit here @@ -3355,6 +3369,16 @@ TTS_SCHEMA = { "Forwarded to the OpenAI backend (gpt-4o-mini-tts and OpenAI-compatible " "voice-design servers). Silently ignored by backends that don't support it." ) + }, + "provider": { + "type": "string", + "description": ( + "Optional TTS provider override. Accepts built-in names " + "(edge, openai, elevenlabs, minimax, xai, mistral, gemini, " + "neutts, kittentts, piper), user-declared command provider " + "names from tts.providers., or plugin-registered names. " + "When omitted, the configured tts.provider from config.yaml is used." + ) } }, "required": ["text"] @@ -3369,7 +3393,8 @@ registry.register( text=args.get("text", ""), output_path=args.get("output_path"), speed=args.get("speed"), - instructions=args.get("instructions")), + instructions=args.get("instructions"), + provider=args.get("provider")), check_fn=check_tts_requirements, emoji="🔊", )