File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,23 @@ async def start(self) -> None:
8989 await self .twilio_websocket .accept ()
9090 print ("Twilio WebSocket connection accepted" )
9191
92+ # ---------------------------
93+ # STARTUP DELAY (fix jitter)
94+ # ---------------------------
95+ # Small configurable delay to allow websockets/handshakes and buffers
96+ # to settle before audio starts. Default is 0.5 seconds.
97+ try :
98+ startup_delay = float (os .getenv ("TWILIO_STARTUP_DELAY_S" , "0.5" ))
99+ except Exception :
100+ startup_delay = 0.5
101+
102+ # Only perform the sleep if a positive value is configured
103+ if startup_delay > 0 :
104+ # allow other coroutines to run while waiting
105+ await asyncio .sleep (startup_delay )
106+ # ---------------------------
107+
108+ # create tasks after warmup so we avoid missing the first audio frames
92109 self ._realtime_session_task = asyncio .create_task (self ._realtime_session_loop ())
93110 self ._message_loop_task = asyncio .create_task (self ._twilio_message_loop ())
94111 self ._buffer_flush_task = asyncio .create_task (self ._buffer_flush_loop ())
You can’t perform that action at this time.
0 commit comments