# -*- coding: utf-8 -*- """Audio utilities shared across model providers.""" import struct def _build_streaming_wav_header( sample_rate: int = 24000, channels: int = 1, bits_per_sample: int = 16, ) -> bytes: """Build a 44-byte WAV/RIFF header for streaming PCM. The RIFF and ``data`` chunk sizes are set to ``0xFFFFFFFF`` since the total length isn't known yet. Decoders that only need sample-rate, channel count and bit depth (e.g. the web ``WavStreamPlayer``) treat everything after the ``data`` chunk header as PCM, so this is sufficient for live decoding of an open-ended stream. Both DashScope omni and OpenAI streaming deliver raw PCM upstream; prefixing the first chunk with this header lets the frontend start playback immediately without buffering the whole response. """ byte_rate = sample_rate * channels * bits_per_sample // 8 block_align = channels * bits_per_sample // 8 return ( b"RIFF" + struct.pack("