Comfy-Org/ComfyUI · error · ValueError
Input audio must have {expected_channels} channels, got {wav
Error message
Input audio must have {expected_channels} channels, got {waveform.shape[1]} What it means
The audio VAE encoder has a fixed channel count (self.autoencoder.encoder.in_channels, typically 2 for stereo). A mono waveform is auto-expanded, but anything with a different channel count (3+, or 0) is rejected because the mel preprocessor would produce a malformed spectrogram.
Source
Thrown at comfy/ldm/lightricks/vae/audio_vae.py:148
self.preprocessor = AudioPreprocessor(
target_sample_rate=autoencoder_config["sampling_rate"],
mel_bins=autoencoder_config["mel_bins"],
mel_hop_length=autoencoder_config["mel_hop_length"],
n_fft=autoencoder_config["n_fft"],
)
def encode(self, audio, sample_rate=44100) -> torch.Tensor:
"""Encode a waveform dictionary into normalized latent tensors."""
waveform = audio
waveform_sample_rate = sample_rate
input_device = waveform.device
expected_channels = self.autoencoder.encoder.in_channels
if waveform.shape[1] != expected_channels:
if waveform.shape[1] == 1:
waveform = waveform.expand(-1, expected_channels, *waveform.shape[2:])
else:
raise ValueError(
f"Input audio must have {expected_channels} channels, got {waveform.shape[1]}"
)
mel_spec = self.preprocessor.waveform_to_mel(
waveform, waveform_sample_rate, device=waveform.device
)
latents = self.autoencoder.encode(mel_spec)
posterior = DiagonalGaussianDistribution(latents)
latent_mode = posterior.mode()
normalized = self.normalizer.normalize(latent_mode)
return normalized.to(input_device)
def decode(self, latents: torch.Tensor) -> torch.Tensor:
"""Decode normalized latent tensors into an audio waveform."""
original_shape = latents.shape
View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Convert to stereo first: waveform.convert(2) via torchaudio or torch.mean/tile to 2 channels
- Mono is fine as-is (auto-expanded); only other counts fail
- Check the tensor is (B, C, T) — transpose if you built (B, T, C)
Example fix
# before latents = audio_vae.encode(waveform_6ch) # 6 channels -> ValueError # after waveform_2ch = waveform_6ch[:, :2] # or downmix latents = audio_vae.encode(waveform_2ch)
Defensive patterns
Strategy: validation
Validate before calling
C = waveform.shape[1] expected = audio_vae.autoencoder.encoder.in_channels assert C == 1 or C == expected, (C, expected)
Type guard
def audio_channels_ok(waveform: torch.Tensor, expected: int) -> bool:
return waveform.dim() >= 2 and waveform.shape[1] in (1, expected) Prevention
- Downmix/convert to stereo before encode
- Verify tensor layout is (B, C, T) at the loader boundary
When it happens
Trigger: vae.encode(waveform) where waveform is (B, C, T) with C not in {1, expected_channels}; e.g. passing 5.1 audio (6ch), or a tensor laid out (B, T, C) so the channel axis is misread.
Common situations: Loading multichannel files, wrong tensor layout from a custom loader, or batching audio with a channels-first vs channels-last mismatch.
Related errors
- Unsupported spatial_scale {scale}. Choose from {list(mapping
- Unsupported audio_channels: {audio_channels}
- Vocoder is missing upsample_factor; cannot infer output samp
- {cls.__name__} does not have a NONE member to map None to
- Invalid {cls.__name__} string: '{value}'. Valid values are:
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/6a38194981bc018c.
Report an issue: GitHub.