liveBook · Manning

Chapter 10: Building a voice-enabled AI chat application

What you will learn in chapter 10 of Build Applications with Local AI Models on a Mac

The introduction explains why a local voice chat app is more complex than a text chatbot: it connects audio capture, speech recognition, and language model inference in a pipeline.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why a local voice chat app is more complex than a text chatbot: it connects audio capture, speech recognition, and language model inference in a pipeline.

Key terms: audio capture, speech recognition, language model inference, pipeline

10.1 The voice AI pipeline

The section traces a spoken request through three local stages and explains why the voice chat pipeline keeps its data on the Mac.

Key terms: audio capture, st.audio_input(), WAV bytes, MLX Whisper, LLM inference, Ollama, locally, initial one-time model downloads

10.2 Setting up the voice chat application project

Sets up the Chapter 10 project files and dependencies and clarifies how to use successive versions of the application code.

Key terms: ch10, my-ai-chatbot, voice_chat.py, model_config.json, setup_ollama.sh, voice_input.py, requirements.txt, dependencies, downloaded source package, earlier-stage code

10.3 Building the application step by step

The section introduces incremental development as building the voice chat application in stages and testing each stage before adding the next.

Key terms: incremental development, stages

10.3.1 Stage 1: Transcription in Streamlit

This section introduces browser microphone input in Streamlit and shows how to check that the first transcription stage works.

Key terms: st.audio_input(), WAV bytes, Web Audio API, microphone access, transcribed text, You said:

10.3.2 Why use a temporary WAV file?

Explains why the voice chat app writes recorded WAV bytes to a temporary file before passing them to MLX Whisper, and why the file must remain until transcription reads it.

Key terms: st.audio_input(), UploadedFile, WAV bytes, transcribe(), tempfile.NamedTemporaryFile(), delete=False

10.3.3 Stage 2: Connecting transcription to the LLM

This stage connects spoken-question transcription to Ollama so the app displays the transcript and a streaming AI response while retaining conversation context.

Key terms: Ollama, transcribed words, streaming response, session state, context

10.3.4 Stage 3: The complete application

10.4 The complete voice chat application

10.4.1 Running the application

This section explains how to prepare Ollama and launch the completed voice chat application in a local browser.

Key terms: ch10/setup_ollama.sh, ollama.default_model, model_config.json, ollama list, gemma3:1b, Ollama server, Ollama API, Streamlit, ch10 folder, local URL

10.4.2 Updating the Ollama model menu

This section explains how to add an Ollama model to the voice chat app’s sidebar menu by updating its configuration file.

Key terms: Ollama model tag, ch10/model_config.json, name, label, notes, default_model

10.5 Understanding the complete voice chat application code

10.5.1 Browser page configuration

This subsection explains how the application configures its browser page before other Streamlit calls.

Key terms: st.set_page_config(), layout="wide"

10.5.2 The sidebar: Controlling two models

Explains how the voice chat sidebar selects the response and transcription models and adjusts the variability of Ollama’s replies.

Key terms: Ollama selectbox, Whisper selectbox, label-to-identifier mapping, model_config.json, model tag, WHISPER_MODELS, Hugging Face repository path, temperature slider, Ollama options dictionary

10.5.3 transcribe_audio(): The bridge between Streamlit and MLX Whisper

Explains how transcribe_audio() passes Streamlit audio to MLX Whisper and handles the input, temporary file, and transcript.

Key terms: transcribe_audio(), temporary file, MLX Whisper, try / finally, os.unlink(tmp_path), orphaned temp files, st.audio_input(), audio_file.read(), .seek(0), read position

10.5.4 stream_response(): A reusable streaming function

This section explains why the app’s repeated streaming logic is refactored into stream_response() and what the function does.

Key terms: refactoring, streaming, stream_response(), messages, assistant message bubble, streaming loop

10.5.5 handle_user_message(): The unified entry point

This section explains how one function handles user text from both voice and keyboard input before requesting an LLM response.

Key terms: handle_user_message(), conversation history, streaming response, voice input path, text input path

10.5.6 Dual input: Voice and text

The section explains why the Streamlit chat app offers both voice and text input and routes them through one handler.

Key terms: microphone recorder, text field, text fallback, handle_user_message()

10.6 Running and testing the application

10.6.1 Startup checklist

This section gives the checks to make before launching the voice chat app.

Key terms: Ollama, setup_ollama.sh, ollama serve, ollama list, model_config.json, virtual environment

10.6.2 Testing checklist

This section gives a checklist for testing voice and text input, shared conversation context, model switching, and conversation clearing in the completed app.

Key terms: Voice input, transcript, Whisper, Text fallback, Conversation context, voice message, text input, Model switching, Ollama model, Whisper model

10.6.3 Troubleshooting

10.7 Understanding the latency budget

Explains why voice chat has a noticeable wait before the first response and how model choice, hardware, and progress feedback affect that wait.

Key terms: latency, transcribe, streaming text, whisper-large-v3-mlx, transcription latency, st.spinner("Transcribing..."), Apple silicon

10.8 Exercises

10.9 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 9: Recording audio and transcribing speech with MLX Whisper Chapter 11: Managing session state and chat history →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.