Nodes/Quality of Life Nodes for ComfyUI/JSON Audio Encoder (Soze)
ComfyUI Node

JSON Audio Encoder (Soze)

AUDIO to a JSON-friendly string, with no key attached

By SozeInc·Created 2 years ago·Updated 8 days ago· 10
JSON Audio Encoder (Soze)
  • audio
  • encoded
modedata_uri
save_path
append_suffixtrue

Sometimes the audio doesn't need a name in a JSON object - it just needs to become a string you can drop anywhere text is accepted. JSON Audio Encoder (Soze) is the standalone version of the audio encoding core: ComfyUI AUDIO in, one STRING out, no name, no chain. Wire the result into a JSON Chain String Pair's value socket, an API parameter, or any text slot that happens to want a data URI or a file path.

It encodes the first frame of the AUDIO batch - the array pair variant covers the rest. If you've used the JSON Image Encoder, this is the same idea with MP3 instead of PNG, and the same data_uri/filepath trade-off to think about.

How it works

The first frame is encoded to MP3 through torchaudio.save, which needs torchaudio with its ffmpeg backend (ComfyUI normally ships it). Then it's presented one of two ways:

  • data_uri (default) - data:audio/mpeg;base64,.... Self-contained; MP3 compression keeps it reasonably small.
  • filepath - writes an .mp3 to disk (relative to ComfyUI's output dir, or absolute) and returns the path. .mp3 is added if missing; append_suffix (default true) appends _00001 if the target exists.

Inputs and outputs

  • audio - required AUDIO input (forced). First frame used.
  • mode - data_uri or filepath.
  • save_path, append_suffix - optional filepath-mode controls.

Output: encoded, a single STRING.

Installing it

Part of the Soze pack:

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

Restart ComfyUI, or search ComfyUI_Soze in ComfyUI Manager. torchaudio is in the pack's requirements.

Gotchas

The dependency that bites is the ffmpeg backend for MP3 encoding - if you see "MP3 encoding failed" style errors, that's torchaudio missing its backend, not the node. Fix it by making sure ffmpeg is installed and torchaudio is >= 2.1. Also worth remembering the output is always MP3; the decoder, by contrast, reads whatever torchaudio can load (WAV, FLAC, OGG, M4A, AAC included). So this encoder is a great normalizer: whatever format your audio arrives in, it comes out the other side as a standard MP3 string.

CategorySoze Nodes/JSON

Inputs (4)

NameTypeDefaultDescription
audioAUDIO
modeCOMBOdata_uri2 options: data_uri, filepath
save_pathoptSTRING
append_suffixoptBOOLEANtrue

Outputs (1)

NameTypeDescription
encodedSTRING