I am using useTranscriptions hook. I need to know ...
# ask-ai
r
I am using useTranscriptions hook. I need to know when the incoming transcript is final.
lk.transcription_final
is always returning
false
Any idea why?
t
Thanks for reaching out, Halil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking why
lk.transcription_final
is always false when using
useTranscriptions
and how to detect final transcripts — here's what to check and what to do next. Possible reasons
lk.transcription_final
stays false • The STT/agent is only sending interim (partial) results and never signals end-of-utterance. Interim results have
transcription_final = false
. • End-of-utterance detection (VAD or STT turn detection) isn't configured, so the pipeline never finalizes segments. •
sync_transcription
is disabled, which can affect when final flags are emitted. • The STT provider/plugin you use doesn’t emit final transcripts reliably without extra configuration (some providers stream partial results indefinitely). What you can do now 1. Verify the STT/agent settings: ◦ Ensure end-of-utterance detection (VAD or the STT provider’s turn-detection) is enabled. ◦ If using a plugin (e.g., AssemblyAI), confirm its finalization settings are configured to emit final transcripts. 1. Check `sync_transcription`: ◦ Make sure
sync_transcription
is enabled if your flow relies on synchronized final events. 1. Use the event that guarantees final text: ◦ Listen for
conversation_item_added
(this event contains only committed/final messages). Combine
useTranscriptions
for interim updates with
conversation_item_added
to detect finalized transcripts reliably. If you want, tell me: • which STT/provider or plugin you’re using, • whether you’ve enabled VAD or
sync_transcription
, and I’ll give tailored steps for that setup. Sources: Text and transcriptions | LiveKit docs | AssemblyAI plugin guide | LiveKit Docs | Events and error handling | LiveKit docs
r
Vad is enabled. STT is
assemblyai/universal-streaming:en
. I haven’t set any explicit values to
sync_transcription
This also happens as the agent speaks.
t
Thanks — that helps. You're using AssemblyAI (
assemblyai/universal-streaming:en
) with VAD enabled and no explicit
sync_transcription
set. That explains the behavior. Why
lk.transcription_final
stays false • Synchronized transcription is enabled by default, so transcriptions are streamed in real time while speech is ongoing. LiveKit forwards incremental words in sync with the audio, keeping
lk.transcription_final = false
until the full turn is finished. • VAD detects audio activity but doesn't force transcription finalization; finalization depends on the STT backend (AssemblyAI) and the LiveKit sync setting. What to do • Disable synchronized transcription so final transcripts are emitted when AssemblyAI finalizes a segment: ◦ Python: set
room_io.TextOutputOptions(sync_transcription=False)
in
RoomOptions
when starting the session. ◦ Node.js: set
outputOptions.syncTranscription = false
(or
syncTranscription: false
) when calling
session.start
. • After disabling sync, listen to
useTranscriptions
for interim updates and use
lk.transcription_final === true
to detect finals — or rely on
conversation_item_added
for guaranteed committed messages. If you want, tell me which runtime (Python or Node.js) you're using and I’ll give the exact code snippet to change
sync_transcription
. Sources: Text and transcriptions | LiveKit docs | AssemblyAI STT | LiveKit Docs
r
How do I listen
conversation_item_added
on the React side?
t
You're asking how to listen for
conversation_item_added
in React. That event is emitted only inside the agent backend and isn't available directly in the frontend. Instead, read finalized transcriptions that are mirrored to the client via the agent participant's
lk.transcription
text track. Two simple ways to get finalized transcriptions in React: 1) Use the LiveKit components to render the text track • Find the agent participant (e.g., via
useParticipants()
). • Use the
TextTrack
component with the agent's
lk.transcription
track to receive updates. 2) Manually subscribe to the agent's
lk.transcription
track • Get the agent participant, then:
Copy code
const track = agent.getTrackByTopic('lk.transcription');
if (track) {
  const handle = (msg: string) => {
    // msg contains transcription chunks; check msg metadata or fields for final flag
    console.log('transcription:', msg);
  };
  track.on('message', handle);
  return () => track.off('message', handle);
}
Notes: • Finalized, committed messages are also emitted server-side as
conversation_item_added
, but the frontend receives the equivalent final text via the
lk.transcription
text stream. • If you need a guaranteed “final” marker in the frontend, combine
lk.transcription
updates with
lk.transcription_final === true
in the message payload, or rely on
conversation_item_added
on the backend and forward a custom participant attribute or data message to clients. If you want, tell me which LiveKit React SDK version you’re using and I’ll provide a small, runnable example for that version. Sources: Text and transcriptions | LiveKit docs
r
“@alert-easter-19258/components-react”: “2.9.17"
t
You're on @livekit/components-react 2.9.17 — good. Quick answer:
conversation_item_added
is backend-only. On the React client, read finalized transcriptions from the agent participant's
lk.transcription
text track. Below are two concise patterns for v2.9.17. 1) Using the provided TextTrack component
Copy code
import { useParticipants, TextTrack } from "@livekit/components-react";

