which is the livekit event that emits when user sp...
# ask-ai
c
which is the livekit event that emits when user speech committed in v1
t
Thanks for reaching out, NAJAM. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! While LiveKit doesn’t have a specific event named exactly for when user speech is "committed" in v1, there are a couple of events that come pretty close and might be just what you need: • user_input_transcribed: This event fires when the user’s transcription is ready. It includes a handy property
is_final: bool
that tells you if the transcript is final. • conversation_item_added: This one triggers when an item, like user input, is officially added to the chat history. If you’d like, I’m here to help with a specific implementation or if you need any more details—just let me know! Sources: Events and error handling | LiveKit docs | livekit-agents/livekit/agents/stt/stream_adapter.py | agents/src/stt/stt.ts
c
how can i implement this in python
t
I'd love to help you get started with handling the user_input_transcribed and conversation_item_added events in Python for LiveKit. Here's a simple way to approach it: 1. First, set up an
AgentSession
within your LiveKit room context. 2. Next, make sure to register your event handlers before you start the session. 3. You can use the
on
method to define what should happen when each event occurs. Here's a friendly example to guide you:
Copy code
from livekit.agents import JobContext, AgentSession, UserInputTranscribedEvent, ConversationItemAddedEvent

async def entrypoint(ctx: JobContext):
    await ctx.connect()
    session = AgentSession()

    @session.on("user_input_transcribed")
    def on_user_input_transcribed(event: UserInputTranscribedEvent):
        print(f"User said: {event.transcript}, Final: {event.is_final}")

    @session.on("conversation_item_added")
    def on_conversation_item_added(event: ConversationItemAddedEvent):
        print(f"New conversation item: {event.item.text_content}")

    await session.start(agent=YourAgent(), room=ctx.room)
If you have any questions or would like me to walk you through a more detailed example, please don’t hesitate to ask. I’m here to help! Sources: pipeline-stt/transcriber/README.md | tests/test_agent_session.py | Events and error handling | LiveKit docs | Session recording and transcripts | LiveKit Docs