Comfy-Org/ComfyUI · error · ValueError

Unsupported wav dtype: {wav.dtype}

Error message

Unsupported wav dtype: {wav.dtype}

What it means

_f32_pcm normalizes an audio waveform tensor to float32 PCM: floating dtypes pass through, int16 divides by 2^15, int32 by 2^31. Any other dtype (int8, uint8, int64, or exotic quantized types) has no defined scale and raises ValueError naming the dtype.

Source

Thrown at comfy_api_nodes/util/conversions.py:568

        return InputImpl.VideoFromFile(output_buffer)

    except Exception as e:
        if input_container is not None:
            input_container.close()
        if output_container is not None:
            output_container.close()
        raise RuntimeError(f"Failed to resize video: {str(e)}") from e


def _f32_pcm(wav: torch.Tensor) -> torch.Tensor:
    """Convert audio to float 32 bits PCM format. Copy-paste from nodes_audio.py file."""
    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 audio_bytes_to_audio_input(audio_bytes: bytes) -> dict:
    """
    Decode any common audio container from bytes using PyAV and return
    a Comfy AUDIO dict: {"waveform": [1, C, T] float32, "sample_rate": int}.
    """
    with av.open(BytesIO(audio_bytes)) as af:
        if not af.streams.audio:
            raise ValueError("No audio stream found in response.")
        stream = af.streams.audio[0]

        in_sr = int(stream.codec_context.sample_rate)
        out_sr = in_sr

        frames: list[torch.Tensor] = []
        n_channels = stream.channels or 1

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Re-encode the audio to a standard format first: ffmpeg -i in.wav -ar 44100 -c:a pcm_s16le out.wav.
  2. If you build the tensor yourself, convert to float32 (or int16) before passing it in.
  3. Upgrade PyAV — newer versions map more sample formats to int16/int32/float32 cleanly.
  4. As a library maintainer, add int8/uint8 branches scaling by 2^7/2^8-1 if the source format is required.

Example fix

// before
wav = torch.from_numpy(arr)          # uint8 from pcm_u8
wav = _f32_pcm(wav)                   # raises

// after
if wav.dtype == torch.uint8:
    wav = (wav.float() - 128.0) / 128.0
else:
    wav = _f32_pcm(wav)
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = (torch.float16, torch.bfloat16, torch.float32, torch.float64, torch.int16, torch.int32)
if wav.dtype not in SUPPORTED:
    wav = wav.to(torch.float32) / 32768.0  # or re-source the audio

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)

Prevention

When it happens

Trigger: audio_bytes_to_audio_input decoding an audio stream whose sample format maps to an unsupported numpy dtype (e.g. uint8 pcm_u8 or int64 planar audio from an unusual codec), then calling _f32_pcm on the concatenated tensor.

Common situations: 8-bit WAV files (pcm_u8 -> uint8), 24-bit packed audio decoded oddly, or a codec/PyAV version whose to_ndarray output dtype changed. Very rare with mainstream mp3/aac/wav-float/int16 sources.

Related errors


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