{"record":{"id":"735423545c19cd3e","repo":"Comfy-Org/ComfyUI","slug":"audio-duration-must-be-at-most-max-duration-s-go","errorCode":null,"errorMessage":"Audio duration must be at most {max_duration}s, got {dur - eps:.2f}s","messagePattern":"Audio duration must be at most (.+?)s, got (.+?)s","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/validation_utils.py","lineNumber":171,"sourceCode":"\ndef get_number_of_images(images):\n    if isinstance(images, torch.Tensor):\n        return images.shape[0] if images.ndim >= 4 else 1\n    return len(images)\n\n\ndef validate_audio_duration(\n    audio: Input.Audio,\n    min_duration: float | None = None,\n    max_duration: float | None = None,\n) -> None:\n    sr = int(audio[\"sample_rate\"])\n    dur = int(audio[\"waveform\"].shape[-1]) / sr\n    eps = 1.0 / sr\n    if min_duration is not None and dur + eps < min_duration:\n        raise ValueError(f\"Audio duration must be at least {min_duration}s, got {dur + eps:.2f}s\")\n    if max_duration is not None and dur - eps > max_duration:\n        raise ValueError(f\"Audio duration must be at most {max_duration}s, got {dur - eps:.2f}s\")\n\n\ndef validate_string(\n    string: str,\n    strip_whitespace=True,\n    field_name=\"prompt\",\n    min_length=None,\n    max_length=None,\n):\n    if string is None:\n        raise Exception(f\"Field '{field_name}' cannot be empty.\")\n    if strip_whitespace:\n        string = string.strip()\n    if min_length and len(string) < min_length:\n        raise Exception(\n            f\"Field '{field_name}' cannot be shorter than {min_length} characters; was {len(string)} characters long.\"\n        )\n    if max_length and len(string) > max_length:","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/validation_utils.py#L153-L189","documentation":"Raised by validate_audio_duration() in comfy_api_nodes/util/validation_utils.py when an AUDIO input is longer than the provider's maximum. Duration is waveform length / sample_rate, minus a one-sample epsilon so a clip of exactly max_duration passes. Raised before any network call so oversized audio fails locally instead of on the provider side.","triggerScenarios":"Passing an AUDIO tensor to a node calling validate_audio_duration(audio, max_duration=N): sync.so enforces 600 s, bytedance clip-context 30 s, Kling 300 s, Wan variants 29-60 s. A 45 s clip into validate_audio_duration(audio, max_duration=30.0) raises.","commonSituations":"Long podcast/music audio fed into a lip-sync or video-augmentation node with a permissive-looking UI; workflows reused across providers with different caps; audio whose real duration is underestimated because the user reasons in minutes while the cap is in seconds.","solutions":["Trim the audio to <= max_duration seconds before the node (audio trim/crop node or split into segments).","Compute the exact duration first: audio['waveform'].shape[-1] / audio['sample_rate'] and compare against the node's documented cap.","For long content, split into chunks and run the node per chunk, then recombine outputs.","If the provider offers a higher-limit endpoint, switch to the corresponding node variant."],"exampleFix":"# before: 45 s audio into validate_audio_duration(clip, max_duration=30.0)\n# raises: Audio duration must be at most 30.0s, got 45.00s\n\n# after: trim to first 30 s\nmax_samples = int(30.0 * clip['sample_rate'])\nclip['waveform'] = clip['waveform'][..., :max_samples]","handlingStrategy":"validation","validationCode":"dur = audio['waveform'].shape[-1] / audio['sample_rate']\nif dur - 1.0 / audio['sample_rate'] > MAX_DUR:\n    audio['waveform'] = audio['waveform'][..., :int(MAX_DUR * audio['sample_rate'])]","typeGuard":null,"tryCatchPattern":"try: validate_audio_duration(audio, max_duration=MAX) except ValueError as e: raise RuntimeError(f'Audio too long: {e}') from e","preventionTips":["Trim long audio to the provider cap before the node.","Split long content into chunks and recombine outputs.","Keep a note of each provider node's duration cap when reusing workflows."],"tags":["audio","api-nodes","validation","input-validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}