{"record":{"id":"6bcc7590e0db6126","repo":"Comfy-Org/ComfyUI","slug":"unsupported-wav-dtype-wav-dtype-6bcc75","errorCode":null,"errorMessage":"Unsupported wav dtype: {wav.dtype}","messagePattern":"Unsupported wav dtype: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_audio.py","lineNumber":331,"sourceCode":"\n    @classmethod\n    def execute(cls, audio) -> IO.NodeOutput:\n        if audio is None:\n            raise ValueError(\"PreviewAudio: input audio is None (source video may have no audio track).\")\n        return IO.NodeOutput(audio, ui=UI.PreviewAudio(audio, cls=cls))\n\n    save_flac = execute  # TODO: remove\n\n\ndef f32_pcm(wav: torch.Tensor) -> torch.Tensor:\n    \"\"\"Convert audio to float 32 bits PCM format.\"\"\"\n    if wav.dtype.is_floating_point:\n        return wav\n    elif wav.dtype == torch.int16:\n        return wav.float() / (2 ** 15)\n    elif wav.dtype == torch.int32:\n        return wav.float() / (2 ** 31)\n    raise ValueError(f\"Unsupported wav dtype: {wav.dtype}\")\n\ndef load(filepath: str) -> tuple[torch.Tensor, int]:\n    with av.open(filepath) as af:\n        if not af.streams.audio:\n            raise ValueError(\"No audio stream found in the file.\")\n\n        stream = af.streams.audio[0]\n        sr = stream.codec_context.sample_rate\n        n_channels = stream.channels\n\n        frames = []\n        length = 0\n        for frame in af.decode(streams=stream.index):\n            buf = torch.from_numpy(frame.to_ndarray())\n            if buf.shape[0] != n_channels:\n                buf = buf.view(-1, n_channels).t()\n\n            frames.append(buf)","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_audio.py#L313-L349","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-encode the file to 16-bit or 32-bit PCM WAV (ffmpeg -c:a pcm_s16le) before loading","If calling f32_pcm directly, pre-convert the tensor: wav.int16() or wav.to(torch.int16) / wav.float()","Extend f32_pcm with an explicit branch for the dtype you actually need (with correct scaling) rather than relying on the generic path"],"exampleFix":"// before\nwav = f32_pcm(raw)  # raw is uint8\n\n// after\nwav = (raw.float() - 128.0) / 128.0  # explicit u8 -> f32\n# or re-encode source: ffmpeg -i in.wav -c:a pcm_s16le out.wav","handlingStrategy":"type-guard","validationCode":"SUPPORTED = lambda d: d.is_floating_point or d in (torch.int16, torch.int32)\nif not SUPPORTED(wav.dtype):\n    wav = wav.to(torch.int16)  # or float()","typeGuard":"def is_supported_pcm_dtype(wav: torch.Tensor) -> bool:\n    return wav.dtype.is_floating_point or wav.dtype in (torch.int16, torch.int32)","tryCatchPattern":"try:\n    wav = f32_pcm(wav)\nexcept ValueError as e:\n    if 'Unsupported wav dtype' in str(e):\n        wav = wav.float() / (2 ** (wav.element_size() * 8 - 1))\n    else:\n        raise","preventionTips":["Re-encode sources to pcm_s16le/pcm_f32le before loading","Convert tensors to int16/float before calling f32_pcm","Check wav.dtype against the supported set at your decode boundary"],"tags":["audio","dtype","pcm","decode"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}