`mlx_whisper.transcribe()` turns speech in an audio file into text on an Apple silicon Mac. Pass an audio file path and choose a Whisper model with `path_or_hf_repo`. For example, `mlx_whisper.transcribe(str(audio_file), path_or_hf_repo="mlx-community/whisper-small-mlx")` returns a Python dictionary; `result["text"]` is the transcript. The audio should be mono at 16 kHz, using int16 for a WAV file. section 9.11 section 9.6
import mlx_whisper
from pathlib import Path
AUDIO_FILE = Path(__file__).with_name("recording.wav")
WHISPER_MODEL = "mlx-community/whisper-small-mlx"
def transcribe(audio_path: str, model: str = WHISPER_MODEL) -> str:
"""Transcribe an audio file and return the text."""
if not Path(audio_path).is_file():
raise FileNotFoundError(
f"Audio file not found: {audio_path}. Run python record.py first."
)
print(f"Transcribing with {model.split('/')[-1]}...")
result = mlx_whisper.transcribe(str(audio_path), path_or_hf_repo=model)
return result["text"].strip()
if __name__ == "__main__":
text = transcribe(AUDIO_FILE)
print(f"\nTranscript:\n{text}")
A runnable wrapper checks that the recording exists, calls MLX Whisper, and returns stripped transcript text. Its path is based on the script’s location, so running it from another directory does not change which recording it opens. section 9.6
The result also has `segments` and `language` keys. Keep the dictionary when you need details such as detected language; a wrapper that returns only `result["text"]` discards them. A Hugging Face model name triggers an automatic download and local cache on first use; a local model-folder path is another option. section 9.6 section 9.10
Useful next steps:
- Transcribe a short voice memo or other audio file; convert an MP3 to mono, 16 kHz WAV first if needed. section 9.10
- Compare tiny and small models on the same recording. Run each once before timing it so download and model loading do not skew the comparison. section 9.10
- For browser-recorded WAV bytes, write a temporary file before passing its path to `transcribe()`, then delete the file in a `finally` block. section 10.9
