Skip to main content

Overview

This guide is for voice agents that connect AssemblyAI’s AssemblyAI-STT-3.7-Realtime-Agent WebSocket directly to a custom LLM and TTS, with no LiveKit, Pipecat, or other orchestrator in the loop. AssemblyAI-STT-3.7-Realtime-Agent is AssemblyAI’s most accurate real-time model for voice agents, with entity-aware turn detection, native code-switching across 32 languages, and prompting support. The protocol is documented in detail on the AssemblyAI-STT-3.7-Realtime-Agent quickstart and message sequence pages. This guide focuses on the voice-agent loop and how to handle barge-in and interruptions correctly.

Quickstart

A minimal Python consumer that connects to the streaming WebSocket and reacts to Begin, Turn, SpeechStarted, and Termination events:
For the full message protocol, including all event fields, audio framing, and termination, see the message sequence reference.

Turn detection

AssemblyAI-STT-3.7-Realtime-Agent doesn’t end turns on silence alone. When the speaker pauses, the model judges from the transcript whether the speaker is finished, and holds the turn open when it ends in an entity that may still continue, such as part of a phone number. Two parameters control the timing, and the mode preset sets their defaults:
  • min_turn_silence is the silence before the model runs an end-of-turn check. If the turn reads as complete, it ends.
  • max_turn_silence is the maximum silence before the turn is forced to end, regardless of content.
See Turn detection for entity-aware endpointing, tuning guidance, and manual mode, and the message sequence reference for the full event protocol.

Interruption handling

While the agent is speaking, users often produce backchannel utterances (“mhm”, “yeah”, “um”, “okay”) that you don’t want to treat as interruptions. A barge-in trigger that fires on every SpeechStarted (or every short Turn) will cause the agent to stop mid-sentence even though the user didn’t intend to interrupt. The recommended fix is a single combined filter applied to each Turn event during agent speech: skip the barge-in if the transcript is short or if every token is a known backchannel. Reset the filter once the agent has finished speaking.
How it works:
  1. While the agent is speaking (plus a 1-second grace window after speech ends), each Turn event is checked.
  2. _should_suppress_interrupt returns True when the transcript has fewer than MIN_WORDS tokens or when every token is a known backchannel. Either condition drops the event.
  3. Utterances with any non-filler content past the threshold (e.g., “yeah I’d like the suite”) always pass through.
  4. SpeechStarted is gated through the same Turn-level check rather than firing barge-in directly. This prevents a race where a backchannel triggers SpeechStarted before the gating logic sees the transcript.
The BACKCHANNELS set is domain-customizable. “yes” and “no” are deliberately excluded because they often represent genuine confirmations in booking or IVR scenarios. Edit the set for your use case. MIN_WORDS = 2 is a reasonable default. Raise it if you see frequent two-word filler (“uh okay”, “yeah right”) slipping through.
If you’re building on LiveKit, prefer LiveKit’s adaptive interruption handling. See LiveKit > Interruption handling. The strategy on this page is the equivalent for direct-WebSocket integrations.
Three presets covering most voice-agent use cases:
For cross-cutting topics like dynamic configuration updates, scaling, latency budgeting, and evals, see the voice agent best practices guide.