{"record":{"id":"56160f74ea65505e","repo":"Comfy-Org/ComfyUI","slug":"audio-duration-must-be-at-least-min-duration-s-g","errorCode":null,"errorMessage":"Audio duration must be at least {min_duration}s, got {dur + eps:.2f}s","messagePattern":"Audio duration must be at least (.+?)s, got (.+?)s","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/validation_utils.py","lineNumber":169,"sourceCode":"        raise ValueError(f\"Video frame count must be at most {max_frame_count}, got {frame_count}\")\n\n\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.\"","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/validation_utils.py#L151-L187","documentation":"Raised by validate_audio_duration() in comfy_api_nodes/util/validation_utils.py when an AUDIO input is shorter than the provider's minimum. Duration is computed as waveform.shape[-1] / sample_rate with a one-sample epsilon (1/sr) added so that a waveform containing exactly min_duration of samples passes. The check runs before the API call so short audio fails fast locally.","triggerScenarios":"Passing an AUDIO tensor to a node that calls validate_audio_duration(audio, min_duration=X) — e.g. Wan/Kling lip-sync nodes enforce min 2-3 s, sync.so nodes use max only, bytedance clips cap at 30 s. A 1.0 s clip into a node with min_duration=2.0 raises because dur + 1/sr < 2.0.","commonSituations":"User records or crops a very short voice line for lip-sync; a TTS upstream node produces a trailing-silence-trimmed clip shorter than expected; or a silence-trim node removes most of the audio. Common after switching providers, since minima differ (1.5 s, 2 s, 3 s).","solutions":["Extend the audio to at least min_duration seconds: pad with silence (e.g. an audio-pad/empty-audio node) or supply a longer recording.","Verify the actual duration in Python: len(audio['waveform'].shape[-1]) / audio['sample_rate'] before wiring it in.","Check the node's tooltip for the provider's minimum and use a provider/node with a lower minimum if your content is intentionally short.","If silence-trim or VAD nodes are shortening the clip, disable or re-tune them upstream."],"exampleFix":"# before: 1.2 s audio into validate_audio_duration(audio, 3.0, 29.0)\n# raises: Audio duration must be at least 3.0s, got 1.20s\n\n# after: pad audio with silence to >= 3 s before the node\nsr = audio['sample_rate']\nneed = int(3.0 * sr) - audio['waveform'].shape[-1]\nif need > 0:\n    audio['waveform'] = torch.cat([audio['waveform'], torch.zeros(1, 1, need)], dim=-1)","handlingStrategy":"validation","validationCode":"def audio_duration(audio) -> float:\n    return audio['waveform'].shape[-1] / audio['sample_rate']\n\nif audio_duration(a) + 1.0 / a['sample_rate'] < MIN_DUR:\n    a['waveform'] = torch.nn.functional.pad(a['waveform'], (0, int(MIN_DUR * a['sample_rate']) - a['waveform'].shape[-1]))","typeGuard":null,"tryCatchPattern":"try: validate_audio_duration(audio, min_duration=MIN) except ValueError as e: raise RuntimeError(f'Short audio: {e}') from e","preventionTips":["Compute duration from waveform length / sample_rate before wiring audio in.","Pad short clips with silence to clear provider minimums.","Watch silence-trim nodes shrinking clips below the limit."],"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"}