how to save transcripts on backend in >version ...
# ask-ai
q
how to save transcripts on backend in >version 1.0
t
Thanks for reaching out, Nirmal. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in saving transcripts on the backend in LiveKit (version >1.0)! Let's walk through the steps together to make sure everything goes smoothly: 1. Enable Transcription: When you start your agent session, just set
transcription_enabled=True
in
RoomOutputOptions
. Here’s a simple example to get you started:
Copy code
await session.start(
    agent=YourAgent(),
    room=ctx.room,
    room_output_options=RoomOutputOptions(
        transcription_enabled=True,
        audio_enabled=False,  # disable if audio output isn’t needed
    ),
)
1. Save Full Transcript: You can easily access the conversation history using
session.history
and save it when the session shuts down. Here’s how you might do that:
Copy code
@session.on("shutdown")
async def on_shutdown():
    history = session.history
    with open("transcript.json", "w") as f:
        f.write(history.model_dump_json(indent=2))
1. Real-Time Transcription: If you want to get live updates, listen for events like
user_input_transcribed
. It’s a great way to stay in the loop as things happen:
Copy code
@session.on("user_input_transcribed")
async def on_transcribed(text: str, is_final: bool):
    if is_final:
        logger.info(f"Final transcript: {text}")
1. Advanced Option: For more customized handling, you can use text streams with the topic
lk.transcription
. Here’s a snippet to guide you:
Copy code
await self._room.local_participant.stream_text(
    topic=TOPIC_TRANSCRIPTION,
    sender_identity=self._participant_identity,
    attributes=attributes,
)
If you’d like to dive deeper, the LiveKit Session Recording docs and the Python transcription example are fantastic resources. Feel free to explore them at your own pace! Sources: livekit-agents/livekit/agents/tts/tts.py | Session recording and transcripts | LiveKit Docs | Agents v0.x migration guide - Python | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docs