---
type: email
from: gn00295120 <notifications@github.com>
subject: [openai/openai-agents-python] fix: prevent ValueError when audio

 buffer is empty in STT (fixes #821) (PR #1934)
received: 2026-03-06 08:08:36
date_header: Sat, 18 Oct 2025 23:28:02 -0700
priority: normal
status: awaiting_approval
uid: 32975
---

## Email Content

**From:** gn00295120 <notifications@github.com>
**Subject:** [openai/openai-agents-python] fix: prevent ValueError when audio

 buffer is empty in STT (fixes #821) (PR #1934)
**Date:** Sat, 18 Oct 2025 23:28:02 -0700

### Body (preview)

## Summary



Fixes #821



This PR prevents a `ValueError` crash when the audio buffer is empty in the STT transcription pipeline.



## Problem



When `_turn_audio_buffer` is empty, calling `_audio_to_base64()` triggers:

```

ValueError: need at least one array to concatenate

```



This occurs at line 126 in `openai_stt.py`:

```python

self._tracing_span.span_data.input = _audio_to_base64(self._turn_audio_buffer)

```



### When This Happens



1. **Turn ends before audio data arrives** - Network latency or slow audio stream

2. **Transcript generated without audio** - Some STT edge cases

3. **Audio data loss** - Connection issues during transmission



## Solution



Add a simple check before calling `_audio_to_base64()`:



```python

# Before (line 125-126)

if self._trace_include_sensitive_audio_data:

    self._tracing_span.span_data.input = _audio_to_base64(self._turn_audio_buffer)



# After (fixed)

if self._trace_include_sensitive_audio_data and self._turn_audio_buffer:

    self._tracing_span.span_data.input = _audio_to_base64(self._turn_audio_buffer)

```



The additional `and self._turn_audio_buffer` check ensures we only encode when there&#39;s actual data.



## How to Test



### Test 1: Reproduce the Original Bug



Create a file `test_bug.py`:



```python

import numpy as np

import base64



def _audio_to_base64(audio_data):

    concatenated_audio = np.concatenate(audio_data)  # Will crash if empty!

    return base64.b64encode(concatenated_audio.tobytes()).decode(&quot;utf-8&quot;)



# Simulate the bug scenario

transcript = &quot;Hello world&quot;  # We have transcript

audio_buffer = []  # But no audio data!



try:

    result = _audio_to_base64(audio_buffer)

except ValueError as e:

    print(f&quot;✅ Bug reproduced: {e}&quot;)

    # Output: need at least one array to concatenate

```



Run: `python test_bug.py`



Expected: Shows the `ValueError` that users reported in issue #821



### Test 2: Verify the Fix



Create a file

---

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