โ† All build guides

Build a Local Voice AI Agent with Ollama

A voice agent that listens, thinks, and talks back โ€” speech-to-text, the LLM and text-to-speech all running on your own machine.

โฑ 60 minutes๐Ÿ›  Python 3.10+, a microphone, and enough memory for an 8B model (a GPU helps; CPU works, slower)
  1. 1

    Pick the three pieces

    A voice agent is three models stitched together: speech-to-text (Whisper or faster-whisper), an LLM (any chat model via Ollama), and text-to-speech (Piper, Coqui, or any OpenAI-compatible TTS). Start with the smallest viable model for each: faster-whisper with the `base` model, `ollama pull llama3.1:8b`, and Piper (`pip install piper-tts`) with the `en_US-amy-medium` voice from the piper-voices collection on Hugging Face.

  2. 2

    Capture and stream audio

    `pip install pyaudio webrtcvad`. Capture mic input at 16kHz with `pyaudio` and use `webrtcvad` to detect when the user starts and stops talking โ€” this is voice activity detection and it's the difference between an agent that feels real and one that interrupts you mid-sentence. Buffer audio between VAD events.

  3. 3

    Transcribe with Whisper

    Pass the buffered audio to `faster_whisper.WhisperModel("base").transcribe(audio_array)`; it returns segments whose text you join. Whisper base is 74M parameters and needs about 1 GB of memory (OpenAI Whisper README), so it is a light first pick; move up to `small` if accuracy is poor. `whisper.cpp` with a quantized model is the other common route. The output is plain text โ€” your input to the LLM.

  4. 4

    LLM with conversation memory

    Maintain a `messages` list with the system prompt + last N turns. Send to Ollama via `ollama.chat(model="llama3.1:8b", messages=messages, stream=True)`. Stream the tokens โ€” don't wait for the full response โ€” because TTS can start speaking the first sentence while the LLM is still generating the second.

  5. 5

    TTS in real time

    Pipe the streaming LLM output into Piper sentence-by-sentence. Each sentence becomes a wav blob you push to the audio output, so the agent starts speaking before the full reply is generated. Time the gap between the user finishing and the agent starting on your own machine: it depends on your GPU, the Whisper model size and the LLM you picked, and it is the number worth optimising.

  6. 6

    What you do not get from a 60-min build

    Production voice agents need turn-taking interrupts (the agent shutting up when the user starts speaking), barge-in detection, eval sets for transcription accuracy, telephony integration (Twilio / SIP), and observability for sub-second-budget tracking. The Voice AI course on Local AI Master walks all of that, with capstones for telephony deployment.

Want the full path?

Continue with the full Voice AI and Realtime Agents course on Local AI Master.

This page is one chapter of a structured course covering everything from foundations to production. Go Pro for full access to all 561 chapters across 25 courses plus the Python Lab โ€” about $0.30/day, cancel anytime.

$8.99/mo ยท about $0.30/day ยท cancel anytime
Free Tools & Calculators