Skip to content

Conversation

@Shraman123
Copy link

Fixes #1906

This PR reduces a short audio "jitter"/skip at the start of the Twilio realtime voice example by adding a small, configurable startup delay (env: TWILIO_STARTUP_DELAY_S, default 0.5s) before the realtime session, Twilio message loop and buffer flush tasks are started. This allows the websocket and audio buffers to settle and prevents missing the first audio frames.

Change summary:

  • Add configurable startup delay (TWILIO_STARTUP_DELAY_S) in examples/realtime/twilio/twilio_handler.py
  • Default value: 0.5 seconds

Manual check:

  • Verified locally with a Twilio test call + ngrok (0.5s eliminated initial pop). If preferred by maintainers, I can replace this with a deterministic startup-buffer approach (buffer first N chunks then flush) — happy to implement either.

Thanks!

@seratch
Copy link
Member

seratch commented Nov 4, 2025

Thanks for sending this pull request! I think we can have this change for now, but if you're fine to work on the following quickly,

If preferred by maintainers, I can replace this with a deterministic startup-buffer approach (buffer first N chunks then flush)

this is definitely the best approach for us. Let me know if you're willing to take more time for this. Otherwise, we can merge this PR as an immediate workaround.

@seratch seratch added the documentation Improvements or additions to documentation label Nov 4, 2025
@Shraman123
Copy link
Author

Thanks for the feedback @seratch! 🙏

I’ve updated this PR to switch from a time-based delay to a deterministic startup warm-up:

  • Buffer the first N chunks of incoming Twilio audio (env TWILIO_STARTUP_BUFFER_CHUNKS, default 3 × 50ms).
  • Once the threshold is reached, flush buffered audio to OpenAI and mark warmed; subsequent audio is sent immediately.
  • Kept TWILIO_STARTUP_DELAY_S as optional knob, but default is now 0.0 since buffering is preferred.

Happy to tweak defaults, naming, or placement if you prefer this logic elsewhere. 👍

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you resolve the lint error?

@seratch seratch added this to the 0.5.x milestone Nov 5, 2025
@Shraman123 Shraman123 force-pushed the fix/twilio-startup-delay-1906 branch from 1952338 to abab19c Compare November 5, 2025 08:23
@Shraman123
Copy link
Author

Shraman123 commented Nov 5, 2025

Fixed the lint issues and rebased on the latest main all clean now ✅

@Shraman123
Copy link
Author

Hi @seratch 👋
I've fixed the formatting and verified everything locally.
All checks should pass once the workflow is approved ✅
Please review again when you get a chance — thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feature:realtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

twilio example: jittering/skip sound in the beginning of every word

2 participants