alert-smartphone-80139
08/07/2025, 1:32 PMtall-airline-16756
08/07/2025, 1:32 PMtall-airline-16756
08/07/2025, 1:33 PMwait_for_playout()
method on the SpeechHandle
. Here’s how:
• Generate Speech and Get Handle: Use session.say()
or session.generate_reply()
to create a SpeechHandle
object. Set allow_interruptions=False
to prevent interruptions during the speech.
• Wait for Speech Playout: Call await handle.wait_for_playout()
to ensure the speech finishes before proceeding. This method blocks until the speech has completed playing.
• End the Call: After the speech completes, end the call using the delete_room
API. This ensures the session terminates only after the last speech is played.
Here’s an example:
handle = session.say("Thank you for calling. Goodbye!", allow_interruptions=False)
await handle.wait_for_playout()
await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
Alternatively, if you prefer using asyncio.sleep()
, you can poll the speech handle’s done()
status:
handle = session.say("Goodbye message...", allow_interruptions=False)
while not handle.done():
await asyncio.sleep(0.1)
await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
Using wait_for_playout()
is recommended as it handles the playout asynchronously without busy waiting. Let me know if you need further assistance!