Sub topic 13
Running Whisper faster with faster-whisper
This chapter assumes you can already transcribe a file with the openai-whisper package. It also assumes you know what the model sizes, beam size, and 30-second windows are, and that you have read the earlier chapter on speed and memory. You should be comfortable with Python generators and with installing packages using pip.
What faster-whisper is
faster-whisper is a reimplementation of Whisper inference. It does not train or change the model. It loads the same weights, converted to the format of CTranslate2, a C++ inference engine for transformer models. CTranslate2 provides optimized kernels, weight quantization, and efficient memory use on both CPU and GPU.
The project reports transcription up to about four times faster than openai-whisper at similar accuracy, with lower memory use. Your own gain depends on hardware, model size, and settings, so measure it on your own audio.
Three practical differences matter:
- It decodes audio with PyAV, which bundles FFmpeg libraries. You do not need a separate
ffmpegexecutable. - It downloads converted models from the Hugging Face Hub the first time you use a model name.
transcribereturns a lazy generator of segments plus an info object, not a dictionary.
Install it with:
pip install faster-whisperThe basic call
The code below runs the small model on CPU with 8-bit integer weights.
from faster_whisper import WhisperModel
model = WhisperModel("small", device="cpu", compute_type="int8")
segments, info = model.transcribe("audio.mp3", beam_size=5)
print(info.language, info.language_probability)
for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")info is available immediately. It holds the detected language, the probability of that language, and the audio duration. The segments are produced only as you iterate, so the loop is where the decoding work happens.
How the pipeline fits together
The model stages match the original Whisper: 30-second windows, an encoder, and an autoregressive decoder with the same fallback logic. The speed comes from running those stages in a faster engine, not from changing them.
Choosing device and compute type
device can be "cpu", "cuda", or "auto". compute_type sets the numeric precision of the weights and activations. CTranslate2 converts on load if the requested type is not the stored one, and it falls back to a supported type if your hardware cannot run the one you asked for.
| compute_type | Typical use | Notes |
|---|---|---|
| `float32` | Reference quality on CPU or GPU | Largest and slowest |
| `float16` | Default choice on a modern NVIDIA GPU | Needs GPU support for half precision |
| `int8_float16` | GPU with limited VRAM | Smaller weights, activations in fp16 |
| `int8` | CPU, or GPU when memory is tight | Smallest memory, small accuracy loss on some audio |
Quantization can change output slightly. If you compare settings, use the word error rate from the earlier chapter on the same reference transcripts instead of assuming the output is identical.
from faster_whisper import WhisperModel
model = WhisperModel("large-v3", device="cuda", compute_type="float16")
segments, info = model.transcribe(
"interview.mp3",
language="en",
beam_size=5,
word_timestamps=True,
vad_filter=True,
vad_parameters={"min_silence_duration_ms": 500},
)
for segment in segments:
print(f"[{segment.start:.2f} -> {segment.end:.2f}] {segment.text}")
for word in segment.words:
print(f" {word.start:.2f}-{word.end:.2f} {word.word} ({word.probability:.2f})")The GPU path needs the NVIDIA cuBLAS and cuDNN libraries installed in versions that match your faster-whisper and CTranslate2 release. Check the project README for the current versions.
Lazy segments: the most common mistake
transcribe returns a generator. Two consequences follow.
First, if you time only the call to transcribe, you measure almost nothing. The decoding happens during iteration.
Second, a generator can be consumed only once. The second list(segments) below returns an empty list.
import time
from faster_whisper import WhisperModel
model = WhisperModel("base", device="cpu", compute_type="int8")
start = time.perf_counter()
segments, info = model.transcribe("audio.mp3")
call_seconds = time.perf_counter() - start # tiny: no decoding yet
first = list(segments) # decoding happens here
total_seconds = time.perf_counter() - start
second = list(segments) # generator is exhausted
print(f"transcribe() returned after {call_seconds:.3f}s")
print(f"all segments ready after {total_seconds:.3f}s")
print(len(first), len(second))Convert to a list once if you need the segments more than once. The generator is useful for long files, because you can print or save each segment as soon as it is ready and stop early if you want.
Options that carry over, and options that differ
Most decoding options from openai-whisper exist under the same names: language, task ("transcribe" or "translate"), beam_size, temperature, initial_prompt, condition_on_previous_text, and word_timestamps. There are differences to know:
beam_sizedefaults to 5 in faster-whisper. Inopenai-whisper,transcribeuses greedy decoding unless you request beam search. A comparison with default settings is therefore not like for like.temperatureaccepts a single value or a list. The default list is a fallback sequence from 0.0 up to 1.0. A higher temperature is tried only when a segment fails the compression-ratio or log-probability checks.vad_filter=Trueruns the Silero voice activity detector before decoding and skips non-speech audio. It is off by default.- Segment objects are attribute-style (
segment.text), not dictionaries (segment["text"]).
Voice activity detection and silence
The limitations chapter described hallucinated text on silence. vad_filter is the most direct mitigation in this library. Tune it with vad_parameters, for example min_silence_duration_ms for how long a pause must be before it is cut, and speech_pad_ms for padding kept around speech. If the filter is too aggressive, it can clip quiet words at the start or end of an utterance. Raise the padding or lower the detection threshold, then check a few clips by ear.
When VAD removes audio, faster-whisper maps timestamps back to the original timeline. Verify this on one file where you know the true timing, because errors here are easy to miss.
Context and repetition loops
condition_on_previous_text=True feeds the previous window's text to the decoder as a prompt. This keeps spelling and style consistent, but it can also make a repetition loop spread across windows. If you see the same phrase repeated many times, set it to False and compare.
Batched inference
Recent faster-whisper releases include BatchedInferencePipeline. It splits the audio into speech chunks, usually with VAD, and decodes several chunks in one forward pass. This raises throughput on a GPU, especially for long recordings.
from faster_whisper import WhisperModel, BatchedInferencePipeline
model = WhisperModel("large-v3", device="cuda", compute_type="float16")
batched = BatchedInferencePipeline(model=model)
segments, info = batched.transcribe("long_recording.mp3", batch_size=16)
for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")Batching has trade-offs. Chunks are decoded independently, so there is no text carried from one chunk to the next. Larger batches need more VRAM, and an out-of-memory error means you should lower batch_size. If the import fails, upgrade the package, because older versions do not have this class.
CPU tuning
On CPU, cpu_threads sets the number of threads that one model uses (it defaults to a small value chosen by the library). num_workers allows several transcriptions to run in parallel against one model. These two settings compete for the same cores, so setting both high on a small machine slows everything down. Start with cpu_threads equal to your physical core count, and change only one setting at a time.
from faster_whisper import WhisperModel
model = WhisperModel("small", device="cpu", compute_type="int8", cpu_threads=4)Common errors
- Empty output on the second pass. The generator was already consumed. Wrap it in
list(...)once. - Benchmark shows near-zero time. You timed the call, not the iteration.
- Missing or mismatched CUDA libraries. Errors mentioning
libcublasorlibcudnnmean the GPU libraries are absent or the wrong version. Install the versions the release documents, or usedevice="cpu"to confirm the rest of your code works. - Different text than
openai-whisper. Beam size, quantization, VAD, and the fallback settings can each change output. Match them before concluding that one library is less accurate. - Wrong language from auto-detection. Pass
language="en"(or the right code) instead of relying on detection of the first window, as with the original package.
When to choose faster-whisper
Choose faster-whisper when throughput or memory is the constraint, for example batch transcription of many files, a CPU-only server, or a GPU with limited VRAM. Stay with openai-whisper if you need its exact reference behavior or output format without changes. Use the Hugging Face pipeline from the next chapter if the rest of your system already depends on transformers.
Exercise
A colleague writes segments, info = model.transcribe("talk.mp3"), times that line at 0.02 seconds, and reports that faster-whisper transcribes a one-hour talk in under a second. They then call list(segments) twice and get an empty list the second time. What went wrong in each case, and how do you fix both?
Show answer
transcribe returns a lazy generator, so decoding happens only while the segments are iterated. The 0.02 seconds covers file opening and language detection, not transcription. The fix is to time the full iteration, for example segments = list(segments) inside the timed region. The empty second list appears because a generator can be consumed only once. Convert it to a list one time and reuse that list.
Exercise
You run faster-whisper on a recording with long silent gaps and see invented sentences during the gaps. Name the option that addresses this, one parameter that controls how long a pause must be before it is removed, and one risk of setting the filter too aggressively.
Show answer
Set vad_filter=True. Tune it with vad_parameters, for example min_silence_duration_ms. If the filter is too aggressive, it can cut quiet words at the start or end of speech, so you lose real content. Padding (speech_pad_ms) or a lower detection threshold reduces that risk.