OpenAI Whisper on Apple silicon with MLX and the Hugging Face Hub
pip install mlx-whisperWhisper
Speech recognition with Whisper in MLX. Whisper is a set of open source speech recognition models from OpenAI, ranging from 39 million to 1.5 billion parameters.1
Setup
Install ffmpeg:
# on macOS using Homebrew (https://brew.sh/)
brew install ffmpeg
Install the mlx-whisper package with:
pip install mlx-whisper
Run
CLI
At its simplest:
mlx_whisper audio_file.mp3
This will make a text file audio_file.txt with the results.
Use -f to specify the output format and --model to specify the model. There
are many other supported command line options. To see them all, run
mlx_whisper -h.
You can also pipe the audio content of other programs via stdin:
some-process | mlx_whisper -
The default output file name will be content.*. You can specify the name with
the --output-name flag.
API
Transcribe audio with:
import mlx_whisper
text = mlx_whisper.transcribe(speech_file)["text"]
The default model is "mlx-community/whisper-tiny". Choose the model by
setting path_or_hf_repo. For example:
result = mlx_whisper.transcribe(speech_file, path_or_hf_repo="models/large")
This will load the model contained in models/large. The path_or_hf_repo can
also point to an MLX-style Whisper model on the Hugging Face Hub. In this case,
the model will be automatically downloaded. A collection of pre-converted
Whisper
models
are in the Hugging Face MLX Community.
The transcribe function also supports word-level timestamps. You can generate
these with:
output = mlx_whisper.transcribe(speech_file, word_timestamps=True)
print(output["segments"][0]["words"])
To see more transcription options use: