From 8ad09ee11d669a27763af1f7e17e2fd403ae4c46 Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Sat, 5 Sep 2026 19:39:14 +0530 Subject: [PATCH 1/2] fix(voice): decode PCM16 as little-endian --- src/agents/voice/result.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/agents/voice/result.py b/src/agents/voice/result.py index a01f7d762c..036dbc410f 100644 --- a/src/agents/voice/result.py +++ b/src/agents/voice/result.py @@ -104,7 +104,9 @@ def _transform_audio_buffer( # np.int16 needs 2-byte alignment; pad odd-length chunks safely. combined_buffer += b"\x00" - np_array = np.frombuffer(combined_buffer, dtype=np.int16) + # Provider PCM16 is little-endian regardless of host byte order. Decode it + # explicitly, then normalize to native int16 before exposing it to callers. + np_array = np.frombuffer(combined_buffer, dtype=np.dtype(" Date: Sat, 5 Sep 2026 19:39:24 +0530 Subject: [PATCH 2/2] test(voice): pin little-endian PCM16 decoding --- tests/voice/test_pcm16_endianness.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/voice/test_pcm16_endianness.py diff --git a/tests/voice/test_pcm16_endianness.py b/tests/voice/test_pcm16_endianness.py new file mode 100644 index 0000000000..dbe0cf650c --- /dev/null +++ b/tests/voice/test_pcm16_endianness.py @@ -0,0 +1,27 @@ +import numpy as np + +from agents.voice.result import StreamedAudioResult + + +def test_transform_audio_buffer_decodes_pcm16_as_little_endian() -> None: + result = StreamedAudioResult.__new__(StreamedAudioResult) + + raw = b"\x01\x02\x03\x04" + transformed = result._transform_audio_buffer([raw], np.int16) + + assert transformed.dtype == np.dtype(np.int16) + assert transformed.tolist() == [0x0201, 0x0403] + + +def test_transform_audio_buffer_float32_uses_little_endian_samples() -> None: + result = StreamedAudioResult.__new__(StreamedAudioResult) + + raw = b"\x01\x02\x03\x04" + transformed = result._transform_audio_buffer([raw], np.float32) + + assert transformed.dtype == np.dtype(np.float32) + assert transformed.shape == (2, 1) + np.testing.assert_allclose( + transformed[:, 0], + np.asarray([0x0201, 0x0403], dtype=np.float32) / 32767.0, + )