when i have interrupted the agent messgae during t...
# ask-ai
l
when i have interrupted the agent messgae during tts, i want the complete transcrption of the agent to be displayed, instead of the partial response until i have interuppted.. how can i do that???
t
Thanks for reaching out, Computer. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like you’re interrupting TTS mid‑utterance and only seeing the transcript up to the point of interruption. By design, the synchronized transcript truncates with spoken audio. To display the full agent message instead, capture the agent’s text from the conversation history rather than the TTS-aligned stream. Two simple options: • Capture committed items ◦ Listen for
conversation_item_added
and render the agent’s full text when the agent turn is committed (even if audio was interrupted). Guide • Manually flush the agent turn ◦ On interruption, call
await session.aclose()
to flush the incomplete agent turn to history, then read it from
session.history
and render that full text. Guide Recording/transcripts Notes: • The TTS-aligned transcript will remain truncated by design when interrupted. Use it for timing, but use history/committed items for full text. Text & transcriptions • If you need to know when audio actually finishes (when not interrupted), subscribe to
playback_finished
on audio output. Detect finish Would you like a minimal code snippet showing
conversation_item_added
handling and the interrupt →
session.aclose()
flow? Sources: Pipeline nodes and hooks | LiveKit docs | How to capture real-time agent transcriptions during conversations | How to detect when an agent has finished speaking | Text and transcriptions | LiveKit docs | ElevenLabs TTS plugin guide | LiveKit Docs
l
yes
t
Great—here’s a minimal Python sketch showing both approaches you asked about: capturing the full agent text via
conversation_item_added
, and flushing on interrupt to render the complete message.
Copy code
from livekit.agents import Agent, AgentSession

# 1) Capture committed items (use this to display full agent text)
def on_item_added(ev):
    if ev.item.role == "assistant":
        # Render/store the full agent text for your UI
        render_full_agent_text(ev.item.text)

async def run_session():
    session = AgentSession(
        # optional: enable tighter TTS-aligned transcripts if supported
        # use_tts_aligned_transcript=True,
    )
    session.on("conversation_item_added", on_item_added)

    # optional: if you want a realtime feed too, capture fragments
    class MyAgent(Agent):
        async def transcription_node(self, task, out):
            async for fragment in await super().transcription_node(task, out):
                save_fragment(fragment)  # interim fragments if you want them
                yield fragment

    agent = MyAgent(session=session)
    await agent.start()

    return session, agent

# 2) On user interrupt: flush the incomplete turn so history has the full text
async def handle_interrupt(session: AgentSession):
    await session.aclose()  # flush incomplete agent turn to history
    # Then pull from history (or rely on on_item_added handler)
    last = session.history[-1] if session.history else None
    if last and last.role == "assistant":
        render_full_agent_text(last.text)

# 3) (Optional) If you need to know when audio actually finished
def on_playback_finished(ev):
    notify_clients_audio_done({"interrupted": ev.interrupted})

# subscribe if needed:
# session.output.audio.on("playback_finished", on_playback_finished)
References: • Text and transcriptions: docs • Capture real-time transcripts and committed items: guide • Pipeline nodes and hooks (
transcription_node
): docs • Turn interruption behavior: docs • Detect when audio finishes: guide Want this adapted for Node.js or with a concrete UI render example? Sources: Text and transcriptions | LiveKit docs | How to capture real-time agent transcriptions during conversations | Pipeline nodes and hooks | LiveKit docs | Turn detection and interruptions | LiveKit Docs | Understanding Transcript Timing in Voice Conversations
l
so this change need to be made in the backend?? and the message should be displayed in the frontend ryt??
t
You’re asking where to make changes and where to show the result. • Backend: Yes—capture/flush the full agent text in the agent/session (e.g., listen to
conversation_item_added
, or call
session.aclose()
on interrupt and read from
session.history
). This is what ensures you have the complete message even if TTS was interrupted. Guide Turns • Frontend: Yes—display the text you receive from the backend (either via your event/RPC from
conversation_item_added
or after the interrupt flush). If you also care about audio-finish state, listen for a backend signal of
playback_finished
. Detect finish If you want, I can outline the minimal event payload you can emit from the backend for the frontend to render.