how to sent custom transcription event to frontend...
# ask-ai
l
how to sent custom transcription event to frontend for chat
✅ 1
t
Thanks for reaching out, Rajadurai. 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 sending a custom transcription event to the frontend for chat. Short answer: LiveKit delivers transcriptions to the frontend via the
lk.transcription
text stream topic (received with
registerTextStreamHandler
), and standard flows expect transcriptions to originate from the STT/AgentSession pipeline. There isn’t a documented API to inject arbitrary custom transcription events into that transcription stream directly. Options you can use instead: • Use LiveKit data messages to send custom transcription-like events from your server/app to clients. Data messages are flexible and commonly used to transmit agent state, chat text, or synthetic transcription events. Use the client’s data message handlers to display them in your chat UI. • If you must integrate with the built-in transcription stream for sync with audio playback, run your custom text through the AgentSession/STT pipeline or the
transcription_node
so it’s emitted as part of the transcription flow (the docs show
transcription_node
can modify agent-generated transcriptions, not create independent events). Quick questions to narrow the best approach: • Do you need those events synchronized with audio playback (so they must appear on
lk.transcription
) or is sending them as chat messages sufficient? • Are the custom transcriptions coming from a bot/service on your server, or from client-side logic? Tell me which option you prefer and where the text originates, and I’ll give exact code snippets for either data messages (server + JS client) or the recommended approach to surface text through the transcription pipeline. Sources: Text and transcriptions | LiveKit Documentation | Live conversations with AI using ChatGPT and WebRTC | LiveKit, with interactive elements
l
give python code snipet for that
t
Thanks — I’m responding to your request for a Python snippet to send custom transcription-like events to the frontend. Below are two concise options: (A) send via the transcription text stream (
lk.transcription
) using an AgentSession helper, and (B) publish a data message directly (flexible and commonly used). Use whichever fits your architecture. A — Send on
lk.transcription
(AgentSession)
Copy code
# Requires livekit agents SDK and an active AgentSession (session)
async def send_custom_transcription(session, text, final=True):
    """
    Send custom transcription-like text to frontend on lk.transcription.
    `session` is an AgentSession with .output.add_text available.
    """
    await session.output.add_text(text, topic="lk.transcription", final=final)
B — Publish a data message (server/app -> clients)
Copy code
from livekit.agents import proto as agents_proto

# Requires an AgentSession (session) or other publisher that exposes publish_data
async def publish_data_message(session, text):
    await session.output.publish_data(
        data=text.encode("utf-8"),
        kind=agents_proto.DataPacket.Kind.RELIABLE,
        topic="lk.transcription"  # or any custom topic you consume on client
    )
Which method do you want code for next — full example with session setup, or a JS client snippet to receive and display these messages? Sources: Text and transcriptions | LiveKit Documentation, with interactive elements