Which ways can I check in my agent: - if speaking ...
# ask-ai
c
Which ways can I check in my agent: • if speaking out the response has already been started • if the current response has been interrupted
t
Thanks for reaching out, Julian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to detect (1) when the agent has started speaking and (2) whether the current response was interrupted. Two reliable ways: • Use the SpeechHandle returned by session.say() or session.generate_reply() ◦ The returned handle indicates speech generation/playout has begun. ◦ Check
handle.interrupted
after playback (or when the handle resolves) to know if it was interrupted. ◦ Examples: ▪︎ Python:
Copy code
handle = session.say("Hello")
      await handle  # waits for playback to complete
      if handle.interrupted:
          print("Speech was interrupted")
• TypeScript:
Copy code
const handle = session.say("Hello");
      await handle; // waits for completion
      if (handle.interrupted) console.log("Speech was interrupted");
• Listen for agent state changes (agent_state_changed) ◦ Monitor the event and check for
new_state == "speaking"
to detect when speaking starts. ◦ Examples: ▪︎ Python:
Copy code
@session.on("agent_state_changed")
      def on_agent_state_changed(ev):
          if ev.new_state == "speaking":
              print("Agent started speaking")
• TypeScript:
Copy code
session.on(voice.AgentSessionEventTypes.AgentStateChanged, (ev) => {
        if (ev.newState === "speaking") console.log("Agent started speaking");
      });
Notes: • Interruptions occur when the user starts speaking and
allow_interruptions=True
(default), which stops playback and marks the SpeechHandle as interrupted. • If you want, tell me which SDK/language you’re using and whether you prefer event-driven checks or polling, and I’ll provide a short copy-paste snippet for that environment. Sources: Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docs
c
So how could I check in the agents transcription_node of the response that the chunks belong to: • is already being spoken • Is interrupted
t
You're asking whether, inside the agent's
transcription_node
, you can tell if a given transcription chunk is (a) already being spoken or (b) was interrupted. Short answer: you cannot reliably get real-time speaking or interruption status from inside
transcription_node
. It only receives transcription text (or
TimedString
when TTS-aligned transcripts are enabled) for processing; it does not expose the runtime playback state or the
SpeechHandle
interruption flag. What you can do instead (recommended): • Use
TimedString
with
use_tts_aligned_transcript=True
to get word-level `start_time`/`end_time` metadata for when words are scheduled to be spoken. This tells you when words are planned to play, not whether playback actually completed. • Track the actual runtime state and interruptions outside the `transcription_node`: ◦ Monitor
agent_state_changed
events to detect when the agent enters
speaking
. ◦ Track the
SpeechHandle
returned by
session.say()
/
session.generate_reply()
and check
handle.interrupted
after playback or when the handle resolves. ◦ Use the
speech_created
event to get and store the
SpeechHandle
for the current utterance so you can correlate it with transcription output. If helpful, tell me: • Which SDK/language you’re using (Python/TypeScript), and • Whether you want examples showing how to correlate
TimedString
timestamps with a
SpeechHandle
and
agent_state_changed
events — I can provide a short copy-paste snippet. Sources: Pipeline nodes and hooks | LiveKit docs | Text and transcriptions | LiveKit docs | Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docs