enough-dusk-70629
07/12/2025, 1:38 PMtall-airline-16756
07/12/2025, 1:38 PMtall-airline-16756
07/12/2025, 1:38 PMSpeechHandle
objects in LiveKit to coordinate when speech playout is complete, but they serve different purposes:
• add_done_callback: Registers a callback to be executed when playout finishes. It is non-blocking and event-driven, allowing your code to continue executing while the callback runs automatically once the speech completes.
• wait_for_playout: Is an async
method that must be awaited, causing your code to pause until the speech playout is fully done (blocking, in an async sense). Use this when you need to guarantee that speech has finished before continuing.
Both work with the same underlying completion logic, but add_done_callback fits event/callback patterns, while wait_for_playout fits async/await, pausing execution until completion.
You can find example usage in the source code and documentation:
# Registering a callback
handle.add_done_callback(lambda _: print("speech done"))
# Waiting for playout to finish
await handle.wait_for_playout()
Choose based on whether you want to act on completion asynchronously (callback) or need to block until completion (await
).
• Citation: Sources: livekit-agents/livekit/agents/voice/agent_activity.py