Nodes/Audio to Spectrogram/Audio to Spectrogram
ComfyUI Node

Audio to Spectrogram

Turn any audio into a spectrogram image without leaving the graph

By bemoregt·Created 7 months ago·Updated 7 months ago· 4
Audio to Spectrogram
  • audio
  • spectrogram
use_meltrue
n_fft2048
hop_length512
win_length2048
n_mels128
fmin0
fmax8000
colormapinferno
width1024
height512
show_axestrue

Ever loaded a clip and wondered what's actually in it - where the transients are, whether it's got a noise floor, how much silence is hiding at the tail? That's what this node is for. It takes ComfyUI's native AUDIO type and renders it as a spectrogram image you can preview, save, or even feed right back into an image workflow. No API calls, no keys, no model downloads - it's pure signal processing plus a matplotlib render.

It's a small, single-purpose pack (this is its one node), and honestly that's fine. When you want a spectrogram in the graph, you want exactly this.

How it works

The node grabs waveform and sample_rate from the AUDIO tensor, squashes multi-channel audio down to mono, then runs a short-time Fourier transform. With use_mel on (the default) it builds a Mel spectrogram - the human-perception-friendly frequency scale, and the same representation text-to-music models like FluxMusic and MusicGen live in. With it off, you get a plain linear (STFT) spectrogram. Either way the result is power-scaled to decibels and clipped to the top 80 dB of dynamic range, which is the difference between "pretty picture" and "actually readable."

The rendering step is worth knowing about: it draws the array with matplotlib (headless Agg backend) into an in-memory PNG, then Pillow converts and resizes that to your requested dimensions. So the output is a rendered image - axes, colorbar, title and all - not a raw STFT tensor. If you need the actual numbers, this isn't the node for that.

The inputs that matter

Most of the 13 inputs you can leave alone. The ones you'll actually touch:

  • use_mel - Mel vs. linear. Mel reads better to human eyes and is what you want for anything music-related; linear is better for looking at pure tone structure.
  • fmax - top of the frequency axis. Default 8000 Hz is fine for speech. Set it to 0 and it auto-snapshots to Nyquist (sample_rate / 2), per the tooltip.
  • colormap - inferno, magma, viridis, plasma, hot, cool, or gray. Purely aesthetics; inferno is the classic.
  • show_axes - axes, colorbar, and title on or off. Flip it off when you want a clean image.
  • n_fft / hop_length - FFT window size and frame hop. Defaults (2048/512) give good frequency detail with 75% overlap; smaller n_fft trades frequency resolution for time resolution.

The output is a single spectrogram IMAGE, shape [1, H, W, 3], float32 in [0, 1] - the standard ComfyUI image format, so it plugs straight into Preview Image, Save Image, or anything that takes an image. Wire it into a diffusion model and you've got image-from-audio conditioning; that's a legitimate trick in the FluxMusic-adjacent world where music is generated in mel-spectrogram space.

How to install it

Through ComfyUI Manager, search "Audio to Spectrogram" and install. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/bemoregt/ComfyUI_Spectrogram
cd ComfyUI_Spectrogram
pip install torchaudio matplotlib Pillow

Restart ComfyUI and it shows up under the audio category. Dependencies are light: torch, matplotlib, Pillow, numpy - the last three are installed by the command above because ComfyUI's bundled env doesn't ship matplotlib. The pack declares torchaudio as optional-but-recommended.

Where people get burned

Skip torchaudio and use_mel silently does nothing. This is the big one. Without torchaudio the node falls back to a hand-rolled NumPy STFT loop that ignores use_mel, n_mels, fmin, and fmax entirely - you get a linear spectrogram no matter what you set. It also chugs in pure Python, so a long clip renders noticeably slower. If you install nothing else, install torchaudio.

The README's folder name is wrong. The install tree in the README shows CustomNode_Bispectrum/ - a copy-paste leftover from the author's sibling project. Keep the folder named ComfyUI_Spectrogram (or whatever git clone makes it); ComfyUI keys the import off that name, so a renamed folder won't register the node.

It's a picture, not data. Because everything renders through matplotlib, resolution is fixed by width/height regardless of clip duration, and the time axis just squishes. For a visual check that's perfect; for exporting actual spectrogram arrays you'd want a torchaudio-backed node instead.

For what it is - a quick, honest look at any audio file inside ComfyUI - this node does the job with zero fuss. If it's a trap, it's only the torchaudio one.

Categoryaudio

Inputs (12)

NameTypeDefaultDescription
audioAUDIO
use_melBOOLEANtrue
n_fftINT2048256–8192
hop_lengthINT51264–2048
win_lengthINT2048256–8192
n_melsINT12832–512
fminFLOAT00–8000
fmaxFLOAT80000–240000 = Nyquist (sample_rate / 2)
colormapCOMBOinferno7 options: inferno, magma, viridis, plasma, hot, cool, +1
widthINT1024256–4096
heightINT512128–4096
show_axesBOOLEANtrue

Outputs (1)

NameTypeDescription
spectrogramIMAGE