You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Twilio audio jittering by buffering outgoing audio chunks
Fixes#1906
The Twilio realtime example was experiencing jittering/skip sounds at
the beginning of every word. This was caused by sending small audio
chunks from OpenAI to Twilio too frequently without buffering.
Changes:
- Added outgoing audio buffer to accumulate audio chunks from OpenAI
- Buffer audio until reaching 50ms worth of data before sending to Twilio
- Flush remaining buffered audio on audio_end and audio_interrupted events
- Updated periodic flush loop to handle both incoming and outgoing buffers
- Added documentation about audio buffering to troubleshooting section
Technical details:
- Incoming audio (Twilio → OpenAI) was already buffered
- Now outgoing audio (OpenAI → Twilio) is also buffered symmetrically
- Buffer size: 50ms chunks (400 bytes at 8kHz sample rate)
- Prevents choppy playback by sending larger, consistent audio packets
Tested with:
- Linting: ruff check ✓
- Formatting: ruff format ✓
- Type checking: mypy ✓
Generated with Lucas Wang<[email protected]>
Copy file name to clipboardExpand all lines: examples/realtime/twilio/README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,7 @@ This example demonstrates how to connect the OpenAI Realtime API to a phone call
70
70
71
71
- **WebSocket connection issues**: Ensure your ngrok URL is correct and publicly accessible
72
72
- **Audio quality**: Twilio streams audio in mulaw format at 8kHz, which may affect quality
73
+
- **Audio jittering/skipping**: The implementation includes audio buffering (50ms chunks) to reduce jittering at word boundaries. This buffers both incoming (Twilio → OpenAI) and outgoing (OpenAI → Twilio) audio for smoother playback.
73
74
- **Latency**: Network latency between Twilio, your server, and OpenAI affects response time
74
75
- **Logs**: Check the console output for detailed connection and error logs
0 commit comments