LevelUpWith

Explore / AI Engineering

Voice and Realtime AI Agents: From Mic to Phone Line

Build voice agents you can ship. Wire up speech-to-text, LLM and text-to-speech pipelines or native speech-to-speech models, handle turn-taking and barge-in, connect a phone line, measure latency and cost, and test with simulated callers.

Read lesson 1 free →

Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor.

Photographic 3D course artwork for Voice and Realtime AI Agents: From Mic to Phone Line

Expert · 48 levels · 4 free · Created Nov 2026 · Professionally curated by levelupwith.com

What's inside

  1. Level 1: Anatomy of a Spoken ConversationFree
    Learn what makes voice harder than chat: people expect a reply within a fraction of a second, they interrupt and talk over each other, and an agent has to listen, think and speak in an unbroken loop.
    • Describe the listen, think, speak loop of a voice agent and the job each stage does
    • Explain why the wait that feels fine in a chat window feels broken on a call
    • Record a short human conversation and mark its turn gaps and overlaps on a timeline
  2. Level 2: Digital Audio Basics: Samples, Rates and BitsFree
    Understand raw PCM audio (sample rate, bit depth, channels) and why voice systems mostly run at 8, 16, 24 or 48 kHz.
    • Work out the byte size of one second of 16 kHz, 16-bit mono PCM in Python and in TypeScript
    • Capture microphone audio, save it as a WAV file and inspect its header
    • Explain how the sample rate limits which frequencies survive and why 8 kHz phone audio sounds muffled
  3. Level 3: Frames, Chunks and Streaming Buffers
    Learn how live audio moves as small fixed-length frames (usually 10–40 ms) through queues and buffers, and what goes wrong when a buffer runs too high or runs dry.
    • Split a PCM stream into 20 ms frames and work out the byte count per frame
    • Build a simple jitter buffer and watch it trade added delay against dropouts
    • Spot buffer underruns and overruns from logs and from how the audio sounds
  4. Level 4: Codecs, Containers and Resampling
    Compare the codecs you will meet in voice work (PCM, Opus, G.711 μ-law and A-law, MP3) and learn to resample and transcode between them safely.
    • Convert 8 kHz μ-law phone audio to 16 kHz PCM and back, in Python and in TypeScript
    • Choose the right codec for browser, phone and model-API paths and explain the bandwidth and quality trade-offs
    • Catch the classic errors: sample rate mismatch, wrong byte order, and stereo where mono was expected
  5. Level 5: The Cascaded Pipeline: STT, LLM, TTS
    Build a minimal working voice loop that chains speech-to-text, a text LLM such as Claude, GPT or Gemini, and text-to-speech, and see what each step passes to the next.
    • Wire a turn-by-turn STT to LLM to TTS loop in Python or TypeScript, with the model provider set in config
    • Swap the LLM between Claude, an OpenAI model, a Gemini model and an open-weight model without changing the audio code
    • List what a cascade gives you: transcripts, text-level control, and free choice of each component
  6. Level 6: Native Speech-to-Speech Models
    Learn how speech-to-speech models such as OpenAI's Realtime models and Gemini Live take in audio and produce audio directly, and what you gain and lose compared with a cascade.
    • Explain the architectural difference between a cascade and a speech-to-speech session in terms of latency, prosody, control and debuggability
    • Open a basic speech-to-speech session and exchange one spoken turn
    • Pick a design for a given use case and state the trade-off honestly, noting where practice is still unsettled
  7. Level 7: The Latency Budget: Where Milliseconds Go
    Break voice-to-voice latency into its stages (capture, network, end-of-turn wait, STT finalisation, LLM time to first token, TTS time to first byte, playback) and set a target budget for each.
    • Draw a stage-by-stage latency budget for a cascaded agent and for a speech-to-speech agent
    • Find which stages are fixed costs and which ones you can tune
    • Explain why the wait for the end of a turn often costs more than model inference does
  8. Level 8: Instrumenting and Measuring Latency
    Add timestamps at every stage boundary so you can measure real voice-to-voice latency and report percentiles instead of averages.
    • Add per-stage timing to the Level 5 pipeline in Python and in TypeScript
    • Measure user-stopped-speaking to agent-started-speaking over 50 turns and report p50, p90 and p99
    • Find the slowest stage from your data and run one experiment to shrink it
  9. Level 9: Streaming Speech-to-Text: Partials and Finals
    Use streaming STT, which returns interim (partial) transcripts that keep changing before they settle into final ones, and decide when your agent should act on each.
    • Stream microphone audio to a streaming STT API and log partial and final results with timestamps
    • Measure how often partial transcripts change before they become final
    • Decide when to start LLM work on a partial transcript and when to wait for the final one
  10. Level 10: STT Accuracy on Your Own Audio
    Measure transcription quality with word error rate on audio from your real domain, and improve it with keyword and vocabulary hints and post-processing for names, numbers and codes.
    • Compute word error rate for two STT providers, one an open-weight model, on a small labelled test set
    • Use vocabulary or keyterm hints to fix domain words such as product names and order IDs
    • Explain why a low average WER can still hide errors on the words that matter most to the task
  11. Level 11: The LLM Layer for Speech
    Prompt and configure a text LLM for spoken output: short turns, no markdown, spoken-friendly wording, streamed tokens and fast time to first token.
    • Write a system prompt that produces short, speakable replies with no lists, URLs or markdown
    • Measure time to first token across Claude, OpenAI, Gemini and an open-weight model on the same prompts
    • Stream tokens into the next stage instead of waiting for the full reply
  12. Level 12: Streaming Text-to-Speech
    Feed streamed LLM text into streaming TTS by splitting it at sentence or phrase boundaries, and normalise numbers, dates and symbols so they are spoken correctly.
    • Chunk a token stream into phrases and measure TTS time to first audio byte
    • Normalise text such as currency, dates, phone numbers and abbreviations before it reaches TTS
    • Weigh smaller chunks for lower latency against larger chunks for more natural intonation
  13. Level 13: Choosing a Voice
    Judge TTS voices on naturalness, clarity, prosody, consistency and brand fit, using structured listening tests rather than first impressions.
    • Run a blind listening test that compares voices from three TTS providers, including one open-weight model
    • Use any pronunciation and style controls the provider offers to fix mispronounced domain terms
    • Write a voice choice brief covering persona, speaking rate and what suits a phone line versus a browser
  14. Level 14: Hands-On with a Realtime Speech-to-Speech API
    Build a working session on a native realtime API: configure the session, stream audio up and down, handle server events and read the transcripts it returns alongside the audio.
    • Open a realtime session in Python or TypeScript, set instructions and voice, and hold a multi-turn spoken exchange
    • Handle the session's event stream: audio deltas, transcript events, errors and session end
    • Measure voice-to-voice latency with the Level 8 harness and compare it with your cascade
  15. Level 15: Comparing Speech-to-Speech Options Side by Side
    Put OpenAI's realtime models, Gemini Live and open-weight speech models through the same tasks, and look at hybrid designs that pair speech in with text reasoning by Claude or another LLM.
    • Run one scripted conversation through two hosted speech-to-speech APIs and score latency, accuracy and naturalness
    • Check current model names, availability and deprecation dates against the providers' own docs rather than blog posts
    • Describe a hybrid architecture and say when it beats both a pure cascade and pure speech-to-speech
  16. Level 16: Multilingual Speech and Code-Switching
    Handle callers who speak different languages, or mix languages within one turn, by choosing between language detection, a fixed language per session, and voices and models matched to each language.
    • Measure STT accuracy for the same script in three languages and spot where quality drops
    • Route a session to the right STT language, LLM instructions and TTS voice based on detected or declared language
    • Test how a pipeline copes when a caller switches language mid-conversation
  17. Level 17: Accents, Noise and Real-World Audio
    Make speech recognition hold up for different accents, background noise, echo and 8 kHz phone audio, and measure fairness across groups of speakers.
    • Build a test set that spans accents and noise conditions and report WER for each slice
    • Apply noise suppression and echo cancellation and measure whether they help or hurt recognition
    • Find accent-related accuracy gaps and record how you will mitigate them
  18. Level 18: Voice Cloning: Consent and Disclosure
    Learn the consent, provenance and disclosure duties that come with cloned and synthetic voices, and build consent capture and AI disclosure into the product from the start.
    • Design a voice-cloning consent flow that records who consented, to what use, and for how long
    • Add a clear AI disclosure at the start of a conversation and explain why the rules differ by jurisdiction
    • List cloning misuse risks such as impersonation and fraud, and the controls that reduce them
  19. Level 19: Voice Activity Detection
    Detect when someone is speaking with energy-threshold and neural voice activity detectors such as Silero VAD, and tune thresholds, padding and minimum durations.
    • Run an energy-based detector and a neural VAD on the same noisy recordings and compare false triggers
    • Tune activation threshold, minimum speech length and silence padding for phone audio and for browser audio
    • Explain why VAD tells you someone is speaking but not that they have finished their turn
  20. Level 20: Detecting the End of a Turn
    Decide when the user has finished speaking by combining silence timeouts with semantic turn-detection models that read the words as well as the pauses.
    • Implement a silence-timeout endpointer and measure how often it cuts people off against how long it makes them wait
    • Add a semantic end-of-turn check and compare its latency and its rate of cutting people off with the timeout alone
    • Set different end-of-turn thresholds for contexts like reading out a card number versus small talk
  21. Level 21: Model-Based End-of-Turn Detection
    Learn why silence timers alone cut people off or leave dead air, and how end-of-turn models such as Pipecat's open Smart Turn, LiveKit's turn detector and OpenAI Realtime's semantic_vad use word and tone cues to decide when the caller has finished.
    • Add an open end-of-turn model to a VAD-only pipeline in Python or TypeScript, then compare how often each version interrupts too early and how much delay it adds on a set of recorded test phrases
    • Configure the built-in turn detection of a native speech-to-speech session (for example switching OpenAI Realtime from server_vad to semantic_vad and setting eagerness), and explain when to turn it off so an outside detector can take over
    • Choose minimum and maximum endpointing delays for a given use case and say what that costs: speed against cutting the caller off
  22. Level 22: Barge-In: Stopping the Agent Mid-Sentence
    Make the agent stop talking the moment the caller interrupts: cancel the LLM and TTS streams, clear queued audio, and cut the conversation history down to what the caller actually heard.
    • Build an interruption handler that cancels in-flight generation, flushes the playback buffer and measures the time from caller speech to agent silence
    • Cut the assistant's last message down to what was actually played, using playback position or word timestamps, so the model doesn't think it said things the caller never heard
    • Explain why barge-in that works in a quiet room can break on a speakerphone, and how echo cancellation fits into the design
  23. Level 23: False Interruptions, Backchannels and Echo
    Tell real interruptions apart from 'mm-hm', coughs, background noise and the agent's own voice echoing back, so the agent neither stops for nothing nor talks over the caller.
    • Set up interruption rules (minimum speech length, minimum word count, resuming after a false interruption) and tune them against recorded noisy samples
    • Find echo-triggered self-interruptions in call logs and fix them with acoustic echo cancellation or by changing when the mic is active
    • Write down the trade-off between quick barge-in and robustness to noise for two different deployments, such as a quiet web app and a noisy phone line
  24. Level 24: Tool Calls Mid-Conversation
    Let the agent call functions during a live conversation in both cascaded and speech-to-speech designs, and see how tool calls hit the latency budget and the turn structure.
    • Define the same tool for Claude, OpenAI, Gemini and an open-weight model in a cascaded pipeline, and handle function-call events in a native realtime session
    • Time the stages from end of turn to first audio when a tool is called, and point out where the extra round trip shows up
    • Validate tool arguments heard from speech (names, numbers, dates) before acting on them, and ask the caller to confirm when the transcript is uncertain
  25. Level 25: Filling Dead Air During Slow Tools
    Keep the conversation going while tools run, using spoken holding phrases, asynchronous tool execution and safe handling of results that arrive after the caller has moved on.
    • Add a short spoken filler or progress update that plays while a tool runs longer than a set threshold, without repeating itself or blocking barge-in
    • Run a long tool in the background and feed its result back into the conversation, handling the case where the caller has interrupted or changed topic in the meantime
    • Decide which actions need spoken confirmation before running (payments, bookings, cancellations), and log every tool call so it can be audited
  26. Level 26: Streaming Audio Over WebSockets
    Move audio in real time over a WebSocket: framing, encoding, buffering and backpressure, plus where TCP's ordered delivery hurts on poor networks.
    • Build a Python or TypeScript WebSocket relay that streams PCM frames between a client and an STT or realtime model API, with explicit chunk sizes and a jitter buffer
    • Measure how latency drifts under simulated packet loss and limited bandwidth, and explain head-of-line blocking from your own numbers
    • Choose WebSockets correctly for server-to-server links and for telephony media streams
  27. Level 27: WebRTC for Browser and Mobile Audio
    Learn what WebRTC gives a voice agent that a raw WebSocket doesn't: UDP transport, Opus, built-in echo cancellation and noise suppression, adaptive jitter buffers, and media servers that do the connection plumbing for you.
    • Connect a browser client to a voice agent over WebRTC, through a media server or a provider's WebRTC endpoint, and compare round-trip latency with the WebSocket version
    • Explain what signalling, ICE, STUN and TURN do, and fix a connection that fails behind a corporate firewall
    • Choose a transport for a given setup (browser, mobile app, server-to-server, phone bridge) and justify the choice
  28. Level 28: Your First LiveKit Agents Voice Agent
    Rebuild the hand-made pipeline with LiveKit Agents: rooms, participants, an agent session and pluggable STT, LLM, TTS and turn detection.
    • Build and run a LiveKit Agents voice agent in Python or Node.js with a cascaded pipeline, and talk to it from the browser playground
    • Swap the LLM between Claude, OpenAI, Gemini and an open-weight model, or swap the pipeline for a realtime model, by changing configuration rather than rewriting code
    • Find where the framework hides each latency stage, and turn on its metrics so you can read the stage timings
  29. Level 29: LiveKit Agents: Tools, State and Handoffs
    Go further with LiveKit Agents: function tools, session state that lasts across turns, and handing over between specialised agents in one call.
    • Add typed function tools to a LiveKit agent and handle errors and timeouts inside them
    • Build a two-agent flow (for example intake, then a specialist) that passes context across the handoff without repeating questions
    • Write a unit-style test that runs the agent on text input to check its tool-calling logic
  30. Level 30: Building Pipelines with Pipecat
    Build the same agent in Pipecat, where everything is frames flowing through a chain of processors, and learn to write custom processors for logic the built-in ones don't cover.
    • Assemble a Pipecat pipeline with a transport, STT, an LLM context, TTS and a Smart Turn analyzer, and run it locally
    • Write a custom frame processor that logs per-stage timestamps or redacts personal data before it reaches the LLM
    • Handle interruptions and tool calls in Pipecat and compare its behaviour with your LiveKit version
  31. Level 31: Choosing a Framework: LiveKit, Pipecat or DIY
    Weigh up the frameworks on architecture, transport, deployment model, licensing, vendor lock-in and debuggability, using the two agents you've already built.
    • Write a decision record that compares LiveKit Agents, Pipecat and a hand-rolled pipeline for a named use case, with your own latency and complexity measurements
    • Find the escape hatches in each framework for custom STT, TTS or turn logic
    • Explain which parts of the stack you can self-host and what you depend on from each vendor's cloud
  32. Level 32: Hosted Voice Agent Platforms
    Look at managed voice-agent platforms that bundle telephony, models, turn-taking and dashboards, and weigh their speed to launch against control, cost and lock-in.
    • Build a simple agent with tools on one hosted platform and connect a custom tool through a webhook
    • Compare control over latency, model choice, data storage location and per-minute pricing between a hosted platform and your framework build, using current published pricing
    • Write exit criteria: the signs that a project has outgrown a hosted platform
  33. Level 33: SIP Trunks and Phone Numbers
    Put an agent on the phone network: buy numbers, set up SIP trunks for inbound and outbound calls, and bridge calls into your agent's room or media stream.
    • Set up an inbound phone number that routes through a SIP trunk into a LiveKit or Pipecat agent and answer a real call
    • Place an outbound call from code and handle the outcomes: answered, busy, no answer and voicemail
    • Explain the difference between SIP signalling and RTP media, and read a SIP trace to fix a failed call
  34. Level 34: Phone Audio Realities: Codecs, DTMF, Transfers
    Deal with what the phone network does to audio and to the call: 8 kHz G.711 μ-law, packet loss, keypad (DTMF) input, hold and transfers, and what each one means for speech recognition and turn-taking.
    • Convert sample rates and codecs between the phone media stream and your models, and measure how 8 kHz audio changes speech-to-text accuracy
    • Accept DTMF input alongside speech for PINs and menus, and implement cold and warm transfer to a human
    • Detect voicemail and answering machines on outbound calls and decide what the agent should do
  35. Level 35: Contact-Centre Patterns and Limits
    Fit voice agents into contact centres: replacing or sitting in front of an IVR, handing off to a human with context, connecting to existing CCaaS platforms, scaling to concurrent calls, and where agents still fall short.
    • Design a human-handoff flow that passes a call summary and the collected fields to a human agent without the caller repeating themselves
    • Estimate concurrency, scaling limits and rate limits for a peak call volume, and plan for provider outages with fallbacks
    • List the cases where a voice agent should hand off straight away (distress, vulnerability, repeated failure) and put them in place as rules
  36. Level 36: Transcript Evals and Task Success
    Start evaluating voice agents properly: define task success, score transcripts with rules and LLM judges, and keep a labelled set of real conversations.
    • Write task-success criteria and a scoring rubric for one agent flow, combining deterministic checks (tool called, fields correct) with an LLM judge
    • Check the LLM judge against a small set of human labels and report how often they agree
    • Explain what transcript-only evals miss (latency, interruptions, tone, audio problems) and how to measure those separately
  37. Level 37: Simulated Callers at Scale
    Test the agent with scripted and LLM-driven simulated callers that speak through real audio, with personas, accents, noise and interruptions.
    • Build a simulated caller that phones or connects to your agent, plays a persona with a goal, and records audio and events
    • Run a scenario matrix (personas × accents × noise × interruption behaviour) and report task success and failure modes for each cell
    • Explain the limits of simulation: where simulated callers behave differently from real people and how to check with real calls
  38. Level 38: Regression Testing Latency and Quality in CI
    Turn evals and latency measurements into automated checks that catch regressions when you change prompts, models, voices or providers.
    • Add a CI job that runs a fixed eval set and fails when task success or p95 time-to-first-audio crosses a threshold
    • Handle non-determinism with repeated runs, confidence intervals and baselines you can update deliberately
    • Run an A/B comparison of two LLM or TTS providers and present the quality, latency and cost differences in a short report
  39. Level 39: Observability for Live Calls
    Instrument production calls with traces, per-stage latency metrics, recordings and transcripts so you can find bad calls and see why they went wrong.
    • Add OpenTelemetry-style traces with spans for VAD, end of turn, STT, LLM, tools and TTS, tied together by a call ID
    • Build a dashboard showing p50 and p95 latency per stage, interruption rate, tool error rate and handoff rate, with alerts on regressions
    • Set retention, redaction and access rules for call recordings and transcripts that respect consent and data-protection obligations
  40. Level 40: Modelling Cost per Minute
    Build a per-minute cost model covering STT, LLM tokens, TTS characters or audio, speech-to-speech audio tokens, telephony, and hosting or platform fees, then find the cost drivers you can control.
    • Write a Python or TypeScript cost calculator that uses current published prices to compare a cascaded pipeline, a native speech-to-speech model and a hosted platform for a typical call
    • Show how context growth, prompt caching, silence handling and model choice change cost over a long call
    • Find the cheapest configuration that still meets your latency and task-success targets, using your own eval results
  41. Level 41: Disclosure Law, Recording Consent and Robocall Rules
    Learn what the law expects when an AI voice talks to the public: saying up front that the caller is speaking to an AI, getting consent before recording, the rules for automated outbound calls, and the parts that still differ by country or are unsettled.
    • Write a jurisdiction checklist that covers AI disclosure, one-party versus all-party recording consent and outbound robocall rules, and cite the primary source you checked for each item
    • Add a disclosure line and a recording-consent step to your agent's call flow, and log proof of both in the call record
    • Spot where the rules are still unsettled or differ by region, and write down which ones need a lawyer to look at them before launch
  42. Level 42: Designing Voice Agents for Accessibility
    Design an agent that works for callers with speech differences, hearing loss, cognitive load or a slow pace of speech, through adjustable timing, ways to repeat and confirm, non-voice fallbacks and a reliable path to a human.
    • Tune end-of-turn timeouts, speaking rate and confirmation prompts so slower or atypical speakers are not cut off, and measure the effect in simulated calls
    • Add accessible fallbacks such as DTMF keypad input, SMS or text follow-up and an always-available 'talk to a person' route
    • Run an accessibility pass over your eval set using personas with stutters, strong accents, background noise and hearing-aid audio
  43. Level 43: Security, Abuse and PII on Live Calls
    Protect a voice agent against spoken prompt injection, social engineering, fraud through tool calls and leaks of personal data in transcripts, recordings and logs.
    • Red-team your agent with spoken injection and impersonation attempts, then put guardrails around tools that change data or move money
    • Redact or mask card numbers, IDs and other personal data in streaming transcripts, stored recordings and traces before they reach logs or third-party vendors
    • Set retention rules and access controls for call audio and transcripts, and record the trade-offs in a short threat model
  44. Level 44: Resilience: Fallbacks, Failover and Safe Rollouts
    Keep calls alive when a provider slows down or fails, by using provider fallbacks, timeouts, graceful degradation and staged rollouts that are watched against your eval and latency baselines.
    • Add timeouts and automatic fallback between STT, LLM, TTS or speech-to-speech providers, with a scripted apology or handoff when everything else fails
    • Use fault injection to slow down or break one stage and confirm that calls degrade gracefully instead of going silent
    • Plan a canary or percentage rollout for a prompt or model change, with clear rollback triggers based on task success, latency percentiles and escalation rate
  45. Level 45: Capstone Part 1: Design and Build a Tool-Using Agent
    Choose a real use case, pick a cascaded or speech-to-speech design and a framework, then build a web or phone voice agent that calls at least two tools mid-conversation without dead air.
    • Write a one-page design doc covering the use case, architecture choice, transport (WebRTC, WebSocket or SIP), vendors, disclosure plan and target latency budget
    • Implement the agent in Python or TypeScript with working turn-taking, barge-in and at least two tools, including filler speech or progress updates while slow tools run
    • Run it end to end on a real microphone or phone call and capture the first recordings and transcripts
  46. Level 46: Capstone Part 2: Instrument and Measure Latency
    Instrument your capstone agent so every turn records timings for each stage, from the user stopping speaking to the first audio coming back, then find and fix the biggest source of delay.
    • Emit per-turn traces covering end-of-turn detection, STT finalisation, time to the LLM's first token, tool time, time to the TTS's first byte and network transport
    • Report p50 and p95 voice-to-voice latency across at least 20 turns and compare it with the budget in your design doc
    • Make one targeted optimisation, such as streaming, a region change, prompt trimming or a different model, and show the before and after numbers
  47. Level 47: Capstone Part 3: Run an Eval Suite and Cost Report
    Test your capstone agent with simulated callers and scenario scripts, score task success and conversation quality, and work out its real cost per minute.
    • Build a set of at least 15 scenarios, including happy paths, interruptions, accents, noisy audio, off-topic callers and adversarial callers, and run them through simulated callers
    • Score task success, tool-call correctness, escalation behaviour and disclosure compliance with a mix of automated checks and human transcript review
    • Calculate cost per minute and cost per successful task from real usage data, and write up your findings with the known limits of your evals
  48. Level 48: Final Challenge: Defend Your Voice Agent End to End Exam
    A review of the whole course, done as a full design-and-defend challenge: diagnose, improve and justify a voice agent across audio, architecture, latency, turn-taking, transport, telephony, evals, cost, compliance and accessibility.
    • Diagnose a provided failing voice agent's traces and transcripts, find the root causes across pipeline stages and propose ranked fixes
    • Defend your capstone's main trade-offs: cascaded versus speech-to-speech, WebRTC versus WebSocket, framework versus hosted platform, and vendor choice, backed by your measured latency, eval and cost data
    • Produce a launch-readiness checklist covering disclosure and consent, accessibility, security, fallbacks and monitoring, and mark clearly where practice is still unsettled

Access

Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor. Every level, the podcast edition and the AI tutor come with All Access at £4.99/month or any Creator plan — see pricing.

Read lesson 1 free →

More like this