# m-bain/whisperx architecture

> Architecture diagram of the GitHub repository m-bain/whisperx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m-bain/whisperx
- Repository: https://github.com/m-bain/whisperx

## Overview

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: [`whisperx/transcribe.py`](https://github.com/m-bain/whisperx/blob/main/whisperx/transcribe.py) (Transcribe), [`whisperx/SubtitlesProcessor.py`](https://github.com/m-bain/whisperx/blob/main/whisperx/SubtitlesProcessor.py) (Subtitles), [`whisperx/vads/vad.py`](https://github.com/m-bain/whisperx/blob/main/whisperx/vads/vad.py) (VAD core), [`whisperx/audio.py`](https://github.com/m-bain/whisperx/blob/main/whisperx/audio.py) (Audio ingest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Entry points"]
  node_whisperx___main__["CLI<br/>entrypoint<br/>[__main__.py]"]
  node_whisperx___init__["API<br/>[__init__.py]"]
end

subgraph group_pipeline["Core pipeline"]
  node_whisperx_audio["Audio ingest<br/>audio preprocessing<br/>[audio.py]"]
  node_whisperx_transcribe["Transcribe<br/>orchestration<br/>[transcribe.py]"]
  node_whisperx_asr["ASR engine<br/>speech recognition<br/>[asr.py]"]
  node_whisperx_alignment["Alignment<br/>[alignment.py]"]
  node_whisperx_subtitles["Subtitles<br/>post-processing"]
  node_whisperx_conjunctions["Conjunctions<br/>sentence shaping<br/>[conjunctions.py]"]
end

subgraph group_speaker["Speaker path"]
  node_whisperx_vads_vad["VAD core<br/>vad interface<br/>[vad.py]"]
  node_whisperx_vads_silero["Silero VAD<br/>vad backend<br/>[silero.py]"]
  node_whisperx_vads_pyannote["Pyannote VAD<br/>vad backend<br/>[pyannote.py]"]
  node_whisperx_diarize["Diarization<br/>speaker labeling<br/>[diarize.py]"]
end

subgraph group_shared["Shared support"]
  node_whisperx_schema["Schema<br/>[schema.py]"]
  node_whisperx_utils["Utils<br/>shared helpers<br/>[utils.py]"]
  node_whisperx_log_utils["Logging<br/>diagnostics<br/>[log_utils.py]"]
end

subgraph group_assets["Assets"]
  node_whisperx_assets[("Assets<br/>bundled models")]
end

node_whisperx___main__ -->|"runs"| node_whisperx_transcribe
node_whisperx___init__ -->|"exposes"| node_whisperx_audio
node_whisperx___init__ -->|"exposes"| node_whisperx_transcribe
node_whisperx_transcribe -->|"loads"| node_whisperx_audio
node_whisperx_transcribe -->|"optionally gates"| node_whisperx_vads_vad
node_whisperx_transcribe -->|"calls"| node_whisperx_asr
node_whisperx_asr -->|"uses assets"| node_whisperx_assets
node_whisperx_transcribe -->|"aligns"| node_whisperx_alignment
node_whisperx_alignment -->|"emits"| node_whisperx_schema
node_whisperx_transcribe -->|"optionally enriches"| node_whisperx_diarize
node_whisperx_diarize -->|"uses"| node_whisperx_vads_pyannote
node_whisperx_vads_vad -->|"implements"| node_whisperx_vads_silero
node_whisperx_vads_vad -->|"implements"| node_whisperx_vads_pyannote
node_whisperx_transcribe -->|"formats"| node_whisperx_subtitles
node_whisperx_subtitles -->|"uses"| node_whisperx_conjunctions
node_whisperx_subtitles -->|"reads"| node_whisperx_schema
node_whisperx_audio -->|"uses assets"| node_whisperx_assets
node_whisperx_transcribe -->|"uses"| node_whisperx_utils
node_whisperx_transcribe -->|"logs"| node_whisperx_log_utils

click node_whisperx___main__ "https://github.com/m-bain/whisperx/blob/main/whisperx/__main__.py"
click node_whisperx___init__ "https://github.com/m-bain/whisperx/blob/main/whisperx/__init__.py"
click node_whisperx_audio "https://github.com/m-bain/whisperx/blob/main/whisperx/audio.py"
click node_whisperx_transcribe "https://github.com/m-bain/whisperx/blob/main/whisperx/transcribe.py"
click node_whisperx_asr "https://github.com/m-bain/whisperx/blob/main/whisperx/asr.py"
click node_whisperx_alignment "https://github.com/m-bain/whisperx/blob/main/whisperx/alignment.py"
click node_whisperx_subtitles "https://github.com/m-bain/whisperx/blob/main/whisperx/SubtitlesProcessor.py"
click node_whisperx_schema "https://github.com/m-bain/whisperx/blob/main/whisperx/schema.py"
click node_whisperx_conjunctions "https://github.com/m-bain/whisperx/blob/main/whisperx/conjunctions.py"
click node_whisperx_vads_vad "https://github.com/m-bain/whisperx/blob/main/whisperx/vads/vad.py"
click node_whisperx_vads_silero "https://github.com/m-bain/whisperx/blob/main/whisperx/vads/silero.py"
click node_whisperx_vads_pyannote "https://github.com/m-bain/whisperx/blob/main/whisperx/vads/pyannote.py"
click node_whisperx_diarize "https://github.com/m-bain/whisperx/blob/main/whisperx/diarize.py"
click node_whisperx_utils "https://github.com/m-bain/whisperx/blob/main/whisperx/utils.py"
click node_whisperx_log_utils "https://github.com/m-bain/whisperx/blob/main/whisperx/log_utils.py"
click node_whisperx_assets "https://github.com/m-bain/whisperx/tree/main/whisperx/assets"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_whisperx___main__,node_whisperx___init__ toneBlue
class node_whisperx_audio,node_whisperx_transcribe,node_whisperx_asr,node_whisperx_alignment,node_whisperx_subtitles,node_whisperx_conjunctions toneAmber
class node_whisperx_vads_vad,node_whisperx_vads_silero,node_whisperx_vads_pyannote,node_whisperx_diarize toneMint
class node_whisperx_schema,node_whisperx_utils,node_whisperx_log_utils toneRose
class node_whisperx_assets toneIndigo
```

## Components

### Entry points

User-facing CLI and Python API surfaces.

- [CLI](https://github.com/m-bain/whisperx/blob/main/whisperx/__main__.py): entrypoint · Command-line interface for running transcription workflows. · `whisperx/__main__.py`
- [API](https://github.com/m-bain/whisperx/blob/main/whisperx/__init__.py): package API · Public Python package surface for library consumers. · `whisperx/__init__.py`

### Core pipeline

Audio ingest, transcription, alignment, and transcript shaping.

- [Audio ingest](https://github.com/m-bain/whisperx/blob/main/whisperx/audio.py): audio preprocessing · Decodes media and normalizes audio for model consumption. · `whisperx/audio.py`
- [Transcribe](https://github.com/m-bain/whisperx/blob/main/whisperx/transcribe.py): orchestration · Coordinates the transcription workflow and batching. · `whisperx/transcribe.py`
- [ASR engine](https://github.com/m-bain/whisperx/blob/main/whisperx/asr.py): speech recognition · Runs batched speech-to-text inference via the model backend. · `whisperx/asr.py`
- [Alignment](https://github.com/m-bain/whisperx/blob/main/whisperx/alignment.py): forced alignment · Converts segment transcripts into word-level timestamps. · `whisperx/alignment.py`
- [Subtitles](https://github.com/m-bain/whisperx/blob/main/whisperx/SubtitlesProcessor.py): post-processing · Shapes aligned transcripts into subtitle-ready output. · `whisperx/SubtitlesProcessor.py`
- [Conjunctions](https://github.com/m-bain/whisperx/blob/main/whisperx/conjunctions.py): sentence shaping · Helps split or merge transcript text for subtitle flow. · `whisperx/conjunctions.py`

### Speaker path

Optional diarization and VAD components.

- [VAD core](https://github.com/m-bain/whisperx/blob/main/whisperx/vads/vad.py): vad interface · Common voice activity detection interface and orchestration hooks. · `whisperx/vads/vad.py`
- [Silero VAD](https://github.com/m-bain/whisperx/blob/main/whisperx/vads/silero.py): vad backend · Silero-based speech activity detector. · `whisperx/vads/silero.py`
- [Pyannote VAD](https://github.com/m-bain/whisperx/blob/main/whisperx/vads/pyannote.py): vad backend · Pyannote-based speech activity detector. · `whisperx/vads/pyannote.py`
- [Diarization](https://github.com/m-bain/whisperx/blob/main/whisperx/diarize.py): speaker labeling · Assigns speaker identities to transcript turns and words. · `whisperx/diarize.py`

### Shared support

Helpers, schema, and logging used across the package.

- [Schema](https://github.com/m-bain/whisperx/blob/main/whisperx/schema.py): transcript schema · Defines the structured transcript and segment data model. · `whisperx/schema.py`
- [Utils](https://github.com/m-bain/whisperx/blob/main/whisperx/utils.py): shared helpers · General-purpose helpers shared across the package. · `whisperx/utils.py`
- [Logging](https://github.com/m-bain/whisperx/blob/main/whisperx/log_utils.py): diagnostics · Logging and runtime diagnostic helpers. · `whisperx/log_utils.py`

### Assets

Bundled runtime assets.

- [Assets](https://github.com/m-bain/whisperx/tree/main/whisperx/assets): bundled models · Packaged runtime assets used by audio and model loading. · `whisperx/assets`

## Connections

- 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.
