Real-time voice agent on LiveKit
Voice assistant chaining speech-to-text, GPT-4o and ElevenLabs speech, with per-stage latency metrics.
What it does
A LiveKit Agents worker joins a room and runs a voice pipeline: Silero voice activity detection, OpenAI speech-to-text, GPT-4o for responses and ElevenLabs text-to-speech. A metrics variant subscribes to LLM, STT, end-of-utterance and TTS events and prints token counts, tokens per second, time to first token and durations for latency tuning.
What was built
- 01
Assistant agent combines Silero VAD, OpenAI STT (whisper-1), GPT-4o and ElevenLabs TTS in one AgentSession.
- 02
Entrypoint connects to the LiveKit room and starts the session for each job.
- 03
LLM metrics handler logs prompt and completion tokens, tokens per second and time to first token.
- 04
STT, end-of-utterance and TTS metrics are captured to locate latency in the pipeline.
- 05
ElevenLabs voice IDs can be swapped to change the agent's voice.
The pipeline, layer by layer
Five layers, one pipeline.
L1Transport
- LiveKit room
L2Speech in
- Silero VAD
- Whisper STT
L3Reasoning
- GPT-4o agent session
L4Speech out
- ElevenLabs TTS
L5Observability
- Latency metrics handlers