ComfyUI Node

Spectrogram

Turn audio into the picture of sound ComfyUI can actually process

By rhdunn·Created 2 years ago·Updated 2 years ago· 13
Spectrogram
  • audio
  • SPECT
stypepower
n_fft400
win_length-1
hop_length-1

If you've ever seen a "spectrogram art" workflow - the Riffusion stuff where a diffusion model paints a spectrogram and someone plays it back - this is the node that gets you the raw material. Spectrogram takes a plain AUDIO object and turns it into a frequency-over-time image that the rest of this pack (and your imagination) can work on. It's the front door of the whole comfyui-audio-processing pack.

How it works

Under the hood it's a short-time Fourier transform (STFT) via PyTorch's torchaudio - a sliding window slides across the waveform, an FFT runs on each chunk, and you get a 2D grid: frequency bins on one axis, time frames on the other. torchaudio is already a dependency of ComfyUI itself, so this node costs you nothing extra to run.

The stype input decides what comes out:

  • power (default) - the squared magnitude, |STFT|². The classic "spectrogram" look and the thing most analysis models eat.
  • magnitude - the plain absolute value. Half the dynamic range of power, handy if you want to eyeball quieter detail.
  • complex - the full complex-number result, phase and all. This is the only one that can be inverted losslessly back to audio with Inverse Spectrogram. The others have thrown away phase, so going back means guessing it (that's what Griffin Lim is for).

The other three inputs only matter when you start caring about resolution. n_fft (default 400) is the FFT window size: bigger = finer frequency resolution, coarser time resolution. win_length and hop_length default to -1, which is the code's way of saying "let torchaudio pick" - win = n_fft, hop = n_fft/4. Set hop_length lower for a denser time axis; leave it alone unless you know why you're changing it.

Wiring it

The output is a SPECT object - a dict holding the spectrogram tensor plus its sample rate, stype, and the FFT settings used. That last bit is the pack's clever bit: the metadata rides along, so the inverse nodes know exactly how to undo it. SPECT feeds Plot Spectrogram, the two filter-bank builders, and the two "back to audio" nodes. You feed it AUDIO from ComfyUI's built-in Load Audio, this pack's Load Audio From Path, or any video node that outputs audio.

Installing

One release, zero fuss:

cd ComfyUI/custom_nodes
git clone https://github.com/rhdunn/comfyui-audio-processing

then restart ComfyUI. Or just search "comfyui-audio-processing" in ComfyUI Manager and hit install. There's no requirements.txt and no model to download - the pack leans entirely on torchaudio and matplotlib, which ComfyUI already ships. That's the whole install.

Gotchas

The -1 defaults are the main trap: they look like errors, they're actually "auto". If you hand the resulting SPECT to Inverse Spectrogram or Griffin Lim, they inherit those same -1 values and resolve them identically, so the roundtrip lines up. Where people get burned: choosing power or magnitude and then trying to use Inverse Spectrogram - that node refuses non-complex input with an exception. Want a perfect roundtrip, keep complex. Don't care about phase, use the cheaper real-valued modes and Griffin Lim on the way back.

Categoryaudio processing/spectrogram

Inputs (5)

NameTypeDefaultDescription
audioAUDIO
stypeoptCOMBOpower3 options: complex, magnitude, power
n_fftoptINT4001–4294967296
win_lengthoptINT-1-1–4294967296
hop_lengthoptINT-1-1–4294967296

Outputs (1)

NameTypeDescription
SPECTSPECT