{"record":{"id":"fc514e7b3a3199cc","repo":"Comfy-Org/ComfyUI","slug":"unsupported-wav-dtype-wav-dtype","errorCode":null,"errorMessage":"Unsupported wav dtype: {wav.dtype}","messagePattern":"Unsupported wav dtype: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/conversions.py","lineNumber":568,"sourceCode":"        return InputImpl.VideoFromFile(output_buffer)\n\n    except Exception as e:\n        if input_container is not None:\n            input_container.close()\n        if output_container is not None:\n            output_container.close()\n        raise RuntimeError(f\"Failed to resize video: {str(e)}\") from e\n\n\ndef _f32_pcm(wav: torch.Tensor) -> torch.Tensor:\n    \"\"\"Convert audio to float 32 bits PCM format. Copy-paste from nodes_audio.py file.\"\"\"\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\n\ndef audio_bytes_to_audio_input(audio_bytes: bytes) -> dict:\n    \"\"\"\n    Decode any common audio container from bytes using PyAV and return\n    a Comfy AUDIO dict: {\"waveform\": [1, C, T] float32, \"sample_rate\": int}.\n    \"\"\"\n    with av.open(BytesIO(audio_bytes)) as af:\n        if not af.streams.audio:\n            raise ValueError(\"No audio stream found in response.\")\n        stream = af.streams.audio[0]\n\n        in_sr = int(stream.codec_context.sample_rate)\n        out_sr = in_sr\n\n        frames: list[torch.Tensor] = []\n        n_channels = stream.channels or 1\n","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/conversions.py#L550-L586","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-encode the audio to a standard format first: ffmpeg -i in.wav -ar 44100 -c:a pcm_s16le out.wav.","If you build the tensor yourself, convert to float32 (or int16) before passing it in.","Upgrade PyAV — newer versions map more sample formats to int16/int32/float32 cleanly.","As a library maintainer, add int8/uint8 branches scaling by 2^7/2^8-1 if the source format is required."],"exampleFix":"// before\nwav = torch.from_numpy(arr)          # uint8 from pcm_u8\nwav = _f32_pcm(wav)                   # raises\n\n// after\nif wav.dtype == torch.uint8:\n    wav = (wav.float() - 128.0) / 128.0\nelse:\n    wav = _f32_pcm(wav)","handlingStrategy":"validation","validationCode":"SUPPORTED = (torch.float16, torch.bfloat16, torch.float32, torch.float64, torch.int16, torch.int32)\nif wav.dtype not in SUPPORTED:\n    wav = wav.to(torch.float32) / 32768.0  # or re-source the audio","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":null,"preventionTips":["Normalize audio tensors to float32 before feeding conversion helpers.","Re-encode 8-bit/24-bit audio to pcm_s16le or float32 WAV upstream.","Pin a known-good PyAV version so sample-format-to-dtype mapping is stable."],"tags":["audio","dtype","pcm","pyav"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}