Comfy-Org/ComfyUI · error · ValueError

Unsupported wav dtype: {wav.dtype}

Error message

Unsupported wav dtype: {wav.dtype}

What it means

f32_pcm converts decoded audio tensors to float32 PCM and supports only floating dtypes plus int16 and int32. Any other integer width (e.g. int8, uint8, int24 packed oddly, or int64) raises this error because no defined scaling exists for it.

Source

Thrown at comfy_extras/nodes_audio.py:331

    @classmethod
    def execute(cls, audio) -> IO.NodeOutput:
        if audio is None:
            raise ValueError("PreviewAudio: input audio is None (source video may have no audio track).")
        return IO.NodeOutput(audio, ui=UI.PreviewAudio(audio, cls=cls))

    save_flac = execute  # TODO: remove


def f32_pcm(wav: torch.Tensor) -> torch.Tensor:
    """Convert audio to float 32 bits PCM format."""
    if wav.dtype.is_floating_point:
        return wav
    elif wav.dtype == torch.int16:
        return wav.float() / (2 ** 15)
    elif wav.dtype == torch.int32:
        return wav.float() / (2 ** 31)
    raise ValueError(f"Unsupported wav dtype: {wav.dtype}")

def load(filepath: str) -> tuple[torch.Tensor, int]:
    with av.open(filepath) as af:
        if not af.streams.audio:
            raise ValueError("No audio stream found in the file.")

        stream = af.streams.audio[0]
        sr = stream.codec_context.sample_rate
        n_channels = stream.channels

        frames = []
        length = 0
        for frame in af.decode(streams=stream.index):
            buf = torch.from_numpy(frame.to_ndarray())
            if buf.shape[0] != n_channels:
                buf = buf.view(-1, n_channels).t()

            frames.append(buf)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Re-encode the file to 16-bit or 32-bit PCM WAV (ffmpeg -c:a pcm_s16le) before loading
  2. If calling f32_pcm directly, pre-convert the tensor: wav.int16() or wav.to(torch.int16) / wav.float()
  3. Extend f32_pcm with an explicit branch for the dtype you actually need (with correct scaling) rather than relying on the generic path

Example fix

// before
wav = f32_pcm(raw)  # raw is uint8

// after
wav = (raw.float() - 128.0) / 128.0  # explicit u8 -> f32
# or re-encode source: ffmpeg -i in.wav -c:a pcm_s16le out.wav
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED = lambda d: d.is_floating_point or d in (torch.int16, torch.int32)
if not SUPPORTED(wav.dtype):
    wav = wav.to(torch.int16)  # or float()

Type guard

def is_supported_pcm_dtype(wav: torch.Tensor) -> bool:
    return wav.dtype.is_floating_point or wav.dtype in (torch.int16, torch.int32)

Try / catch

try:
    wav = f32_pcm(wav)
except ValueError as e:
    if 'Unsupported wav dtype' in str(e):
        wav = wav.float() / (2 ** (wav.element_size() * 8 - 1))
    else:
        raise

Prevention

When it happens

Trigger: load() decodes a file whose codec outputs a planar/sample format that maps to a torch dtype outside {float*, int16, int32} — e.g. 8-bit PCM, 24-bit packed, or u8 via frame.to_ndarray(). Also directly calling f32_pcm on a raw tensor of unsupported dtype.

Common situations: Loading exotic WAV variants (8-bit unsigned, 24-bit) or codecs whose PyAV to_ndarray conversion yields unusual dtypes after tensor view/transpose operations reshape the buffer.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/6bcc7590e0db6126. Report an issue: GitHub.