From 964d0d68c5fb2dfcb0261f7ebdb7bcdbb14c63e7 Mon Sep 17 00:00:00 2001 From: Sayo Date: Sun, 1 Mar 2026 17:35:05 +0900 Subject: [PATCH] fix: wav parse --- nodes.py | 58 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/nodes.py b/nodes.py index 4b5aa81..90b3351 100644 --- a/nodes.py +++ b/nodes.py @@ -95,28 +95,54 @@ def _encode_audio_b64(audio) -> str: return _tensor_to_wav_b64(waveform, audio["sample_rate"]) +def _parse_wav_bytes(audio_bytes: bytes): + """Parse WAV bytes manually to support PCM (fmt=1) and float32 (fmt=3).""" + if audio_bytes[:4] != b"RIFF" or audio_bytes[8:12] != b"WAVE": + raise RuntimeError("Not a valid WAV file") + pos = 12 + fmt_tag = n_channels = sample_rate = sampwidth = 0 + data_offset = data_size = 0 + while pos < len(audio_bytes) - 8: + chunk_id = audio_bytes[pos:pos+4] + chunk_size = struct.unpack_from("