Nodes/comfyui-audio-processing/Inverse Spectrogram
ComfyUI Node

Inverse Spectrogram

The lossless way back from a spectrogram to real audio

By rhdunn·Created 2 years ago·Updated 2 years ago· 13
Inverse Spectrogram
  • spectrogram
  • AUDIO

If Spectrogram is the pack's forward direction, Inverse Spectrogram is the return trip - and it's the honest one. Feed it a complex spectrogram and it reconstructs the audio with near-perfect fidelity, because nothing was thrown away. That's the whole point of keeping phase around: it turns a one-way analysis into a roundtrip.

How it works

The node calls torchaudio's inverse STFT on the stored spectrogram tensor. The neat part is that it doesn't make you re-enter the FFT settings: the SPECT object you get from Spectrogram carries its own n_fft, win_length, and hop_length metadata, and this node reads them back out. You can't actually misconfigure it even if you try - the settings that built the spectrogram are the settings used to invert it.

There's exactly one input (spectrogram) and exactly one output (AUDIO). Wire that output into ComfyUI core's PreviewAudio to hear it, or into SaveAudio to write a file. The AUDIO it emits is the same standard format as the rest of the ecosystem, so downstream nodes don't care that the audio came from an image of itself.

The one rule: it must be complex

This node raises an exception if the spectrogram isn't complex-typed. That's not a bug, it's the math being honest with you. The power and magnitude modes of Spectrogram discard phase information, and without phase there is no exact inverse - the problem is underdetermined. If you have a magnitude or power spectrogram, your options are Griffin Lim (estimates phase iteratively, lossy) or going back and re-computing with stype set to complex.

So the practical workflow is: set stype = "complex" on Spectrogram, run it through whatever analysis or modification you want, and inverse it here for a lossless result. Under the defaults - n_fft 400, hop 100 - the roundtrip is essentially bit-perfect-sounding; you won't hear the difference.

Where people get burned

The classic mistake is running Apply Filter Bank between Spectrogram and this node and expecting audio back. Filtering doesn't change the metadata - the SPECT still claims the original n_fft - but it does change the frequency axis from n_fft/2+1 bins to however many filter bins you used. The inverse then gets a tensor whose shape doesn't match what the STFT inverse expects, and it errors (or worse, produces garbage if the shapes happen to line up). The filter-bank path is for analysis and plotting; for audio out, keep your complex spectrogram untouched.

Installing

Same as the rest of the pack - ComfyUI Manager, search "comfyui-audio-processing", or:

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

restart, done. No requirements to install, no models to download, since torchaudio ships with ComfyUI.

Categoryaudio processing/spectrogram

Inputs (1)

NameTypeDefaultDescription
spectrogramSPECT

Outputs (1)

NameTypeDescription
AUDIOAUDIO