calesthio/OpenMontage · error · ValueError

voice_speed must be between {TTS_SPEED_MIN} and {TTS_SPEED_M

Error message

voice_speed must be between {TTS_SPEED_MIN} and {TTS_SPEED_MAX}

What it means

Raised by kling_tts._build_request when voice_speed (default 1.0) falls outside the module constants TTS_SPEED_MIN..TTS_SPEED_MAX. The wrapper validates the range locally because Kling's API rejects out-of-range speeds server-side.

Source

Thrown at tools/audio/kling_tts.py:211

    def _build_request(self, inputs: dict[str, Any]) -> dict[str, Any]:
        text = str(inputs.get("text") or "").strip()
        if not text:
            raise ValueError("text is required")
        if len(text) > 5000:
            raise ValueError("text exceeds Kling TTS safety limit of 5000 characters")

        voice_id = str(inputs.get("voice_id") or "").strip()
        if not voice_id:
            raise ValueError("voice_id is required for Kling official TTS")

        voice_language = str(inputs.get("voice_language") or "en")
        if voice_language not in TTS_LANGUAGES:
            raise ValueError(f"voice_language must be one of: {', '.join(TTS_LANGUAGES)}")

        voice_speed = float(inputs.get("voice_speed", 1.0))
        if voice_speed < TTS_SPEED_MIN or voice_speed > TTS_SPEED_MAX:
            raise ValueError(f"voice_speed must be between {TTS_SPEED_MIN} and {TTS_SPEED_MAX}")

        payload: dict[str, Any] = {
            "text": text,
            "voice_id": voice_id,
            "voice_language": voice_language,
            "voice_speed": voice_speed,
        }
        self._copy_common_task_fields(inputs, payload)
        return {
            "protocol": "classic",
            "path": "/v1/audio/tts",
            "payload": payload,
            "operation": "text_to_speech",
            "model": "kling-official-tts",
        }

    @staticmethod
    def _create_and_collect_audios(

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. Clamp voice_speed into [TTS_SPEED_MIN, TTS_SPEED_MAX] before calling
  2. Keep the default 1.0 unless the script explicitly needs pacing changes
  3. If 150-style percentages come from config, divide by 100 first

Example fix

// before
inputs = {"text": t, "voice_id": vid, "voice_speed": 150}  # raises

// after
from tools.audio.kling_tts import TTS_SPEED_MIN, TTS_SPEED_MAX
inputs = {"text": t, "voice_id": vid, "voice_speed": min(max(1.5, TTS_SPEED_MIN), TTS_SPEED_MAX)}
Defensive patterns

Strategy: validation

Validate before calling

from tools.audio.kling_tts import TTS_SPEED_MIN, TTS_SPEED_MAX
speed = float(inputs.get("voice_speed", 1.0))
if not (TTS_SPEED_MIN <= speed <= TTS_SPEED_MAX):
    raise ValueError(f"voice_speed must be within [{TTS_SPEED_MIN}, {TTS_SPEED_MAX}]")

Type guard

def is_valid_speed(speed: float) -> bool:
    return TTS_SPEED_MIN <= speed <= TTS_SPEED_MAX

Prevention

When it happens

Trigger: Passing voice_speed like 0.1, 5, or a string that float() accepts but is out of range; copying a speed value calibrated for another provider's scale.

Common situations: Providers use different speed scales (0.25–4.0 vs 0.5–2.0); user-provided 'playbackRate' forwarded unclamped; unit confusion (percent 150 passed as 150).

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/ae70d9ed3b2df689. Report an issue: GitHub.