Nodes/SongBloom_ComfyUI/SongBloom Audio Ensure2D
ComfyUI Node

SongBloom Audio Ensure2D

The shape-fixer that stops 'Dimension out of range' before it happens

By xuchenxu168·Created 12 months ago·Updated 10 months ago· 15
SongBloom Audio Ensure2D
  • audio
  • audio
  • info

Audio tensors in ComfyUI are supposed to be 2D - (channels, samples). In practice they show up as 1D, 3D, lists, numpy arrays, and sometimes stranger things, because every pack that produces audio has opinions about shape. And the downstream node (usually a saver or the torchaudio.save call inside it) will happily throw a "Dimension out of range" error at you for it. This node exists to never let that happen.

That's the entire job: take whatever you feed it and guarantee the output is a 2D (channels, samples) tensor, moved to CPU, contiguous, and ready for anything that expects the standard shape. The author's own description in the README is the best summary - it "normalizes any 0D/1D/3D/list/ndarray down to 2D (channels, samples)" and is recommended before using a non-pack save node.

How it works

It's tolerant by design, in a specific order: it verifies the input is a proper AUDIO dict (waveform + sample_rate), then coerces whatever the waveform actually is - numpy array to tensor, list to tensor, 3D squeezed, 1D given a channel dimension - until it lands on the canonical 2D shape. Garbage that can't be coerced (like a bare scalar) degrades to a minimal silence sample rather than a crash. Then it reports what it did.

Inputs and outputs

  • audio (required) - any AUDIO you're worried about.
  • Output audio (AUDIO) - the normalized 2D version.
  • Output info (STRING) - the shape before and after, so you can actually see what was wrong.

The honest use case: splice it between a non-SongBloom audio source and a non-SongBloom saver. If you're using this pack's own nodes end-to-end, most of them already normalize internally (the cropper, the prompt node, the generator all handle shapes defensively). Where Ensure2D earns its keep is the boundary - the moment your audio crosses from this pack into someone else's save node, or the reverse, this is cheap insurance.

Install

Same as the whole pack:

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

ComfyUI Manager: search "SongBloom_ComfyUI". Restart and it's under SongBloom/Audio. No model files, no GPU, no dependencies beyond the pack itself. It's a 30-second node to add and it only ever runs when a shape problem would have bitten you - the definition of a good utility.

CategorySongBloom/Audio

Inputs (1)

NameTypeDefaultDescription
audioAUDIO

Outputs (2)

NameTypeDescription
audioAUDIO
infoSTRING