How m-bain/whisperx works
1. What this repo is
WhisperX is a Python package and CLI for long-form speech transcription. Its core architecture is a staged pipeline: audio ingest → speech segmentation/VAD → ASR transcription → forced alignment for word timestamps → optional speaker diarization → subtitle/transcript post-processing.
2. Primary entry points
The user-facing surfaces are whisperx/__main__.py for the command-line tool and whisperx/__init__.py for the Python API. The README’s public workflow maps directly onto package calls like loading an ASR model, loading audio, aligning segments, and assigning speaker labels.
3. Audio ingestion and normalization
whisperx/audio.py is the boundary for turning media files into model-ready audio. This is where the repo likely handles decoding, resampling, and sample-format normalization, with ffmpeg implied by the README. whisperx/utils.py and whisperx/log_utils.py support shared helpers and runtime diagnostics.
4. ASR transcription subsystem
whisperx/asr.py and whisperx/transcribe.py encapsulate the speech-to-text stage. The README shows batched Whisper inference through the faster-whisper backend / CTranslate2, which is a key architectural choice: it enables fast, GPU-efficient batch transcription and differs from stock OpenAI Whisper by operating without timestamps in the first pass.
5. Voice activity detection as an upstream gate
The whisperx/vads/ package contains the VAD implementations: a common interface in vad.py, plus concrete backends for silero and pyannote. VAD is not just a utility here; it is part of the transcription strategy, used to reduce hallucinations and create cleaner transcription batches.
6. Forced alignment for word-level timing
whisperx/alignment.py is the alignment subsystem. It takes segment-level ASR output and aligns it against language-specific phoneme/ASR alignment models, producing word-level timestamps. The README indicates model selection is language-aware and may pull from torchaudio pipelines or Hugging Face.
7. Speaker diarization boundary
whisperx/diarize.py is a separate optional subsystem that labels speech by speaker identity. It depends on pyannote-based diarization models and requires a Hugging Face token for access. Architecturally, diarization happens after transcription/alignment, then its speaker turns are mapped back onto transcript words/segments.
8. Transcript post-processing and subtitle shaping
whisperx/SubtitlesProcessor.py, whisperx/conjunctions.py, and whisperx/schema.py support transcript formatting and structure. The README mentions sentence-level segmentation, subtitle output, and word highlighting; these files appear to encode the transcript schema and the logic that converts aligned words into display-ready subtitles.
9. Data flow through the system
The canonical flow is: input audio is decoded, optionally VAD-segmented, transcribed in batches, aligned to get precise word times, then optionally diarized so words/segments receive speaker IDs. The final output is a nested transcript structure with segments, word timings, and speaker annotations, suitable for .srt-style subtitle generation or programmatic consumption.
10. Model and asset dependencies
The repo vendors small runtime assets under whisperx/assets/, including mel_filters.npz and pytorch_model.bin. More substantial models are fetched externally at runtime from Hugging Face or torchaudio, so the package is partly self-contained but still model-dependent.
11. Runtime and deployment constraints
This is primarily a Python ML inference repo built around PyTorch, CUDA-capable GPUs, and audio tooling like ffmpeg. CPU execution is supported but slower, and compute type/device selection materially affects memory use and throughput. Speaker diarization also introduces an external auth boundary via Hugging Face tokens.
12. Testing and CI
The tests/ directory currently contains alignment-related coverage, specifically word timestamp interpolation behavior. GitHub Actions workflows cover build/release, tests, Python compatibility, and security linting, which suggests the maintainers care about cross-version package behavior more than a large internal test matrix.
13. Architecture diagram takeaway
If you draw this repo, the important boxes are: CLI/API façade, audio preprocessing, ASR engine, VAD gate, alignment engine, diarization engine, and subtitle/post-processing. The main arrows are linear, but alignment and diarization are optional branches that enrich the transcript rather than changing the core transcription path.
Main entry points: transcribe.py Transcribe · SubtitlesProcessor.py Subtitles · vad.py VAD core · audio.py Audio ingest
Components 16
Entry points
User-facing CLI and Python API surfaces.
Core pipeline
Audio ingest, transcription, alignment, and transcript shaping.
- Audio ingest · Decodes media and normalizes audio for model consumption.
whisperx/audio.py - Transcribe · Coordinates the transcription workflow and batching.
whisperx/transcribe.py - ASR engine · Runs batched speech-to-text inference via the model backend.
whisperx/asr.py - Alignment · Converts segment transcripts into word-level timestamps.
whisperx/alignment.py - Subtitles · Shapes aligned transcripts into subtitle-ready output.
whisperx/SubtitlesProcessor.py - Conjunctions · Helps split or merge transcript text for subtitle flow.
whisperx/conjunctions.py
Speaker path
Optional diarization and VAD components.
- VAD core · Common voice activity detection interface and orchestration hooks.
whisperx/vads/vad.py - Silero VAD · Silero-based speech activity detector.
whisperx/vads/silero.py - Pyannote VAD · Pyannote-based speech activity detector.
whisperx/vads/pyannote.py - Diarization · Assigns speaker identities to transcript turns and words.
whisperx/diarize.py
Shared support
Helpers, schema, and logging used across the package.
Assets
Bundled runtime assets.
- Assets · Packaged runtime assets used by audio and model loading.
whisperx/assets
Connections 19
- CLI → Transcribe: runs · CLI delegates to the transcription workflow.
- API → Audio ingest: exposes · Package API exposes the core building blocks.
- API → Transcribe: exposes · Package API exposes transcription entry points.
- Transcribe → Audio ingest: loads · Workflow starts by decoding and normalizing audio.
- Transcribe → VAD core: optionally gates · VAD can segment audio before transcription.
- Transcribe → ASR engine: calls · Transcription workflow invokes the ASR engine.
- ASR engine → Assets: uses assets · ASR setup depends on packaged runtime assets.
- Transcribe → Alignment: aligns · Segment-level text is aligned to produce word timestamps.
- Alignment → Schema: emits · Alignment produces structured transcript data.
- Transcribe → Diarization: optionally enriches · Speaker labels are added after transcription/alignment.
- Diarization → Pyannote VAD: uses · Diarization relies on pyannote-based speaker models.
- VAD core → Silero VAD: implements · Silero is one concrete VAD backend.
- VAD core → Pyannote VAD: implements · Pyannote is one concrete VAD backend.
- Transcribe → Subtitles: formats · Final transcript can be shaped into subtitles.
- Subtitles → Conjunctions: uses · Subtitle shaping uses sentence-flow heuristics.
- Subtitles → Schema: reads · Subtitle generation consumes the transcript schema.
- Audio ingest → Assets: uses assets · Audio/model preprocessing uses bundled resources.
- Transcribe → Utils: uses · Workflow shares helper utilities.
- Transcribe → Logging: logs · Workflow emits structured runtime diagnostics.