Sub topic 13
Running Whisper Faster with faster-whisper
This chapter assumes you know basic Python, can install packages with pip, and understand Whisper transcription, segments, and timestamps. It focuses on improving inference speed and reducing memory use without changing the overall transcription workflow.
What faster-whisper changes
faster-whisper is an alternative implementation of Whisper. It uses CTranslate2, an inference engine designed for efficient transformer execution. It can use optimized kernels, lower-precision numbers, and quantization to run Whisper with less computation.
The model still performs the same broad task:
- Read audio features.
- Encode the audio.
- Decode text tokens.
- Return segments and metadata.
The main difference is the runtime and model format. You load a model by name, and faster-whisper downloads a compatible converted model the first time.
Install and run a CPU transcription
Install the package with:
pip install faster-whisperThe following example uses the small model with integer quantization on a CPU.
from faster_whisper import WhisperModel
model = WhisperModel(
"small",
device="cpu",
compute_type="int8",
)
segments, info = model.transcribe(
"audio.mp3",
language="en",
beam_size=5,
)
print(f"Language: {info.language}")
print(f"Confidence: {info.language_probability:.3f}")
for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")compute_type="int8" stores many model values with 8-bit integers. This reduces memory use and can improve CPU speed. It may cause a small accuracy difference, so compare it with another setting when accuracy matters.
A useful detail is that segments is lazy. The transcription work happens as you iterate over it. This lets the program begin processing results before the entire recording has been decoded.
Choosing device and precision
The best compute_type depends on the device and its supported operations.
| Device | Compute type | Typical reason |
|---|---|---|
| CPU | `int8` | Lower memory use and practical CPU speed |
| CPU | `float32` | A compatibility baseline |
| CUDA GPU | `float16` | Fast inference on a modern NVIDIA GPU |
| CUDA GPU | `int8_float16` | Lower memory use with GPU-friendly computation |
For a CUDA GPU, use settings such as:
model = WhisperModel(
"medium",
device="cuda",
compute_type="float16",
)The GPU version requires a compatible NVIDIA driver and CUDA libraries. If initialization fails, try a supported compute type or use device="cpu".
Tuning decoding and timestamps
The beam_size option controls beam search. Beam search keeps several possible text continuations while decoding. A larger value can improve difficult transcriptions, but it usually takes more time.
Word timestamps require additional alignment work:
from faster_whisper import WhisperModel
model = WhisperModel("small", device="cpu", compute_type="int8")
segments, info = model.transcribe(
"interview.mp3",
language="en",
beam_size=5,
word_timestamps=True,
vad_filter=True,
)
for segment in segments:
print(f"{segment.start:.2f} -> {segment.end:.2f}: {segment.text}")
if segment.words:
for word in segment.words:
print(f" {word.start:.2f} -> {word.end:.2f}: {word.word}")vad_filter=True enables voice activity detection. Voice activity detection identifies portions that probably contain speech. It can reduce unnecessary processing and prevent some output during long silent sections. Test it with your recordings because quiet speech may sometimes be removed.
Benchmark before choosing a setting
Measure both elapsed time and accuracy. A smaller or quantized model may be faster but can produce more substitutions, omissions, or hallucinations. Keep a representative test set with known reference transcripts and calculate word error rate when comparing configurations.
Use the original Whisper package as a quality baseline, then compare model size, device, compute type, beam size, and VAD settings. Do not assume that the fastest configuration is suitable for production.
Exercise
Why might segments appear to return immediately, even though transcription is still being performed?
Show answer
segments is lazy. The transcription work is performed as the program iterates over the segments.