export function TranscriptionsView() {
  const participants = useParticipants();
  const agent = participants.find(p => p.identity?.startsWith("agent")); // adjust selector

  if (!agent) return null;

  const track = agent.getTrackByTopic("lk.transcription");
  if (!track) return null;

  return (
    <TextTrack
      track={track}
      onTextTrackMessage={(msg) => {
        // msg is the transcription payload; check msg.lk?.transcription_final
        console.log("text track msg:", msg);
      }}
    />
  );
}
2) Manual subscription to the text track messages
Copy code
import { useEffect } from "react";
import { useParticipants } from "@livekit/components-react";

export function TranscriptionListener() {
  const participants = useParticipants();
  const agent = participants.find(p => p.identity?.startsWith("agent"));

  useEffect(() => {
    if (!agent) return;
    const track = agent.getTrackByTopic("lk.transcription");
    if (!track) return;

    const handle = (event: any) => {
      // event contains transcription text and metadata
      // check event.lk?.transcription_final === true for final
      console.log("transcription event:", event);
    };

    track.on("message", handle);
    return () => track.off("message", handle);
  }, [agent]);

  return null;
}
Notes: • The message payload on the
lk.transcription
track contains the transcription text and
lk.transcription_final
(true when final). Use that flag to detect finals. • If you need server-side
conversation_item_added
semantics, forward a custom data message or participant attribute from your backend when you handle
conversation_item_added
. The frontend cannot directly subscribe to that backend-only event. Would you like a complete runnable example (including how to pick the agent participant reliably)?
r
lk.transcription_final is still always file after setting
syncTranscription: false
t
Thanks — I’ll help debug why
lk.transcription_final
stays false. I’m responding to your note that you set
syncTranscription: false
, use AssemblyAI (
assemblyai/universal-streaming:en
), and VAD is enabled. Quick checklist and targeted debugging steps — please share the items I ask for after: 1) Confirm text stream and attribute reading • Verify you’re reading the
lk.transcription
text track and checking the attribute
lk.transcription_final
on the message attributes (not a different field). • If you’re using the LiveKit text-track message object, inspect
reader.info.attributes["lk.transcription_final"]
(or the message payload’s
lk.transcription_final
) to see `"true"`/`"false"`. 2) Ensure final events are emitted by AssemblyAI • AssemblyAI must emit
FINAL_TRANSCRIPT
(end-of-utterance). With
syncTranscription: false
, LiveKit forwards the final stream when AssemblyAI finalizes. Confirm AssemblyAI is seeing endpointing (check its logs/events for
FINAL_TRANSCRIPT
). 3) Confirm Room/Agent start options • Share the code you use to start the AgentSession (or session.start) so I can confirm
syncTranscription
is actually set in the running session. Example needed for either Python or Node.js. 4) Check user/agent turn detection • Even with VAD on, finalization depends on turn endpointing. Do you see
user_state_changed
=>
listening
or
user_input_transcribed
(is_final=true) events server-side when speech ends? 5) Verify you’re receiving the final text stream (separate streams) • With sync disabled there are separate interim and final streams. Add logging on the backend right before publishing to the
lk.transcription
stream to confirm the code publishes the final stream and sets the attribute to true. What to send me (paste small snippets): • The code where you start the agent session (Node or Python) showing
TextOutputOptions
/
outputOptions
. • The frontend snippet where you subscribe to
lk.transcription
(the listener using
track.on('message', ...)
) and how you read the attributes. • Any server-side logs or AssemblyAI event logs showing interim vs final transcript events around one sample utterance. If you want, I can provide exact lines to add to your backend and frontend to log the raw message + attributes so we can pinpoint whether finality is lost before or after LiveKit publishes the text stream. Which environment (Node or Python) should I target? Sources: Text and transcriptions | LiveKit docs | AssemblyAI plugin guide | LiveKit Docs | Events and error handling | LiveKit docs
r
Copy code
const transcriptions = useTranscriptions();
  useEffect(() => {
    if (transcriptions.length === 0) {
      return;
    }

    const latest = transcriptions[transcriptions.length - 1];
    const isFinal = latest.streamInfo.attributes?.['lk.transcription_final'] === 'true';
    upsertMessage({
      message: {
        id: latest.streamInfo.id,
        type: 'text',
        content: latest.text,
        isAssistant: latest.participantInfo.identity !== room.localParticipant.identity,
        timestamp: latest.streamInfo.timestamp,
      },
      isFinal,
    });
  }, [transcriptions, room.localParticipant.identity]);
