Nodes/ComfyUI WB Utils/WB Audio Duration
ComfyUI Node

WB Audio Duration

How long is that audio? WB Audio Duration just tells you

By webuilder·Created about a year ago·Updated about a year ago· 0
WB Audio Duration
  • audio
  • duration_seconds
  • duration_text

What it actually is

One input, two outputs, zero dependencies. Feed it an AUDIO tensor and it tells you how many seconds it is. That's the whole node, and for once that's a feature, not a cop-out. WB Audio Duration comes from webuilder's WB-ComfyUI-Utils pack, which right now is essentially this one node plus a README of planned features - the author's framing is a "utility collection," and this is the only piece that's shipped so far.

Why would you need it? Audio in ComfyUI is normally invisible. You load an mp3, a waveform tensor flows through the graph, and nothing in the UI tells you whether it's 3 minutes or 8. If you're timing a lipsync segment, matching an audio loop to a video length, or trying to make a mask schedule line up, you end up checking file properties outside ComfyUI. This node drags that answer into the graph where you actually need it.

How it works

The node takes the AUDIO dict that ComfyUI's Load Audio produces - {"waveform": tensor, "sample_rate": int} - and does the one obvious calculation: num_samples / sample_rate. The tensor handling covers 1D [samples], 2D [channels, samples], and 3D [batch, channels, samples], which is what core Load Audio actually hands you. No ffmpeg, no PyAV, no extra installs; it's pure torch, which ComfyUI already ships. The pack's package.json lists zero dependencies and there's no requirements.txt to trip over.

One honest caveat from reading the source: the 2D branch assumes [channels, samples] and reads shape[1] as the sample count. Feed it a channels-last tensor and the math silently goes wrong. In practice, core Load Audio's 3D output avoids that, but the layout assumption is baked in - worth knowing if you're feeding it from a custom source.

There's also a branch that estimates duration from a raw file path at an assumed 128 kbps bitrate. It's effectively dead code - the AUDIO socket won't let you pass a plain string from the UI - so ignore it.

Inputs and outputs

Only three things matter:

  • audio (AUDIO) - wire this from Load Audio, or anything else that emits AUDIO (VHS's loader works too).
  • duration_seconds (FLOAT) - the runtime as a plain number, e.g. 19.59. Wire it into anything that takes a number: a math node, a scheduling node, a prompt text builder.
  • duration_text (STRING) - the same value pre-formatted. Heads up: the formatting strings are in Chinese, so you get 19.59秒 rather than 19.59s.

Because it's declared as an OUTPUT_NODE, ComfyUI treats it as a terminal result - but a bare FLOAT/STRING output node won't show you anything on its face. The author's own sample workflow wires both outputs into core PreviewAny nodes, and that's the move: drop in a PreviewAny, run, read the number.

Installing it

ComfyUI Manager is the easy path - search "WB Utils" or "WB Audio Duration" and hit install. Or clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/webuilder/WB-ComfyUI-Utils

Then restart ComfyUI. No models to download, no Python dependencies to fight over - a genuinely pleasant change in an ecosystem where, as the comfyui-ecosystem notes, "installing missing nodes" is the community's biggest daily complaint. This one just works.

Gotchas

  • It's an output node. It'll still execute if you wire duration_seconds further down the graph, but the clean way to read the result is a PreviewAny.
  • duration_text comes out with Chinese unit labels. If a downstream text node mangles that or you want English, use duration_seconds and format it yourself.
  • Debug spam: the node prints a full trace of shape and calculation to the console on every run. Harmless, occasionally useful.

Honestly, for a one-input node this is as painless as ComfyUI gets. If you've ever sat there wondering how long the audio you just loaded actually is, this is the fix - and it's a two-minute install.

Categoryaudio

Inputs (1)

NameTypeDefaultDescription
audioAUDIO

Outputs (2)

NameTypeDescription
duration_secondsFLOAT
duration_textSTRING