diff --git a/CHANGELOG.md b/CHANGELOG.md index 14718216..435a166c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Per-PR attribution and contributor credits are published automatically on the co ## [Unreleased] ### Fixed - `GAP_TRIM_MS=0` turns the base chunk trim off. It used to slice every chunk to nothing, so all audio came back silent +- Non-streamed WAV (`"stream": false`) has its real length in the header. It said 4 GB, so readers that trust the header, like Python's `wave`, reported a one-sentence file as about 25 hours long (#586) ## [v0.10.0] - 2026-11-08: Websockets/Realtime API, CPU Memory & API Keys ### Added diff --git a/api/src/services/streaming_audio_writer.py b/api/src/services/streaming_audio_writer.py index 5f9b5980..90592405 100644 --- a/api/src/services/streaming_audio_writer.py +++ b/api/src/services/streaming_audio_writer.py @@ -1,5 +1,6 @@ """Audio conversion service with proper streaming support""" +import struct from io import BytesIO from typing import Optional @@ -8,6 +9,25 @@ from loguru import logger +def set_wav_sizes(data: bytes) -> bytes: + """Replace the streaming size placeholders in a complete WAV with the real sizes.""" + if data[:4] != b"RIFF" or data[8:12] != b"WAVE": + return data + if len(data) > 0xFFFFFFFF: + logger.warning("WAV over 4 GiB, using placeholder streaming size") + return data + out = bytearray(data) + struct.pack_into("