Hi, what's the simplest way to pull a user transcr...
# ask-ai
b
Hi, what's the simplest way to pull a user transcript at the end of a call.
t
Thanks for reaching out, Matt. 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 with pulling a user transcript at the end of a call! The easiest way to do this is by using the session history along with a shutdown callback. This handy method will save the entire conversation history automatically when the session wraps up. Here’s a simple example to guide you:
Copy code
from datetime import datetime
import json

async def entrypoint(ctx):
    async def write_transcript():
        current_date = datetime.now().strftime("%Y%m%d_%H%M%S")
        filename = f"/tmp/transcript_{ctx.room.name}_{current_date}.json"
        
        with open(filename, 'w') as f:
            json.dump(session.history.to_dict(), f, indent=2)
        
        print(f"Transcript for {ctx.room.name} saved to {filename}")
    
    ctx.add_shutdown_callback(write_transcript)
    await ctx.connect()
This way, you can be confident the transcript is saved automatically once the session ends. If you’d like, I’m here to walk you through any part of this or explore other methods that might suit your needs better. Just let me know! Sources: Session recording and transcripts | LiveKit docs | livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/stt.p... | agents/src/voice/audio_recognition.ts