calm-shampoo-47633
08/15/2025, 3:49 PMtall-airline-16756
08/15/2025, 3:49 PMtall-airline-16756
08/15/2025, 3:49 PMuser_speech_committed
and agent_stopped_speaking
to catch those transcriptions.
• Save these transcriptions to a file or directly into your database.
• Pull the whole conversation history from the session whenever you need and export it.
If you'd like a hand with the details or need help connecting this with a specific database, just give me a shout!calm-shampoo-47633
08/15/2025, 3:51 PMtall-airline-16756
08/15/2025, 3:51 PMfrom datetime import datetime
async def save_transcription(speaker, text):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open("transcriptions.log", "a") as f:
f.write(f"{timestamp} - {speaker}: {text}\n")
# Example usage for user and agent messages
await save_transcription("user", "Hello, how can I help you?")
await save_transcription("agent", "I need assistance with my account.")
2. Real-time Event Handling:
async def on_transcript(transcript):
if transcript.is_final:
await save_transcription("user", transcript.transcript)
async def on_agent_message(event):
await save_transcription("agent", event.text)
3. Frontend Integration:
import { useEffect, useState } from "react";
import { RoomEvent } from "livekit-client";
export default function TranscriptionHandler() {
const [transcripts, setTranscripts] = useState([]);
useEffect(() => {
const handleTranscription = (event) => {
setTranscripts((prev) => [...prev, event.transcription]);
};
room.on(RoomEvent.TranscriptionReceived, handleTranscription);
return () => room.off(RoomEvent.TranscriptionReceived, handleTranscription);
}, []);
return null;
}
4. Save Session History:
async def save_session_history(history):
with open("session_history.json", "w") as f:
json.dump(history, f, indent=2)
# Example usage during shutdown
await save_session_history(session.history)
If you have any questions or want me to walk you through any part of this, just let me know! I'm here to help.