How can I play session.say before the TTS response...
# ask-ai
a
How can I play session.say before the TTS response?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can play a
session.say
message before the main TTS response by calling
session.say()
with your desired message as soon as you want it to play. This is commonly used for quick acknowledgments or pre-responses while the main TTS response is being generated. For example:
Copy code
await session.say("This is a pre-response message.", allow_interruptions=False)
# Then generate and play the main TTS response
LiveKit supports a priority-based speech generation system, so you can control the order and timing of TTS messages. The
session.say()
method can be used for immediate responses, and you can run the main response generation concurrently. For more advanced sequencing, you can implement a message queue to schedule multiple TTS messages in order. Key parameters for
session.say()
include: • allow_interruptions: Allows the user to interrupt the agent while speaking (default
True
). • add_to_chat_ctx: Adds the text to the agent's chat context after playback (default
True
). • audio: Optionally provide pre-synthesized audio to skip TTS and reduce response time. If you are using a realtime model, ensure you have a TTS plugin added to your session, or use
generate_reply()
instead. This approach allows you to provide a fast, responsive user experience by playing a short message before the main TTS response is ready. References: Sources: Agent speech and audio | LiveKit Docs | examples/voice_agents/fast-preresponse.py | Agents Core Architecture | livekit/livekit_composite | DeepWiki | Building a Guided Meditation Assistant | LiveKit Docs