ComfyUI Node

Audio Duration

How many milliseconds is this audio, in one output

By wenchengxiang·Created 2 months ago·Updated 9 days ago· 3
Audio Duration
  • audio
  • duration_ms

Audio Duration takes an AUDIO object and tells you how long it is, in milliseconds, as an INT. One audio input, one duration_ms output, nothing else. It sounds trivial until you're syncing a soundtrack to a video clip or timing a loop, and then it's exactly the node you were missing.

Audio in ComfyUI is a bolted-on layer - the KB's audio-generation doc describes it as a branch that only grew once video got good enough to want a soundtrack. The AUDIO type is a dict carrying a waveform tensor and a sample_rate, and this node reads both. The math in the source is exactly what you'd write by hand: it takes the number of samples (waveform.shape[-1]), divides by the sample rate to get seconds, and multiplies by 1000 to land in milliseconds, truncated to a whole number.

What you do with duration_ms is the fun part:

  • Sync. Feed it into comparison and routing logic so a video frame count or a clip's length adapts to the audio's duration.
  • Looping. Know the exact length of a sound so you can repeat it a whole number of times.
  • Pacing. Use it as the authoritative value for anything downstream that needs to match the audio length - the same "one authoritative source" idea the node-plumbing layer pushes for values generally.

Three notes so you don't get surprised:

  • The output is milliseconds, truncated - not rounded. A 1.5-second clip reads as 1500, and fractional milliseconds get cut off, not rounded up. If you need precision at sub-millisecond level, this isn't the node.
  • It needs a real AUDIO input. You can't type a number in - this is a wire-in/wire-out node, so whatever produces the audio (a loader, a TTS node, a generation model) has to be upstream.
  • Sample count is the last dimension, so stereo vs mono doesn't change the result - both report the same duration correctly.

Install is pack standard: ComfyUI Manager → search ComfyUI-Practical-Tools → install → restart, or git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools into ComfyUI/custom_nodes. No dependencies, no model downloads, no audio packages to add - it reads whatever the AUDIO dict already contains. If you get a weird number, the usual cause is an audio object that doesn't carry a standard waveform/sample_rate pair; check what's actually connected.

CategoryPractical-Tools/audio

Inputs (1)

NameTypeDefaultDescription
audioAUDIO—

Outputs (1)

NameTypeDescription
duration_msINT—