---
type: email
from: gn00295120 <notifications@github.com>
subject: [openai/openai-agents-python] fix: handle odd-length audio chunks in

 voice streaming (fixes #1824) (PR #1928)
received: 2026-03-06 08:08:11
date_header: Sat, 18 Oct 2025 10:50:23 -0700
priority: normal
status: awaiting_approval
uid: 32922
---

## Email Content

**From:** gn00295120 <notifications@github.com>
**Subject:** [openai/openai-agents-python] fix: handle odd-length audio chunks in

 voice streaming (fixes #1824) (PR #1928)
**Date:** Sat, 18 Oct 2025 10:50:23 -0700

### Body (preview)

## Summary



Fixes #1824 - Handles audio chunks with odd byte lengths in voice streaming to prevent `ValueError` when using TTS providers that may produce odd-length chunks (e.g., ElevenLabs MP3 streams).



## Problem



When using custom TTS providers (like ElevenLabs) that stream MP3 audio, the SDK would crash with:



```

ValueError: buffer size must be a multiple of element size

```



This occurred in `StreamedAudioResult._transform_audio_buffer()` when:

1. Audio chunks from the TTS provider had an odd number of bytes

2. The method tried to use `np.frombuffer(..., dtype=np.int16)`

3. Since `int16` requires 2 bytes per element, odd-length buffers caused the error



## Solution



Added automatic padding of odd-length audio buffers:



```python

# Combine all chunks

combined_buffer = b&quot;&quot;.join(buffer)



# Pad with a zero byte if the buffer length is odd

# This is needed because np.frombuffer with dtype=np.int16 requires

# the buffer size to be a multiple of 2 bytes

if len(combined_buffer) % 2 != 0:

    combined_buffer += b&quot;\x00&quot;



np_array = np.frombuffer(combined_buffer, dtype=np.int16)

```



### Why this works:

- The padding adds at most 1 zero byte (&lt; 1 audio sample)

- This has minimal impact on audio quality

- Ensures all buffers are valid for `np.frombuffer` with `dtype=np.int16`

- Applies to all TTS providers, not just ElevenLabs



## Changes Made



- Updated `StreamedAudioResult._transform_audio_buffer()` in `src/agents/voice/result.py`

- Added clear comments explaining the padding logic

- No changes to public API or behavior (except fixing the crash)



## Testing



- ✅ Linting (`ruff check`) - passed

- ✅ Type checking (`mypy`) - passed

- ✅ Formatting (`ruff format`) - passed

- The issue reporter confirmed that adding `b&quot;\x00&quot;` padding fixes the issue



## Test Plan



The issue includes a complete reproduction script using ElevenLabs. To verify:



```bash

# Set up ElevenLabs API key

export

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
