Spectrogram -> Audio
Resynthesize audio from a spectrogram image, no black magic required
- image
- audio
This is the reverse half of the audio pipeline in the More Math pack: it turns a spectrogram image back into real audio. Its sibling, Audio -> Spectrogram, encodes an audio clip's frequency content into an image's RGB channels; this node takes that image (or an image you made yourself) and runs an inverse short-time Fourier transform to reconstruct the waveform. If you want to see your audio, edit it as pixels, and hear the result, this closes the loop.
How it works
The color channels carry the signal, and the encoding is specific:
- Red (R) = real part of the STFT
- Green (G) = magnitude - used for display, ignored on the way back
- Blue (B) = imaginary part
On decode, the node reshapes the image rows into frequency buckets (bucket_count = height / channel_count), computes the FFT size as (bucket_count - 1) * 2, and calls torch.istft to rebuild the waveform. The choice of window function matters because the inverse transform has to match the forward one you used to make the spectrogram in the first place.
The inputs that matter
image- the spectrogram image (R=real, G=magnitude, B=imaginary). Required.sample_rate- output sample rate, default 44100. Standard audio is 44100 or 48000.window_length- FFT window size in samples, default 1024.hop_length- window stride, default 256.channel_count- mono (1) to stereo (2) and beyond, default 1.window_type-bartlett,blackman,hamming,hann(default), orkaiser.
Output is an AUDIO tensor you can feed into an audio save/play node or an AudioMathNode for further processing.
Installing it
It's part of More Math (mcDandy/more_math). Easiest via ComfyUI Manager - search "More Math". Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt
Restart ComfyUI. Dependencies are just antlr4-python3-runtime and torch - no audio libraries, no downloads. Do make sure ComfyUI is current; the pack is built on the newer node API.
Where people get burned
The classic mistake is mismatched parameters. If you created the spectrogram with window_length 1024 and hop_length 256 and then decode with different values, you get pitched, warped, or garbled audio - the STFT and iSTFT parameters have to agree on both sides. Keep them in lockstep.
Second, garbage in, garbage out. The spectrogram format is specific (R=real, B=imaginary). Drop in a normal RGB image that wasn't created as a spectrogram and you'll get noise, because there's no valid phase information in it. If your goal is procedural sound, you can build a valid one with the pack's image/audio math nodes - but you're taking on the STFT semantics yourself.
Third, channel_count and image height interact: the bucket count is derived from height / channel_count, so if that division isn't clean you'll get shapes that don't reconstruct. Keep mono unless you know the source was stereo. This is a niche node - it exists to complete the pack's audio-in-image trick, and it's genuinely cool for editing sound as pictures, but for everyday audio you'll reach for the standard audio save nodes instead.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input spectrogram image (R=Real, G=Magnitude, B=Imaginary) | |
| channel_count | INT | 1 | Number of audio channels |
| sample_rate | INT | 44100 | Sample rate of the output audio |
| window_length | INT | 1024 | Window length in samples |
| hop_length | INT | 256 | Stride of the window (hop length) in samples |
| window_type | COMBO | hann | Type of window function to apply |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| audio | AUDIO | Output audio |