t
Thanks — I reviewed your React snippet. It looks correct for reading
lk.transcription_final
, so next step is to confirm where the final flag is (or isn't) coming from. Quick checklist and two focused debugging steps: 1) Verify backend is publishing final streams • On the agent/server where AssemblyAI runs, add a log right before publishing to the
lk.transcription
text stream that prints the outgoing message attributes and event type (interim vs final). Confirm you see
lk.transcription_final: "true"
there for a finished utterance. • If you don't see that, AssemblyAI or your agent logic isn't marking the segment final (check AssemblyAI event
FINAL_TRANSCRIPT
/ endpointing settings like
max_turn_silence
/
end_of_turn_confidence_threshold
). 2) Confirm the frontend is reading attributes (small extra logging) • In your effect, add a console.log of the raw
latest.streamInfo
to confirm the attribute path and value: ◦ log
latest.streamInfo
and
latest.streamInfo.attributes
(or
latest.streamInfo.attributes['lk.transcription_final']
). • Also log the full
transcriptions
array for one utterance to ensure you’re not always reading interim items only. If both backend logs show the final attribute set to "true" but the frontend still shows false: • Share the backend snippet where you call
session.start
(Node or Python) showing
syncTranscription
/
TextOutputOptions
, and the backend publish/log code around
lk.transcription
. I’ll point out exactly what to adjust. If the backend never shows a final event: • Share AssemblyAI plugin config (or agent STT config) so I can suggest the specific endpointing parameters to change.
r
Give me code snippets for both steps
t
Below are concise runnable-style snippets for both backend (Node + Python) logging/publishing and frontend React logging so you can trace where the final flag is lost. They focus only on the relevant pieces to add. Backend — Node (agent/session start + logging before publishing)
Copy code
// When starting the AgentSession (ensure syncTranscription is false)
await session.start({
  agent: myAgent,
  room: ctx.room,
  outputOptions: {
    syncTranscription: false,
  },
});

// Example handler: log transcription events and attributes before publishing
// (adjust to your agent/plugin event names)
sttPlugin.on('INTERIM_TRANSCRIPT', (evt) => {
  console.log('[STT] INTERIM', { text: evt.text, attrs: evt.attributes });
  // publish interim to lk.transcription as you already do
});

