# dimkablin/speech2text_factory architecture

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

- Interactive diagram: https://gitdiagram.com/dimkablin/speech2text_factory
- Repository: https://github.com/dimkablin/speech2text_factory

## Overview

##### Main Components

a) Client Layer:
- Web Interface (from docs/index.html)
- External API Consumers

b) API Layer (FastAPI):
- Main API Gateway (src/api/main.py)
- Endpoints Controller (src/api/app/endpoint.py)
- CRUD Operations (src/api/app/crud.py)
- Middleware (src/api/app/middleware.py)
- Data Models (src/api/app/models.py)

c) Core Processing Layer:
- Speech-to-Text Factory (src/ai_models/speech2text.py)
- Model Interface (src/ai_models/speech2text_interface.py)
- Multiple STT Model Implementations:
- Whisper Model (src/ai_models/whisper/model.py)
- Custom STT Model (src/ai_models/stt/model.py)

d) Utility Layer:
- Feature Extraction (src/utils/features_extractor.py)
- Buffer Management (src/ai_models/stt/buffer)

**[Client Layer]**
- ↓
**[API Layer]**
- ↓
**[Core Processing Layer]**
- ↓
**[Utility Layer]**

##### Key Relationships

- Factory pattern relationship between speech2text.py and the different model implementations
- Data flow from audio input through feature extraction to model processing
- Relationship between the buffer system and model processing

##### Specific Elements

a) API Endpoints (as listed in README):
- GET / (Homepage)
- GET /get-model-names/
- GET /get-current-model/
- POST /speech-to-text/
- GET /get-model-config/
- POST /change-model/

b) Model Factory System:
- How speech2text.py acts as a factory for different model implementations
- Interface pattern using speech2text_interface.py

c) Data Flow:
- Audio input (.mp3, .wav)
- Feature extraction process
- Model processing
- Text output

##### Technical Stack Indicators

- Python 3.10
- FastAPI
- PyTorch
- CUDA
- Docker

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL["Client Layer"]
        WI["Web Interface"]:::client
        CS["Client Scripts"]:::client
        AC["API Consumers"]:::client
    end

    %% API Layer
    subgraph AL["API Layer"]
        AG["API Gateway"]:::api
        EC["Endpoints Controller"]:::api
        CR["CRUD Operations"]:::api
        MW["Middleware"]:::api
        DM["Data Models"]:::api
    end

    %% Core Processing Layer
    subgraph CPL["Core Processing Layer"]
        STF["Speech-to-Text Factory"]:::core
        MI["Model Interface"]:::core
        subgraph Models["Model Implementations"]
            WM["Whisper Model"]:::model
            CM["Custom STT Model"]:::model
        end
    end

    %% Utility Layer
    subgraph UL["Utility Layer"]
        FE["Feature Extraction"]:::util
        BM["Buffer Management"]:::util
        AD["Audio Data"]:::data
    end

    %% Relationships
    WI --> AG
    CS --> AG
    AC --> AG
    AG --> EC
    EC --> CR
    EC --> DM
    MW --> EC
    CR --> STF
    STF --> MI
    MI --> WM
    MI --> CM
    WM & CM --> FE
    FE --> BM
    AD --> FE

    %% API Endpoints
    AG --> |"GET /"| WI
    AG --> |"GET /get-model-names"| STF
    AG --> |"GET /get-current-model"| STF
    AG --> |"POST /speech-to-text"| STF
    AG --> |"GET /get-model-config"| STF
    AG --> |"POST /change-model"| STF

    %% Click Events
    click WI "https://github.com/dimkablin/speech2text_factory/blob/master/docs/index.html"
    click CS "https://github.com/dimkablin/speech2text_factory/blob/master/docs/script.js"
    click AG "https://github.com/dimkablin/speech2text_factory/blob/master/src/api/main.py"
    click EC "https://github.com/dimkablin/speech2text_factory/blob/master/src/api/app/endpoint.py"
    click CR "https://github.com/dimkablin/speech2text_factory/blob/master/src/api/app/crud.py"
    click MW "https://github.com/dimkablin/speech2text_factory/blob/master/src/api/app/middleware.py"
    click DM "https://github.com/dimkablin/speech2text_factory/blob/master/src/api/app/models.py"
    click STF "https://github.com/dimkablin/speech2text_factory/blob/master/src/ai_models/speech2text.py"
    click MI "https://github.com/dimkablin/speech2text_factory/blob/master/src/ai_models/speech2text_interface.py"
    click WM "https://github.com/dimkablin/speech2text_factory/blob/master/src/ai_models/whisper/model.py"
    click CM "https://github.com/dimkablin/speech2text_factory/blob/master/src/ai_models/stt/model.py"
    click FE "https://github.com/dimkablin/speech2text_factory/blob/master/src/utils/features_extractor.py"
    click BM "https://github.com/dimkablin/speech2text_factory/tree/master/src/ai_models/stt/buffer"
    click AD "https://github.com/dimkablin/speech2text_factory/tree/master/src/data"

    %% Styles
    classDef client fill:#gray,stroke:#333,stroke-width:2px
    classDef api fill:#blue,stroke:#333,stroke-width:2px
    classDef core fill:#purple,stroke:#333,stroke-width:2px
    classDef model fill:#green,stroke:#333,stroke-width:2px
    classDef util fill:#yellow,stroke:#333,stroke-width:2px
    classDef data fill:#orange,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Client Component"]:::client
        L2["API Component"]:::api
        L3["Core Component"]:::core
        L4["Model Component"]:::model
        L5["Utility Component"]:::util
        L6["Data Component"]:::data
    end
```
