How can I get live transcription from an agent via...
# ask-ai
b
How can I get live transcription from an agent via API
t
Thanks for reaching out, Wesley. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to get live transcription from an agent via API. You can receive real‑time (interim + final) transcriptions from an agent by subscribing to the agent session’s transcription events on the backend and/or by reading the
lk.transcription
text stream on the client. Below are the key pieces and example code to get you started. Backend — listen for transcription events • Subscribe to the
user_input_transcribed
event on the AgentSession. • The event payload includes: ◦
transcript
(the text) ◦
is_final
(boolean: false for interim updates, true when complete) • Handle interim updates differently from final results if you need partial display vs. storage. Python example:
Copy code
@session.on("user_input_transcribed")
def on_transcript(transcript):
    if transcript.is_final:
        print(f"Final transcript: {transcript.transcript}")
    else:
        print(f"Interim transcript: {transcript.transcript}")
Frontend — receive text stream messages • Agent text responses and transcriptions are sent over a TextStream topic named
lk.transcription
. • Register a
TextStreamHandler
for that topic and read messages. Use the
lk.transcribed_track_id
attribute to tell user transcriptions apart from agent responses. JavaScript example:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => {
    const message = await reader.readAll();
    if (reader.info.attributes['lk.transcribed_track_id']) {
        console.log(`User transcription: ${message}`);
    } else {
        console.log(`Agent response: ${message}`);
    }
});
Quick notes and next steps • Interim transcripts arrive while the speaker is still talking; final transcripts arrive when speech ends. • If you want a full working example, check the Pi Zero Transcriber recipe which demonstrates logging real‑time final transcriptions to a file. • If you’d like, tell me: ◦ Which language/runtime you’re using on the backend (Python, Node, etc.) ◦ Whether you need interim transcripts shown in a UI or only final transcripts saved ◦ If you plan to stream agent text-only responses or also want audio forwarded to an external STT provider I can then provide a tailored code sample or an integration checklist for your stack. Sources: Pi Zero Transcriber | LiveKit Documentation | How to build an agent with speech-to-text input and text-only output | Live... | Text and transcriptions | LiveKit Documentation