# siafi-unam/f-voice architecture

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

- Interactive diagram: https://gitdiagram.com/siafi-unam/f-voice
- Repository: https://github.com/siafi-unam/f-voice

## Overview

##### Project Type and Purpose
- The project is an advanced TTS (text-to-speech) system that performs synthesis in a single stage using adversarial training and an improved architectural design. It’s based on the VITS2 paper and builds on earlier work in the VITS ecosystem.
- The README highlights improvements over traditional two-stage systems, emphasizing naturalness, speaker adaptation, computational efficiency, and reduced reliance on phoneme conversion.

##### File Structure
- Top-level Python scripts (e.g., train.py, inference.py, export_onnx.py) indicate both training and inference capabilities.
- The presence of Jupyter Notebooks (e.g., create_train_val.ipynb, inference.ipynb) suggests interactive workflows for training and inference experiments.
- Configuration files in the “configs” folder (like vits2_ama.json) define model parameters and training settings.
- Text processing components are contained in the “text” directory (cleaners.py, symbols.py), which are used for text normalization and conversion.
- Audio and mel processing are defined in files such as mel_processing.py and transforms.py.
- Core modules for the model – including models.py, modules.py, commons.py, and losses.py – handle the signal processing and adversarial training aspects.
- The “monotonic_align” folder containing a .pyx file and a setup script indicates a specialized, performance-critical alignment component implemented in Cython.

a. Input / Preprocessing Layer:
- Text Input: Represent the text processing component using files found in the “text” folder and any cleaning or transformation functions in preprocess.py and preprocess_audio.py.
- Data Utilities: Include data handling utilities (data_utils.py) and transforms which help prepare data (e.g., mel spectrogram generation in mel_processing.py).

b. Core Model Architecture:
- Model Definition: Include “models.py” and “modules.py” as key nodes that define the neural network architecture used for synthesis.
- Loss Functions: Represent “losses.py” and “commons.py,” which detail the network’s loss calculations and common routines.
- Monotonic Alignment Module: Highlight “monotonic_align” as a distinct module that optimizes the alignment process within the model (note that this is compiled with Cython for performance).

c. Training & Inference:

d. Configuration and Setup:
- Configurations: Represent configuration files (e.g., the JSON file in “configs”) that feed hyperparameters and settings into various components.
- External Dependencies: Note the dependencies (like PyTorch, Espeak, Visual Studio build tools) which are pre-requisites and necessary to compile native modules.

##### Establish Relationships and Data Flow
- How raw text flows from the input and preprocessing layer to the text processing components.
- The path from prepared text and audio features into the model through feature extraction (mel spectrogram generation).
- The interplay between model components (encoder/decoder/adversarial modules) and the monotonic alignment module.
- Separation between the training pipeline (data preparation, model updating) versus the inference pipeline (data flow from preprocessed input to model prediction and audio synthesis).
- That the configuration file influences both training and inference paths as a foundational element.

##### Architectural Patterns & Technologies
- Since this is an end-to-end TTS solution built on a deep learning framework (PyTorch), emphasize the MVC-like separation:
- Model Layer (models, modules, and losses)
- Controller/Processing Layer (preprocessing scripts, text/ modules, mel processing)
- Deployment Layer (inference scripts and ONNX export capabilities)
- Point out the use of performance-critical modules like “monotonic_align” (compiled via Cython), highlighting how the system optimizes processing speed.

