Speech, Voice Agents and Realtime Audio
Transcribe speech, synthesize voices and build low-latency voice assistants with speech-to-text, text-to-speech and realtime APIs.
Intermediate · about 5 hours · difficulty 3/5
Learn first: Streaming Responses, Tool and Function Calling
Voice interfaces add two conversions around your text pipeline, or replace them with a single speech-to-speech model.
Building blocks
- Speech-to-text (STT): Whisper (open weights) and hosted transcription APIs convert audio to text, with timestamps and speaker labels on some services.
- Text-to-speech (TTS): hosted voices from model providers and specialist vendors turn replies into natural audio, often streaming.
- Realtime / speech-to-speech APIs: a single model hears audio and speaks back over a WebSocket or WebRTC connection, with lower latency and more natural turn-taking.
Two architectures
- Cascade (STT then LLM then TTS): flexible, easy to debug, any text model and tools work, but latency adds up.
- Native realtime: faster and more expressive, with less control and higher cost.
What makes voice hard
- Latency budget: people notice pauses above roughly a second. Stream everything and start speaking before the full reply is ready.
- Turn detection and interruptions: voice activity detection decides when the user has finished, and the agent must stop talking when interrupted.
- Audio quality: noise, accents and phone-line audio reduce accuracy.
- Consent and misuse: disclose AI voices and never clone a voice without permission.
Good enough to move on
You can build a voice assistant that transcribes speech, answers with a tool-using model and speaks back with streaming TTS, and you can measure its end-to-end latency.
Key concepts
- Speech-to-text and Whisper
- Text-to-speech voices
- Cascade voice pipelines
- Realtime speech-to-speech APIs
- Turn detection and interruptions
- Latency budgeting
- Voice consent and disclosure
Mini project
Build a browser voice assistant for a restaurant that takes spoken orders, calls a menu lookup tool, confirms the order aloud, and logs latency for each stage of the pipeline.
Check yourself
Where does the latency go in a cascade voice pipeline, and which stage would you stream first?
Free resources
- OpenAI docs: speech to text (OpenAI)
- OpenAI docs: realtime API (OpenAI)
- Gemini API: Live API (Google)
- Hugging Face Audio Course (Hugging Face)