sttPlugin.on('FINAL_TRANSCRIPT', (evt) => {
  console.log('[STT] FINAL', { text: evt.text, attrs: evt.attributes });
  // ensure you set lk.transcription_final attribute when publishing
  const attrs = { 'lk.transcription_final': 'true', ...evt.attributes };
  await session.publishText({
    topic: 'lk.transcription',
    text: evt.text,
    attributes: attrs,
  });
  console.log('[LIVEKIT] published FINAL with attrs', attrs);
});
Backend — Python (AgentSession start + logging before publishing)
Copy code
# ensure sync_transcription is False when starting
await session.start(
    agent=my_agent,
    room=ctx.room,
    room_options=room_io.RoomOptions(
        text_output=room_io.TextOutputOptions(sync_transcription=False),
    ),
)

# Example STT callbacks
def on_interim(evt):
    print("[STT] INTERIM", {"text": evt.text, "attrs": getattr(evt, "attributes", None)})
    # publish interim as you do

def on_final(evt):
    print("[STT] FINAL", {"text": evt.text, "attrs": getattr(evt, "attributes", None)})
    attrs = {"lk.transcription_final": "true", **(getattr(evt, "attributes", {}) or {})}
    # publish to lk.transcription (example API)
    await session.publish_text(
        topic="lk.transcription",
        text=evt.text,
        attributes=attrs,
    )
    print("[LIVEKIT] published FINAL with attrs", attrs)
Frontend — React (extra logging in your useEffect to inspect raw message + attributes)
Copy code
const transcriptions = useTranscriptions();
useEffect(() => {
  if (transcriptions.length === 0) return;

  console.log('[UI] transcriptions raw', transcriptions);

  const latest = transcriptions[transcriptions.length - 1];
  console.log('[UI] latest.streamInfo', latest.streamInfo);
  console.log('[UI] latest.streamInfo.attributes', latest.streamInfo.attributes);

  const attrVal = latest.streamInfo.attributes?.['lk.transcription_final'];
  console.log('[UI] lk.transcription_final raw value:', attrVal);

  const isFinal = attrVal === 'true';
  upsertMessage({
    message: {
      id: latest.streamInfo.id,
      type: 'text',
      content: latest.text,
      isAssistant: latest.participantInfo.identity !== room.localParticipant.identity,
      timestamp: latest.streamInfo.timestamp,
    },
    isFinal,
  });
}, [transcriptions, room.localParticipant.identity]);
Frontend — manual text track subscription (if you want to inspect incoming track messages)
Copy code
useEffect(() => {
  const agent = participants.find(p => p.identity?.startsWith('agent'));
  if (!agent) return;
  const track = agent.getTrackByTopic('lk.transcription');
  if (!track) return;

  const handle = (msg: any) => {
    console.log('[track message] raw', msg);
    // msg may contain text and attributes depending on SDK shape
    const attrs = msg?.lk || msg?.attributes || msg?.info?.attributes;
    console.log('[track message] attrs', attrs);
  };

  track.on('message', handle);
  return () => track.off('message', handle);
}, [participants]);
What to watch for • Backend logs should show AssemblyAI emitting FINAL and you publishing with
lk.transcription_final: "true"
. • Frontend logs should show the same attribute value on the
latest.streamInfo.attributes['lk.transcription_final']
. • If backend shows final with attr=true but frontend shows false/missing, paste the backend publish call and a sample raw frontend log and I’ll point out why it wasn’t preserved. Send one representative pair of logs (backend FINAL publish log and the corresponding frontend
transcriptions
raw print) and I’ll analyze the mismatch.
r
I am using Livekit Inference for STT
t
Thanks — since you’re using LiveKit Inference for STT, the flow is the same: finality depends on the inference/STT pipeline emitting a final event and LiveKit publishing that final text with
lk.transcription_final: "true"
. Below are concise, focused snippets for LiveKit Inference setups (Node + Python) and the frontend so you can verify where the final flag is set or lost. Backend — Node (LiveKit Inference + logging before publish)
Copy code
// ensure syncTranscription is false when starting the agent session
await session.start({
  agent: myAgent,
  room: ctx.room,
  outputOptions: {
    syncTranscription: false,
  },
});

