Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: write transcoded WAV blocks raw and fix the header once on close (#15917)

Daniel Handfd90e657d2f
diff --git a/studio/backend/core/inference/audio_inputs.py b/studio/backend/core/inference/audio_inputs.py
index ef598fb31d4..57e2e36cb17 100644
--- a/studio/backend/core/inference/audio_inputs.py
+++ b/studio/backend/core/inference/audio_inputs.py
@@ -177,7 +177,7 @@ def transcode(
raise AudioInputError(
413, f"Audio is longer than {int(max_seconds // 60)} minutes."
)
- out.writeframes(block.to_ndarray().reshape(-1)[: take * channels].tobytes())
+ out.writeframesraw(block.to_ndarray().reshape(-1)[: take * channels].tobytes())
frames += take
if cut and frames >= ceiling:
return True
diff --git a/studio/backend/tests/test_audio_inputs.py b/studio/backend/tests/test_audio_inputs.py
index 45e1c7f702f..cb97d9b344c 100644
--- a/studio/backend/tests/test_audio_inputs.py
+++ b/studio/backend/tests/test_audio_inputs.py
@@ -85,6 +85,24 @@ def _frames(path) -> tuple[int, int, int]:
return w.getframerate(), w.getnchannels(), w.getnframes()
+def test_transcode_writes_the_wav_header_sizes_once_at_close(tmp_path, monkeypatch):
+ src = tmp_path / "clip.wav"
+ src.write_bytes(encode("wav", "pcm_s16le", 44100, "stereo", 1.5))
+ patches = []
+ real = wave.Wave_write._patchheader
+
+ def patch(self):
+ patches.append(self._datawritten)
+ return real(self)
+
+ monkeypatch.setattr(wave.Wave_write, "_patchheader", patch)
+ dst = tmp_path / "out.wav"
+ info = audio_inputs.transcode(src, dst)
+ assert patches == [os.path.getsize(dst) - 44]
+ assert _frames(dst) == (44100, 2, int(round(44100 * 1.5)))
+ assert info == {"duration_s": 1.5, "sample_rate": 44100, "channels": 2}
+
+
@pytest.fixture
def client():
from routes import inference