liveBook · Manning

Chapter 9: Recording audio and transcribing speech with MLX Whisper

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

This introduction previews adding microphone recording and speech transcription to the existing text-based AI application as a foundation for a voice-enabled chatbot.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction previews adding microphone recording and speech transcription to the existing text-based AI application as a foundation for a voice-enabled chatbot.

9.1 What is speech recognition?

This section defines speech recognition, explains why it is difficult, and introduces how Whisper transcribes audio locally.

Key terms: speech recognition, automatic speech recognition (ASR), Whisper, phonemes, multilingual audio, statistical patterns of language, encoder-decoder transformer, spectrogram, Mel filterbank, encoder

9.2 Why use MLX Whisper on Apple silicon?

This section explains why MLX Whisper is a faster, more memory-efficient choice for speech transcription on Apple silicon and what that speed can mean for voice chat.

Key terms: PyTorch Whisper, MLX, MLX Whisper, Apple silicon, unified memory, MLX Whisper large-v3, transcription, system load, machine learning, deep learning

9.3 Installing MLX Whisper

This section identifies the packages needed for local speech transcription, how to install and check them, and the alternative for Intel Macs.

Key terms: virtual environment, requirements file, check_versions.py, mlx-whisper, sounddevice, numpy, scipy, audio waveforms, WAV files, Intel Macs

9.4 Understanding digital audio

Introduces the need to understand three numbers that describe digital audio before writing recording scripts.

9.4.1 Audio sample rate

Defines audio sample rate and explains why recordings for Whisper should use 16 kHz or be resampled before transcription.

Key terms: sample, sample rate, Whisper, 16 kHz, resample

9.4.2 Audio channels

9.4.3 Sample bit depth and data type

This subsection compares two audio sample formats and explains why recordings use float32 before conversion to int16 for WAV files.

Key terms: sample, bit depth, float32, int16, WAV

9.5 Recording from the microphone

Introduces a beginner microphone-recording script that saves a WAV file for inspection and later transcription.

Key terms: record.py, recording.wav, WAV file, intermediate audio file, functions, def

9.5.1 sd.rec(): The recording call

Explains how sd.rec() captures a specified number of audio samples and how sd.wait() ensures the recording is complete.

Key terms: sd.rec(), sd.wait(), NumPy array, default input device, sample rate

9.5.2 Squeezing the channel dimension

This subsection explains why a mono recording is squeezed into a flat array for MLX Whisper.

Key terms: sd.rec(), channels=1, .squeeze(), channel dimension, MLX Whisper

9.5.3 Converting to int16 for WAV

Explains why a float32 microphone recording is scaled when converting it to int16 samples for a WAV file.

Key terms: WAV, int16, float32, samples

9.6 Your first transcription

Shows how to transcribe a saved microphone recording with MLX Whisper, read the resulting text, and handle first-run downloads and common errors.

Key terms: recording.wav, record.py, MLX Whisper, mlx_whisper.transcribe(), Python dictionary, result["text"], path_or_hf_repo, Hugging Face, model weights, cache

9.7 Choosing the right Whisper model

This section introduces the accuracy, speed, and memory tradeoff among MLX Whisper model sizes and shows how their Hugging Face repository names are formed.

Key terms: Whisper model sizes, accuracy, memory, Hugging Face repository name, mlx-community/whisper-{size}-mlx, large-v3

9.7.1 Which model should you use?

This section recommends MLX Whisper models for short voice input based on unified memory shared with Ollama and the need for accuracy.

Key terms: unified memory, whisper-small-mlx, whisper-medium-mlx, whisper-large-v3-mlx, Ollama

9.7.2 Trying a larger model

9.8 Building a reusable transcription script

This section turns recording and transcription into a reusable Python module that can be tested now and imported into the voice chatbot later.

Key terms: voice_input.py, record_and_transcribe, self-contained module

9.9 Troubleshooting

9.9.1 “No default input device”

Explains how to resolve a microphone input error caused by macOS blocking access.

Key terms: No default input device, Privacy & Security, Microphone

9.9.2 Audio is captured but Whisper returns empty text

This subsection explains three common reasons a captured recording produces an empty Whisper transcript and how to address each one.

Key terms: empty transcript, input volume, background noise, print("Recording...")

9.9.3 “Cannot import mlx_whisper”

9.9.4 The first download is slow

Explains why MLX Whisper’s first run can be slow and how to let the model download complete.

Key terms: MLX Whisper, model weights, Hugging Face, whisper-large-v3-mlx

9.9.5 “File not found” for ffmpeg

9.10 Exercises

9.11 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 8: Building a web UI with Streamlit Chapter 10: Building a voice-enabled AI chat application →

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.