Is it ok that on the frontend "lk.transcription_fi...
# ask-ai
b
Is it ok that on the frontend "lk.transcription_final" is always "false" for user transcriptions?
t
Thanks for reaching out, Serhii. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
lk.transcription_final
attribute helps us know if a transcription update is final or just interim. If you’re seeing it always as
false
, a few things might be going on: • The agent might not be sending a final transcription update after the speech ends. It’s important to make sure the agent calls
writer.aclose()
with
lk.transcription_final = "true"
when the speech finishes. • The frontend might not be interpreting the attribute correctly. Double-check that it’s looking for the string value
"true"
rather than treating it as a boolean directly. • The STT engine or plugin might not be emitting final events like
END_OF_SPEECH
or
FINAL_TRANSCRIPT
. To help fix this, please review your agent’s logic for handling final transcriptions, ensure the frontend parses the attribute properly, and confirm your STT engine is set up to emit those final events. If you’d like, I’m here to help you go over your agent code or assist with debugging—just let me know! Sources: Events and error handling | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Events and error handling | LiveKit Docs | Sources/LiveKit/Types/TranscriptionSegment.swift | lib/src/types/attribute_typings.dart
b
Is there a way to get segment id of a transcription on the agent's side? I mean the segment ids we get within lk.transcription on the frontend.
t
I'm happy to help you access the segment ID of a transcription on the agent's side! You can do this by retrieving the
lk.segment_id
attribute from the text stream's attributes. Here's a simple example in Python using the LiveKit Agents SDK to guide you through it:
Copy code
from livekit.agents.types import ATTRIBUTE_TRANSCRIPTION_SEGMENT_ID

async def on_text_received(reader: rtc.TextStreamReader, participant_identity: str):
    segment_id = reader.info.attributes.get(ATTRIBUTE_TRANSCRIPTION_SEGMENT_ID, None)
    if segment_id:
        # Handle the segment ID
        pass
This segment ID is unique for each transcription segment and is great for correlating updates. If you have any questions or need a hand with anything else, please feel free to ask—I’m here to support you! Sources: examples/other/chat-stream-receiver.py | VoiceAgent/Chat/Receive/TranscriptionStreamReceiver.swift | Transcriptions | LiveKit Docs | livekit/livekit_models.pb.go
b
I wasn't able to receive any events from "lk.transcription" on agent's side, but it works on the frontend.
t
Hi there! Just to clarify, the agent doesn’t directly "receive"
lk.transcription
events the way the frontend does. Instead, the agent sends transcription data through text streams, and the frontend or client needs to actively subscribe to the
lk.transcription
text stream topic to get those updates. If you’re not seeing these events on the agent’s side, here are a few things to check: • Make sure you’re not using outdated events like
RoomEvent.TranscriptionReceived
. Switching to text streams is the way to go. • Confirm that the frontend or client is subscribed to the
lk.transcription
topic. • If audio output is turned off, you’ll want to set up a custom receiver to listen to the
lk.transcription
text stream topic. • On the agent side, keep an eye on the
conversation_item_added
event to know when text input or output gets added to the chat history. Please feel free to reach out if you’d like a hand setting up the right subscription or if you want to troubleshoot this further—I’m here to help! Sources: How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents | Agents 0.x migration guide | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docs | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs
b
t
Hi there! It looks like the
chat-stream-receiver.py
example might be having some trouble, and that can happen for a few reasons. Let’s walk through some things to check together: • First, please make sure the
LIVEKIT_URL
environment variable is set up correctly. • When you run the script, don’t forget to provide a room name as a command-line argument. • Also, double-check that the sender is publishing text to the right topic, which should be
lk.transcription
for agent output. • It’s important that the sender includes necessary attributes like
segment_id
in the text stream. • And if you’re testing with the playground UI, just a heads-up: it doesn’t support text-only agent responses sent to
lk.transcription
. If you’d like, I’m here to help you verify your setup or troubleshoot any other issues you might be facing. Just let me know! Sources: examples/voice_agents/README.md | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents