Comfy-Org/ComfyUI · error · ValueError
Unsupported audio format: {format!r}
Error message
Unsupported audio format: {format!r} What it means
AudioSaveHelper.save_audio (comfy_api/latest/_ui.py) writes audio with soundfile/ffmpeg-backed encoders and only accepts formats in {'flac','mp3','opus'} as defined by the class-level _FORMATS set. Any other format string ('wav', 'aac', 'ogg'…) fails an explicit allowlist check before any file IO.
Source
Thrown at comfy_api/latest/_ui.py:275
return SavedImages([result], is_animated=len(images) > 1)
class AudioSaveHelper:
"""A helper class with static methods to handle audio saving and metadata."""
_OPUS_RATES = [8000, 12000, 16000, 24000, 48000]
_FORMATS = {"flac", "mp3", "opus"}
@staticmethod
def save_audio(
audio: dict,
filename_prefix: str,
folder_type: FolderType,
cls: type[ComfyNode] | None,
format: str = "flac",
quality: str = "128k",
) -> list[SavedResult]:
if format not in AudioSaveHelper._FORMATS:
raise ValueError(f"Unsupported audio format: {format!r}")
full_output_folder, filename, counter, subfolder, _ = folder_paths.get_save_image_path(
filename_prefix, _get_directory_by_folder_type(folder_type)
)
metadata = {}
if not args.disable_metadata and cls is not None:
if cls.hidden.prompt is not None:
metadata["prompt"] = json.dumps(cls.hidden.prompt)
if cls.hidden.extra_pnginfo is not None:
for x in cls.hidden.extra_pnginfo:
metadata[x] = json.dumps(cls.hidden.extra_pnginfo[x])
results = []
for batch_number, waveform in enumerate(audio["waveform"].cpu()):
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}.{format}"
output_path = os.path.join(full_output_folder, file)View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Use one of the supported formats: 'flac' (lossless default), 'mp3', or 'opus'
- If you maintain the node, keep the format widget list limited to AudioSaveHelper._FORMATS
- Need wav? Save as flac (also lossless) or convert externally after export
Example fix
// before save_audio(audio, prefix, folder_type, cls, format='wav') // after save_audio(audio, prefix, folder_type, cls, format='flac')
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'flac', 'mp3', 'opus'}
if format not in SUPPORTED:
raise ValueError(f'format must be one of {sorted(SUPPORTED)}, got {format!r}') Type guard
def is_supported_audio_format(f) -> bool:
return isinstance(f, str) and f in {'flac', 'mp3', 'opus'} Prevention
- Derive UI format options from AudioSaveHelper._FORMATS so frontend and backend never diverge
- Default to flac for lossless output
When it happens
Trigger: Calling save_audio with a format argument outside {'flac','mp3','opus'} — typically passed straight through from a SaveAudio-style node's format widget or an API request field.
Common situations: Custom nodes extending the format combo with wav/aac without extending _FORMATS; API clients sending arbitrary strings; frontend/backend option lists out of sync after an upgrade.
Related errors
- ERROR: audio encoder file is invalid or unsupported embed_di
- ERROR: audio encoder not supported.
- Minimum cutoff must be larger than zero.
- A cutoff above 0.5 does not make sense.
- Unknown resblock type: {self.resblock}
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/dd2cf41a4d691913.
Report an issue: GitHub.