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. Your brain: however long your LLM (or logic) takes to decide on a reply. See Bring your own brain.
  3. Speech synthesis: either 2wai’s TTS (/speak) or your own (/audio).
  4. Lipsync and encoding: 2wai renders the frames and streams them out.
  5. Network and buffering: the WebSocket hop and however much your MediaSource buffers before playback.

Stages 1-3 usually dominate; 4 is typically the fastest part once a session is warm.

  • Stream your LLM output and speak in sentence chunks. Waiting for a full paragraph before calling /speak adds the model’s entire generation time to your latency budget. Flushing at sentence boundaries lets the avatar start talking within a second or two of the first tokens arriving. See the streaming example in Bring your own brain.
  • Keep sessions warm. Creating a session has setup cost. For a multi-turn conversation, create one session and drive it with repeated /speak//audio calls rather than creating a new session per turn.
  • Use /interrupt on barge-in. If your product supports the user talking over the avatar, call POST /v1/sessions/{id}/interrupt the moment you detect new input, rather than letting a stale reply finish and queuing the new one behind it.
  • If you bring your own TTS, prefer a streaming-capable engine. Chunking audio to /audio as it’s generated (more=true between chunks) avoids waiting for the entire clip to synthesize before any of it can render. See Bring your own TTS.
  • Don’t over-buffer client-side. A MediaSource player that queues many segments before starting playback trades a smoother start for added latency. The player in Streaming into your app appends segments as they arrive rather than batching them.
  • 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.