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.
Where the time goes
Section titled “Where the time goes”- Your input pipeline: speech-to-text, if you’re doing voice input (entirely your stack, not covered by this API).
- Your brain: however long your LLM (or logic) takes to decide on a reply. See Bring your own brain.
- Speech synthesis: either 2wai’s TTS (
/speak) or your own (/audio). - Lipsync and encoding: 2wai renders the frames and streams them out.
- Network and buffering: the WebSocket hop and however much your
MediaSourcebuffers 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
/speakadds 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//audiocalls rather than creating a new session per turn. - Use
/interrupton barge-in. If your product supports the user talking over the avatar, callPOST /v1/sessions/{id}/interruptthe 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
/audioas it’s generated (more=truebetween 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
MediaSourceplayer 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.