I am transferring call to live agent during a sip ...
# ask-ai
c
I am transferring call to live agent during a sip conversation and getting him in the room but I am not able to get the transcript of live agent says in the room.
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.
I'm happy to help you capture the transcript of a live agent during a SIP conversation in LiveKit. Here’s a simple step-by-step guide to get you started: 1. First, make sure to enable transcription by setting
transcription_enabled=True
in
RoomOutputOptions
when you start the session. 2. Next, listen for the
conversation_item_added
event to capture the real-time transcripts. To focus specifically on the agent’s speech, filter for
role == "assistant"
. 3. You can then access the real-time transcription data through the
transcription_node
or
llm_node
for immediate processing. 4. Finally, save the complete transcript by using
session.history
or add a shutdown callback to store the data when the session ends. If you’d like, I’m here to walk you through any part of this or provide more details. Just let me know! Sources: Understanding Transcript Timing in Voice Conversations | complex-agents/teleprompter/cartesia-ink.py | livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/s... | Session recording and transcripts | LiveKit Docs | How to capture real-time agent transcriptions during conversations
c
can you give me some example code in python
t
I'd love to share a helpful Python code snippet that captures the transcript of a live agent during a SIP conversation. Here it is:
Copy code
from livekit.agents import AgentSession, RoomOutputOptions

async def start_sip_session():
    session = AgentSession()

    # Store transcripts in memory
    conversation_transcripts = []

    # Event handler for capturing conversation items
    @session.on("conversation_item_added")
    def on_conversation_item(event):
        if event.item.role == "assistant":
            print(f"Agent said: {event.item.text_content}")
            conversation_transcripts.append({
                "role": event.item.role,
                "text": event.item.text_content,
                "timestamp": event.created_at.isoformat()
            })

    # Start the session with transcription enabled
    await session.start(
        agent=your_sip_agent,
        room=your_room_context,
        room_output_options=RoomOutputOptions(
            transcription_enabled=True,
            audio_enabled=True,
            sync_transcription=True
        )
    )

    # Save the transcript when the session ends
    def save_transcript():
        with open("sip_transcript.json", "w") as f:
            json.dump(conversation_transcripts, f, indent=2)

    session.add_shutdown_callback(save_transcript)

# Call the function to start the session
# asyncio.run(start_sip_session())
This snippet sets up transcription, listens for conversation events, and saves everything neatly into a JSON file once the session wraps up. If anything feels unclear or you'd like me to walk you through more examples, just let me know—I'm here to help!
c
I am still not able to get the transcript. i just need to get the transcript of all convrsation that is happening in room.
t
To help you capture the transcript of all conversations happening in a LiveKit room, here are some friendly methods you can try: 1. Access Full Session History: You can use the
session.history
property to get the entire conversation history, which includes all transcribed user inputs and agent responses. It’s a great idea to save this history when the session ends by using a shutdown callback. 2. Real-Time Event Listening: By listening to the
conversation_item_added
event, you’ll be able to capture new conversation items as they come in — both user and agent messages. 3. Text Streams: Another approach is to register a handler for the
lk.transcription
text stream topic, which lets you receive real-time transcriptions from participants. 4. Frontend Integration: If you’re working with LiveKit’s React components, the
useTranscriptions()
and
useChat()
hooks are super helpful to merge real-time transcriptions with chat messages seamlessly. Here’s a simple Python code snippet to get you started with capturing the full conversation history:
Copy code
from livekit.agents import AgentSession

async def capture_transcripts():
    session = AgentSession()

    # Start the session with transcription enabled
    await session.start(
        agent=your_agent,
        room=your_room_context,
        room_output_options=RoomOutputOptions(
            transcription_enabled=True
        )
    )

    # Save the full conversation history when the session ends
    def save_transcript():
        with open("conversation_history.json", "w") as f:
            json.dump(session.history, f, indent=2)

    session.add_shutdown_callback(save_transcript)
If you have any questions or want me to walk you through additional examples, please don’t hesitate to ask — I’m here to help! Sources: Text and transcriptions | LiveKit docs | Session recording and transcripts | LiveKit Docs | Session recording and transcripts | LiveKit docs | complex-agents/note-taking-assistant/README.md | examples/other/translation/multi-user-translator.py
c
still I am not able to get the transcription of live agent.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!