what is the listener to track all the function cal...
# ask-ai
f
what is the listener to track all the function calls, session.say, and session.generate_reply?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m happy to help you track all function calls,
session.say
, and
session.generate_reply
! Here’s a friendly guide to get you started with the right event listeners: • Tracking Function Calls: You can keep an eye on function tools being executed by using the
function_tools_executed
event. It gives you useful details about the function calls and their results. • Tracking
session.say
and `session.generate_reply`:
The
speech_created
event is your go-to here. It provides a
SpeechHandle
object to help you monitor speech playout, and the
source
property tells you whether the speech came from
say
,
generate_reply
, or
tool_response
. • Accessing Current Speech: If you’re working in Python, you can easily access the active speech handle with
session.current_speech
and sync up with whatever speech is playing at the moment. If you’d like, I can also share some specific code examples or dive deeper into any part—just let me know! I’m here to help. Sources: Agent speech and audio | LiveKit Docs | Events and error handling | LiveKit Docs | Events and error handling | LiveKit Docs | Docs::Agents
f
provide example on how to track the content from speech_created event
t
To help you track the content from the
speech_created
event, here’s a simple approach you can try: Python Example:
Copy code
@session.on("speech_created")
async def on_speech_created(event):
    print(f"Speech created - Source: {event.source}, User initiated: {event.user_initiated}")

    # Access the speech handle to monitor playout
    handle = event.speech_handle

    # Wait for the speech to finish playing
    await handle.wait_for_playout()

    print("Speech playout completed.")
To get the actual speech transcript, you can link this with the
conversation_item_added
event, which includes the agent's spoken text: Python Example:
Copy code
@session.on("conversation_item_added")
def on_conversation_item_added(event):
    item = event.item
    if item.role == "assistant":
        print(f"Assistant said: {item.content}")
This way, you can keep an eye on the speech playout and capture what’s being said. If you’d like me to walk you through this further or provide more examples, please don’t hesitate to ask—I’m here to help! Sources: Events and error handling | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Events and error handling | LiveKit Docs | Agent speech and audio | LiveKit Docs