How can i ask from the frontend to receive all the...
# ask-ai
f
How can i ask from the frontend to receive all the chat transcripts to the ai agent?
t
Thanks for reaching out, muse. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to get all chat transcripts from the frontend to an AI agent in LiveKit, here are a few ways you can do it: • Listen to Transcription Events: You can use the LiveKit SDK to listen for
RoomEvent.TranscriptionReceived
right in your frontend. This way, you’ll gather transcription segments as they come in. • Combine Transcriptions and Chat Data: Try using handy hooks like
useTranscriptions()
and
useChat()
to bring together transcription and chat data for a complete view. • Custom RPC Method: Another option is to create a custom RPC method where the agent shares the conversation history. The agent can set up an RPC method (like
get_all_transcripts
) that your frontend can call to fetch all the transcripts. If you want a hand with any of these or have something specific in mind, just give me a shout—I’m here to help! Sources: Transcriptions | LiveKit Docs | complex-agents/teleprompter/cartesia-ink.py | Session recording and transcripts | LiveKit Docs | Text and transcriptions | LiveKit Docs
f
Okay can you show me a possible implementation of the get_all_transcripts rpc method?
t
Here’s a friendly example of how you can implement the
get_all_transcripts
RPC method: Agent Side: The agent sets up the RPC method to share the conversation history:
Copy code
from livekit import RoomContext

@ctx.room.local_participant.register_rpc_method("get_all_transcripts")
async def get_all_transcripts(data):
    # Grab the conversation history
    history = session.history  # This is available on the agent session
    return {"transcripts": history}
Frontend Side: On the frontend, you can call this RPC method to get the transcripts like this:
Copy code
// Call the RPC method to request transcripts
const response = await room.localParticipant.performRpc({
  destinationIdentity: agentParticipant.identity, // Just swap in the agent's identity here
  method: "get_all_transcripts",
  payload: "" // You can add a payload if needed, or leave it empty
});

// Here’s the transcripts you get back
const transcripts = response.transcripts;
console.log(transcripts);
If you want me to walk you through any part of this or help with adding it to your project, just let me know—I’m here to help!
f
What is the data format of the transcripts?
t
Hey there! Just wanted to share how the transcript data in LiveKit is organized, so it’s easier to work with: Transcription Object: • transcribed_participant_identity (string): This tells you who the participant is whose speech got transcribed • track_id (string): The ID of the audio track that was transcribed • segments (array): A list of
TranscriptionSegment
objects that hold the actual transcript details TranscriptionSegment Object: • id (string): A unique ID for each segment • text (string): The actual transcribed text • start_time (uint64): When this segment starts • end_time (uint64): When this segment ends • final (boolean): Shows if this transcription is final or just a draft • language (string): The language used in the transcription And here’s a quick example in TypeScript to help visualize it:
Copy code
interface Transcription {
  participantIdentity: string;
  trackSid: string;
  segments: TranscriptionSegment[];
}

interface TranscriptionSegment {
  id: string;
  text: string;
  startTime: bigint;
  endTime: bigint;
  language: string;
  final: boolean;
}
If you have any questions or want me to walk you through any part of this, just let me know—I’m happy to help!