# quentinfuxa/whisperlivekit architecture

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

- Interactive diagram: https://gitdiagram.com/quentinfuxa/whisperlivekit
- Repository: https://github.com/quentinfuxa/whisperlivekit

## Overview

##### Main Components
- Client Side (Browser Interface):
- Built-in web UI served through a simple HTML page (found under whisperlivekit/web/live_transcription.html) using MediaRecorder for capturing audio.
- Sends audio chunks (in webm/opus format) over WebSocket.

- Server Side (FastAPI Application):
- API entry point (e.g., whisper_fastapi_online_server.py and FastAPI routes in your example code).
- WebSocket endpoint ("/asr") that handles incoming audio from clients.
- HTTP endpoints for serving the web UI.

- Audio Processing & Transcription Modules:
- AudioProcessor (handles decoding, buffering via FFmpeg integration).
- Whisper streaming logic found in whisperlivekit/whisper_streaming_custom modules for ASR.
- Basic server and core coordination in whisperlivekit/basic_server.py and whisperlivekit/core.py.

- Speaker Diarization:
- Dedicated diarization module in whisperlivekit/diarization (using Diart and potentially pyannote models).
- Processes audio streams for real-time speaker identification.

- External Dependencies & Services:
- FFmpeg (for live decoding of audio chunks).
- External model delivery (via dynamic downloading if not cached locally).
- Optional third-party libraries like torch, diart, and pyannote.audio for advanced features.

##### Relationships & Data Flow
- The Browser (client) captures and sends audio data via WebSocket to the FastAPI backend.
- The FastAPI server receives audio and passes it to the AudioProcessor.
- The AudioProcessor invokes the streaming ASR backend (and optionally the diarization backend) for real-time transcription.
- Processed transcription data is sent back to the client through the WebSocket connection.
- Configuration and inter-module communication (e.g., buffering management and confidence validation) exist between the audio modules and the main server.

##### Architectural Patterns & Design Principles
- Separation of concerns is evident by distinguishing between:
- Client-side UI (responsible for capturing audio and displaying results)
- Server-side API & business logic (using FastAPI for WebSocket management and routing)
- Audio processing and ASR logic (modularized in separate Python modules)
- Modular design that allows plugging in different Whisper backends and optional diarization.
- Real-time processing with asynchronous event-driven design (e.g., async functions and WebSocket communication).

##### Relevant Technologies, Frameworks, or Libraries
- FastAPI and WebSocket support for server/client communication.
- FFmpeg for runtime audio decoding.
- Various Whisper ASR backends (faster-whisper, whisper_timestamped, mlx-whisper, or openai-api) for transcription.
- Diart (and pyannote.audio) for real-time speaker diarization.
- Python libraries for async processing, dependency injection, and potentially configuration parsing.

- Each major component should have a clear label:
- "Browser / MediaRecorder (Client)"
- "FastAPI Server (HTTP & WebSocket Endpoints)"
- "AudioProcessor Module (FFmpeg Decoding & Buffering)"
- "Whisper ASR Backend (Streaming Transcription)"
- "Speaker Diarization Module (Diart/pyannote Integration)"
- "Configuration & Optional Integrations (VAC, Model Management)"
- Audio capture flow: Browser → WebSocket → FastAPI → AudioProcessor.
- Transcription flow: AudioProcessor → Whisper ASR backend → (optional: Diarization module) → WebSocket → Browser.
- Annotations where necessary such as “Decoding via FFmpeg”, “Real-time processing with async”, or “Model backend lookup”.

##### Extra Detail
- Loosely coupled architecture that allows swapping out the ASR backend and enabling/disabling diarization as needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Domain
    subgraph "Client Domain"
        client("Browser / MediaRecorder (Client)"):::client
    end

    %% Server Domain
    subgraph "Server Domain"
        fas("FastAPI Server (HTTP & WebSocket Endpoints)"):::server
        core("Core Coordination & Server Utilities"):::server
        subgraph "Audio Processing Unit"
            ap("AudioProcessor Module (FFmpeg Decoding & Buffering)"):::processing
            asr("Whisper ASR Backend (Streaming Transcription Logic)"):::processing
            diag("Speaker Diarization Module (Diart/pyannote Integration)"):::processing
        end
    end

    %% Data Flow
    client -->|"SendsAudioViaWS"| fas
    fas -->|"ForwardsAudio"| ap
    ap -->|"TranscribesAudio"| asr
    ap -->|"OptionalDiarization"| diag
    asr -->|"ReturnsTranscription"| fas
    diag -->|"ReturnsSpeakerData"| fas
    fas -->|"SendsResults"| client
    fas -->|"CoordinatesServices"| core

    %% Click Events
    click client "https://github.com/quentinfuxa/whisperlivekit/blob/main/whisperlivekit/web/live_transcription.html"
    click fas "https://github.com/quentinfuxa/whisperlivekit/blob/main/whisper_fastapi_online_server.py"
    click fas "https://github.com/quentinfuxa/whisperlivekit/blob/main/whisperlivekit/basic_server.py"
    click ap "https://github.com/quentinfuxa/whisperlivekit/blob/main/whisperlivekit/audio_processor.py"
    click asr "https://github.com/quentinfuxa/whisperlivekit/tree/main/whisperlivekit/whisper_streaming_custom"
    click diag "https://github.com/quentinfuxa/whisperlivekit/tree/main/whisperlivekit/diarization"
    click core "https://github.com/quentinfuxa/whisperlivekit/blob/main/whisperlivekit/core.py"

    %% Styles
    classDef client fill:#A2D9CE,stroke:#117864,stroke-width:2px;
    classDef server fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef processing fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