##### Final Steps
- Double-check that the data flow accurately represents both the training and inference workflows as described in the README.
- Annotations if needed to clarify how components interact, especially highlighting the adversarial mechanism and the integration of the monotonic alignment.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Input / Preprocessing Layer
    subgraph "Input / Preprocessing Layer"
        direction TB
        Cleaners["Cleaners"]:::textPreproc
        Symbols["Symbols"]:::textPreproc
        PreText["Preprocess Text"]:::textPreproc
        PreAudio["Preprocess Audio"]:::textPreproc
        DataUtils["Data Utils"]:::feature
        MelProc["Mel Processing"]:::feature
        Transforms["Transforms"]:::feature
    end

    %% Core Model Architecture
    subgraph "Core Model Architecture"
        direction TB
        ModelDef["Model Definition"]:::model
        LossCommon["Loss Functions & Routines"]:::model
        MonAlign["Monotonic Alignment Module"]:::model
    end

    %% Integrated Model Node
    IntegratedModel["Integrated Model"]:::model

    %% Training & Inference Layer
    subgraph "Training & Inference"
        direction TB
        %% Training Process
        subgraph "Training Process"
            direction TB
            TrainScript["Train Script"]:::training
            TrainNotebook["Train Notebook"]:::training
        end
        %% Inference Process
        subgraph "Inference Process"
            direction TB
            InferScript["Inference Script"]:::inference
            InferNotebook["Inference Notebook"]:::inference
            ExportONNX["Export ONNX"]:::inference
            InferONNX["Infer ONNX"]:::inference
        end
    end

    %% Configuration & Setup Layer
    subgraph "Configuration & Setup"
        direction TB
        VITS2Config["VITS2 Config"]:::config
    end

    %% Connections for Preprocessing Layer
    Cleaners --> Symbols
    Symbols --> PreText
    PreText --> PreAudio
    PreAudio --> DataUtils
    DataUtils --> MelProc
    MelProc --> Transforms

    %% Connections to Core Model Architecture
    Transforms --> ModelDef
    ModelDef --> LossCommon
    LossCommon --> MonAlign
    MonAlign --> IntegratedModel

    %% Connections to Training & Inference
    IntegratedModel --> TrainScript
    IntegratedModel --> InferScript

    %% Configuration influences both pipelines
    VITS2Config --> TrainScript
    VITS2Config --> InferScript

    %% Connections within Training Process
    TrainScript --> TrainNotebook

    %% Connections within Inference Process
    InferScript --> InferNotebook
    InferNotebook --> ExportONNX
    ExportONNX --> InferONNX

    %% Click Events for Input / Preprocessing Layer
    click Cleaners "https://github.com/siafi-unam/f-voice/blob/main/text/cleaners.py"
    click Symbols "https://github.com/siafi-unam/f-voice/blob/main/text/symbols.py"
    click PreText "https://github.com/siafi-unam/f-voice/blob/main/preprocess.py"
    click PreAudio "https://github.com/siafi-unam/f-voice/blob/main/preprocess_audio.py"
    click DataUtils "https://github.com/siafi-unam/f-voice/blob/main/data_utils.py"
    click MelProc "https://github.com/siafi-unam/f-voice/blob/main/mel_processing.py"
    click Transforms "https://github.com/siafi-unam/f-voice/blob/main/transforms.py"

    %% Click Events for Core Model Architecture
    click ModelDef "https://github.com/siafi-unam/f-voice/blob/main/models.py"
    click ModelDef "https://github.com/siafi-unam/f-voice/blob/main/modules.py"
    click LossCommon "https://github.com/siafi-unam/f-voice/blob/main/losses.py"
    click LossCommon "https://github.com/siafi-unam/f-voice/blob/main/commons.py"
    click MonAlign "https://github.com/siafi-unam/f-voice/blob/main/monotonic_align/core.pyx"
    click MonAlign "https://github.com/siafi-unam/f-voice/blob/main/monotonic_align/setup.py"

    %% Click Events for Training Process
    click TrainScript "https://github.com/siafi-unam/f-voice/blob/main/train.py"
    click TrainNotebook "https://github.com/siafi-unam/f-voice/blob/main/create_train_val.ipynb"

    %% Click Events for Inference Process
    click InferScript "https://github.com/siafi-unam/f-voice/blob/main/inference.py"
    click InferNotebook "https://github.com/siafi-unam/f-voice/blob/main/inference.ipynb"
    click ExportONNX "https://github.com/siafi-unam/f-voice/blob/main/export_onnx.py"
    click InferONNX "https://github.com/siafi-unam/f-voice/blob/main/infer_onnx.py"

    %% Click Event for Configuration & Setup
    click VITS2Config "https://github.com/siafi-unam/f-voice/blob/main/configs/vits2_ama.json"

    %% Styles
    classDef textPreproc fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef feature fill:#ffe699,stroke:#b38f00,stroke-width:2px;
    classDef model fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef training fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef inference fill:#d6d6f5,stroke:#3c3c8c,stroke-width:2px;
    classDef config fill:#e6ccff,stroke:#663399,stroke-width:2px;
```
