From 1e5fda3c5c9bea04782342d6fa599c561d536d9d Mon Sep 17 00:00:00 2001 From: calesthio Date: Sat, 4 Apr 2026 13:10:29 -0700 Subject: [PATCH] Fix OpenAI TTS passing null instructions to API The instructions parameter was passed as None when not provided, causing a 400 error. Now only included when explicitly set. Also adds speed passthrough support. --- tools/audio/openai_tts.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/audio/openai_tts.py b/tools/audio/openai_tts.py index b2a50e2..29ebd7d 100644 --- a/tools/audio/openai_tts.py +++ b/tools/audio/openai_tts.py @@ -132,13 +132,18 @@ class OpenAITTS(BaseTool): output_path = Path(inputs.get("output_path", f"openai_tts.{fmt}")) output_path.parent.mkdir(parents=True, exist_ok=True) - with client.audio.speech.with_streaming_response.create( - model=model, - voice=voice, - input=text, - response_format=fmt, - instructions=inputs.get("instructions"), - ) as response: + kwargs: dict[str, Any] = { + "model": model, + "voice": voice, + "input": text, + "response_format": fmt, + } + if inputs.get("instructions"): + kwargs["instructions"] = inputs["instructions"] + if inputs.get("speed") and inputs["speed"] != 1.0: + kwargs["speed"] = inputs["speed"] + + with client.audio.speech.with_streaming_response.create(**kwargs) as response: response.stream_to_file(output_path) audio_duration = probe_duration(output_path)