# richard523/whisperx architecture

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

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

## Overview

##### Project type and purpose
- WhisperX is an audio-processing pipeline library and CLI tool for time-accurate automatic speech recognition (ASR). It extends OpenAI’s Whisper by adding:
- Batched inference via the faster-whisper backend
- Voice Activity Detection (VAD) for segmenting speech and reducing hallucination
- Forced phoneme alignment (wav2vec2) to produce word-level timestamps
- Optional speaker diarization (pyannote-audio or silero VAD) to label speakers

##### File structure
- Top-level:
- setup.py, requirements.txt, README.md → packaging & documentation
- whisperx/ package:
- __main__.py → CLI entrypoint
- SubtitlesProcessor.py → SRT/ASS subtitle formatting
- audio.py → loading & preprocessing audio
- asr.py, transcribe.py → Whisper model loading & batched transcription
- alignment.py → forced alignment wrappers (wav2vec2 via torchaudio/HF)
- diarize.py → speaker diarization pipeline (pyannote or silero)
- vads/ → VAD implementations (pyannote, silero, generic vad.py)
- utils.py, types.py, conjunctions.py → shared helpers, type definitions, silence words

##### README for additional insights
1. Audio input → VAD segmentation
2. Batched Whisper ASR
3. Phoneme alignment → word-level timestamps
4. Speaker diarization → assign speaker IDs
5. Subtitle & transcript generation
- Lists dependencies (PyTorch, torchaudio, CTranslate2, Hugging Face, pyannote-audio)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        CLI["CLI & Python API\n(__main__.py)"]:::io
        AudioLoader["Audio Loader\n(audio.py)"]:::io
    end

    %% Preprocessing Layer
    subgraph "Preprocessing (VAD)" 
        GenericVAD["Generic VAD Interface\n(vads/vad.py)"]:::compute
        PyannoteVAD["Pyannote VAD\n(vads/pyannote.py)"]:::compute
        SileroVAD["Silero VAD\n(vads/silero.py)"]:::compute
    end

    %% Core ASR & Alignment
    subgraph "Core ASR & Alignment"
        ASREngine["Whisper ASR Engine\n(asr.py)"]:::compute
        Transcribe["Transcription Orchestrator\n(transcribe.py)"]:::compute
        Alignment["Phoneme Alignment\n(alignment.py)"]:::compute
    end

    %% Optional Enhancements
    subgraph "Optional Enhancements"
        Diarization["Speaker Diarization\n(diarize.py)"]:::compute
    end

    %% Post-processing & Output
    subgraph "Post-processing & Output"
        AssignSpeakers["assign_word_speakers"]:::compute
        Subtitles["Subtitle Processor\n(SubtitlesProcessor.py)"]:::io
        Helpers["Helpers & Types\n(utils.py, types.py,\nconjunctions.py)"]:::io
    end

    %% External Models & Assets
    subgraph "External Services & Assets"
        HFHub["Hugging Face Model Hub"]:::external
        GPU["GPU (Compute)"]:::external
        Assets["Local Model Assets\n(assets/)"]:::external
    end

    %% Data Flows
    CLI -->|"load audio"| AudioLoader
    AudioLoader -->|"raw audio"| GenericVAD
    AudioLoader -->|"raw audio"| PyannoteVAD
    AudioLoader -->|"raw audio"| SileroVAD

    GenericVAD -->|"speech segments"| Transcribe
    PyannoteVAD -->|"speech segments"| Transcribe
    SileroVAD -->|"speech segments"| Transcribe

    Transcribe -->|"utterances"| ASREngine
    ASREngine -->|"transcripts"| Alignment
    Alignment -->|"word timestamps"| AssignSpeakers

    AudioLoader -->|"raw audio"| Diarization
    Diarization -->|"speaker segments"| AssignSpeakers

    AssignSpeakers -->|"annotated segments"| Subtitles
    Helpers --> Subtitles

    HFHub --> ASREngine
    HFHub --> Alignment
    HFHub --> Diarization

    Assets --> ASREngine
    Assets --> Alignment
    Assets --> Diarization

    GPU --> ASREngine
    GPU --> Alignment
    GPU --> Diarization

    %% Click Events
    click CLI "https://github.com/richard523/whisperx/blob/main/whisperx/__main__.py"
    click AudioLoader "https://github.com/richard523/whisperx/blob/main/whisperx/audio.py"
    click GenericVAD "https://github.com/richard523/whisperx/blob/main/whisperx/vads/vad.py"
    click PyannoteVAD "https://github.com/richard523/whisperx/blob/main/whisperx/vads/pyannote.py"
    click SileroVAD "https://github.com/richard523/whisperx/blob/main/whisperx/vads/silero.py"
    click ASREngine "https://github.com/richard523/whisperx/blob/main/whisperx/asr.py"
    click Transcribe "https://github.com/richard523/whisperx/blob/main/whisperx/transcribe.py"
    click Alignment "https://github.com/richard523/whisperx/blob/main/whisperx/alignment.py"
    click Diarization "https://github.com/richard523/whisperx/blob/main/whisperx/diarize.py"
    click Subtitles "https://github.com/richard523/whisperx/blob/main/whisperx/SubtitlesProcessor.py"
    click Helpers "https://github.com/richard523/whisperx/blob/main/whisperx/utils.py"

    %% Styles
    classDef compute fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef io fill:#DFFFE0,stroke:#333,stroke-width:1px
    classDef external fill:#FFE0B3,stroke:#333,stroke-width:1px
```