// Example: attach to inference transcription events (pseudo-handler name)
inference.on('transcription', async (evt: any) => {
  // evt.type might be 'INTERIM' or 'FINAL' depending on inference
  console.log('[INFERENCE] event', evt.type, evt.text, evt);
  const isFinal = evt.type === 'FINAL' || evt.is_final === true;

  const attrs = { ...(evt.attributes || {}), 'lk.transcription_final': isFinal ? 'true' : 'false' };

  // publish to lk.transcription explicitly so we know attributes used
  await session.publishText({
    topic: 'lk.transcription',
    text: evt.text,
    attributes: attrs,
  });

  console.log('[LIVEKIT] published lk.transcription', { text: evt.text, attrs });
});
Backend — Python (LiveKit Inference + logging before publish)
Copy code
# start session with sync_transcription disabled
await session.start(
    agent=my_agent,
    room=ctx.room,
    room_options=room_io.RoomOptions(
        text_output=room_io.TextOutputOptions(sync_transcription=False),
    ),
)

# handle inference transcription callback
async def on_transcription(evt):
    # evt.type == 'FINAL' or 'INTERIM' or evt.is_final
    print("[INFERENCE] event", evt.type, getattr(evt, "text", None), evt)
    is_final = (evt.type == "FINAL") or getattr(evt, "is_final", False)

    attrs = {**(getattr(evt, "attributes", {}) or {}), "lk.transcription_final": "true" if is_final else "false"}

    await session.publish_text(
        topic="lk.transcription",
        text=evt.text,
        attributes=attrs,
    )
    print("[LIVEKIT] published lk.transcription", {"text": evt.text, "attrs": attrs})
Frontend — React (extra logging in useTranscriptions)
Copy code
const transcriptions = useTranscriptions();
useEffect(() => {
  if (transcriptions.length === 0) return;

  console.log('[UI] all transcriptions', transcriptions);

  const latest = transcriptions[transcriptions.length - 1];
  console.log('[UI] latest.streamInfo', latest.streamInfo);
  console.log('[UI] latest.streamInfo.attributes', latest.streamInfo.attributes);

  const attrVal = latest.streamInfo.attributes?.['lk.transcription_final'];
  console.log('[UI] lk.transcription_final raw value:', attrVal);

  const isFinal = attrVal === 'true';
  upsertMessage({
    message: {
      id: latest.streamInfo.id,
      type: 'text',
      content: latest.text,
      isAssistant: latest.participantInfo.identity !== room.localParticipant.identity,
      timestamp: latest.streamInfo.timestamp,
    },
    isFinal,
  });
}, [transcriptions, room.localParticipant.identity]);
Frontend — raw text-track subscription (inspect incoming messages)
Copy code
useEffect(() => {
  const agent = participants.find(p => p.identity?.startsWith('agent'));
  if (!agent) return;
  const track = agent.getTrackByTopic('lk.transcription');
  if (!track) return;

  const handle = (msg: any) => {
    console.log('[track message] raw', msg);
    // check common places for attributes
    console.log('[track message] potential attrs', msg?.lk, msg?.attributes, msg?.info?.attributes);
  };

  track.on('message', handle);
  return () => track.off('message', handle);
}, [participants]);
What to compare • Backend log when inference emits FINAL and the subsequent publish log that includes
lk.transcription_final: "true"
. • Frontend logs showing the same transcription item and the
latest.streamInfo.attributes['lk.transcription_final']
value. If you see: • Backend shows FINAL and published attr="true", but frontend attr is missing/false → paste the backend publish call and a sample frontend raw log. I’ll point out why attributes might be dropped. • Backend never shows FINAL → the inference pipeline isn’t endpointing; share the inference config or logs so I can suggest endpointing parameters (e.g., silence thresholds, confidence thresholds). Would you like me to review one pair of logs (one backend FINAL publish log and the corresponding frontend raw log)? Send them and I’ll analyze.