Nodes/More Math/Audio -> Spectrogram
ComfyUI Node

Audio -> Spectrogram

Turn audio into an image you can actually look at

By mcDandy·Created about a year ago·Updated 3 days ago· 5
Audio -> Spectrogram
  • audio
  • image
  • Channel count
  • Sample rate
window_length1024
hop_length256
bucket_count513
window_typehann

If you've ever loaded an audio file into a generative image workflow, you know the problem: there's no stock node that turns sound into pixels. Audio -> Spectrogram from More Math is that missing converter. It takes an audio tensor, runs an STFT (short-time Fourier transform), and paints the result as an image - which you can preview, feed into an image model, or use as the visual spine of an audio-to-image pipeline.

How it works

The node is honest about what it's doing: it computes a spectrogram via torch.stft and stacks the result into an RGB image where Red = the real part, Green = the log magnitude (deliberately, "just so it looks good"), and Blue = the imaginary part. Each audio channel stacks vertically in the output, so a stereo track becomes two stacked bands. Because it's a real STFT, the image isn't just a pretty picture - it's an invertible-ish representation, and the pack pairs it with a SpectrogramToAudio node to go back the other way.

You control the analysis with the parameters: window_length (default 1024 samples), hop_length (256 - the window stride, so smaller hop = more time resolution), bucket_count (513 - the frequency resolution), and window_type (hann, hamming, blackman, kaiser, or bartlett).

Inputs and outputs

One required input, audio (the AUDIO tensor). Outputs are image (the spectrogram), channel_count (how many channels ended up stacked), and sample_rate - both handy metadata if you're routing this into a save node or building a lossless round-trip.

Installing it

Same as every node in the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt

Restart ComfyUI, or install "More math" from ComfyUI Manager. Only dependency beyond torch is antlr4-python3-runtime. No model files.

Practical notes

The defaults are sensible for music-ish audio; lower hop_length for sharper time detail, raise bucket_count for sharper frequency detail - there's a resolution tradeoff between the two, and both are capped at 4096. One thing that surprises people: the green channel is log-magnitude, so the image won't look like a "normal" spectrogram until you remember the color mapping. And this isn't a semantic feature extractor - it's a faithful transform, so don't expect the image model to "understand" it as music. For audio-driven generation (feeding a spectrogram into img2img, or conditioning on an audio-derived visual), it's a genuinely useful bridge that the stock nodes never shipped. New pack, solo-maintained, but this one's small, well-scoped, and has held up in the pack's own example workflows.

CategoryMore math

Inputs (5)

NameTypeDefaultDescription
audioAUDIOInput audio
window_lengthINT102416–4096Window length in samples
hop_lengthINT2561–4096Stride of the window (hop length) in samples
bucket_countINT5132–4096Number of frequency buckets (determines resolution)
window_typeCOMBOhannType of window function to apply

Outputs (3)

NameTypeDescription
imageIMAGE
Channel countINTNumber of channels in the output image
Sample rateINTSample rate of the input audio