Skip to content

Latency

The time between “user finishes speaking/typing” and “avatar starts responding on screen” is the sum of several stages, and most of them are yours to tune.

  1. Your input pipeline: speech-to-text, if you’re doing voice input (entirely your stack, not covered by this API).
  2. Sending the turn: your client sends the user’s words to the agent as a text stream on lk.chat. This is one hop over the LiveKit room.
  3. The avatar’s brain: the avatar’s own brain (set in 2wai Studio) writes the reply.
  4. Speech, lip-sync and encoding: 2wai voices the reply in the avatar’s voice, renders the frames and streams them out on the room’s tracks.
  5. Network and transport: LiveKit room join and WebRTC jitter-buffer warmup. Typically the fastest leg on a stable network.

Stages 3 and 4 run on 2wai’s side. The levers you control are below.

  • Keep sessions warm. Creating a session has setup cost. For a multi-turn conversation, create one session and send every turn over the same room rather than creating a new session per turn.
  • Join early. Mint and join the room while the user is still reading or typing, so the agent is ready by the time the first turn is sent. Sending before the agent has joined can lose the turn.
  • Send the turn the right way the first time. A turn sent with publishData, on the wrong topic, blank, over 8,000 characters, or as a JSON object that is not a valid envelope gets no reply, which looks like a very slow one. Send plain text with sendText on lk.chat. See Streaming into your app.
  • Keep LiveKit’s adaptiveStream and dynacast off for 2wai sessions. The agent’s video and audio are the only tracks you care about; adaptive logic can drop the video during brief idle periods, which looks like a stall on the client. Every 2wai SDK ships with these off. If you’re wiring livekit-client yourself, pass new Room({ adaptiveStream: false, dynacast: false }).

Bringing your own brain or TTS, and with it per-sentence /speak flushing and /interrupt on barge-in, is planned but not available on the current gateway (those endpoints answer 409 not_available_on_livekit).

  • Sessions for keeping a session alive across a whole conversation instead of recreating it.
  • Limits & concurrency: running near your concurrency cap can itself introduce queuing delay.