acceptable-dream-85180
08/01/2025, 6:45 PMtall-airline-16756
08/01/2025, 6:45 PMtall-airline-16756
08/01/2025, 6:46 PMRoomEvent.TranscriptionReceived event in the Frontend SDK to capture transcription segments as they are generated. Here's an example:
import { useEffect, useState } from "react";
import { useMaybeRoomContext } from "@livekit/components-react";
import { RoomEvent, TranscriptionSegment } from "livekit-client";
export default function Transcriptions() {
const room = useMaybeRoomContext();
const [transcriptions, setTranscriptions] = useState<{ [id: string]: TranscriptionSegment }>({});
useEffect(() => {
if (!room) return;
const updateTranscriptions = (segments: TranscriptionSegment[]) => {
setTranscriptions(prev => {
const newTranscriptions = { ...prev };
for (const segment of segments) {
newTranscriptions[segment.id] = segment;
}
return newTranscriptions;
});
};
room.on(RoomEvent.TranscriptionReceived, updateTranscriptions);
return () => room.off(RoomEvent.TranscriptionReceived, updateTranscriptions);
}, [room]);
return (
);
}
Note: Transcription events are being moved to text streams on the lk.chat topic, so you may need to update your implementation accordingly.
2. Post-Session Transcript Retrieval:
You can use the session.history property to access and save the session's history upon room shutdown. Here's an example in Python:
from datetime import datetime
import json
from livekit.agents import stt, transcription
from livekit.plugins.deepgram import STT
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 saved to {filename}")
async def entrypoint(ctx: JobContext):
ctx.add_shutdown_callback(write_transcript)
Let me know if you need further assistance with implementing these methods!
Sources: Session recording and transcripts | LiveKit Docs | Transcriptions | LiveKit Docs