# speechforge/tts_hindi architecture

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

- Interactive diagram: https://gitdiagram.com/speechforge/tts_hindi
- Repository: https://github.com/speechforge/tts_hindi

## Overview

1. **Repository purpose**
   This is a Hindi text-to-speech system built around a VITS-style end-to-end TTS pipeline, with two notable customizations: a **Mamba-based text encoder** and **IndicMFA-driven alignment** for Hindi grapheme-level supervision.

2. **Top-level execution paths**
   The main entry points are:
   - `train.py` / `train_ms.py` for training
   - `infer.py` / `inference.py` for synthesis
   - `evaluate_tts.py` for evaluation
   These scripts sit on top of the model, data, and text-processing modules and are the primary boundaries for the system.

3. **Text frontend**
   The `text/` package is the Hindi text normalization and symbol layer. It contains cleaners, symbol definitions, and Hindi-specific label tables used to turn raw text into model-ready token sequences. `Hindi_Dictionary_g2g.txt` supports grapheme-to-grapheme handling rather than a classic phoneme-centric frontend.

4. **Alignment and corpus preparation**
   The `IndicMFA/` subproject is an external-aligner boundary. It contains its own setup and corpus-preparation script (`prepare_hindi_mfa_corpus.py`) and is used to create forced-alignment resources that anchor Hindi text/audio pairing during training. Architecturally, this is the bridge between raw speech data and supervised alignment targets.

5. **Data loading and preprocessing**
   `data_utils.py`, `transforms.py`, and `mel_processing.py` form the audio pipeline. They handle dataset loading, waveform/spectrogram transformations, and mel feature extraction used by both training and inference.

6. **Core model stack**
   `models.py`, `modules.py`, `attentions.py`, and `commons.py` implement the main neural architecture and reusable blocks. This is where the encoder/decoder, alignment components, residual blocks, and shared utilities live. The README indicates that the text encoder replaces standard Transformer blocks with **Mamba/state-space blocks**, so that design choice is concentrated in this model layer.

7. **Duration and alignment modeling**
   `styletts2_predictors.py` suggests the repo uses stochastic predictor components inspired by StyleTTS2 for rhythm and duration modeling. In system terms, this is the module that converts text-alignment information into temporal structure for speech generation.

8. **Waveform generation**
   `phase_aware_vocoder.py` is the final waveform synthesis boundary. The model does not stop at mel prediction; it includes a post-acoustic generation stage that converts intermediate acoustic representations into the output waveform.

9. **Training objectives**
   `losses.py` defines the optimization targets used to train the acoustic/alignment model. This layer ties together the text frontend, alignment supervision, duration prediction, and reconstruction objectives.

10. **Configuration and experiment control**
    `configs/hindi_tts.config` is the central experiment definition: dataset paths, model hyperparameters, and runtime settings are managed there. The architecture is therefore configuration-driven, with training/inference behavior mostly controlled by that file plus the entrypoint scripts.

11. **Runtime and dependency boundaries**
    `requirements.txt` covers the base TTS stack, while `requirements-mamba.txt` adds the Mamba-specific dependency layer. Practically, this means the repo depends on a standard PyTorch environment plus an additional state-space-model runtime for the custom encoder.

12. **Overall data flow**
    The system flow is: raw Hindi text enters the text cleaners and symbol encoder, speech data and alignments come from the IndicMFA path, the model fuses text and alignment information through the Mamba-based encoder and duration/alignment modules, and the vocoder produces the final waveform. The main architectural boundary is between **frontend/alignment preprocessing** and **neural speech synthesis**.

Main entry points: [`models.py`](https://github.com/speechforge/tts_hindi/blob/main/models.py) (Models), [`train.py`](https://github.com/speechforge/tts_hindi/blob/main/train.py) (Train), [`text`](https://github.com/speechforge/tts_hindi/tree/main/text) (Text Frontend), [`configs/hindi_tts.config`](https://github.com/speechforge/tts_hindi/blob/main/configs/hindi_tts.config) (Hinglish Config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_frontend["Frontend & Alignment"]
  node_n_text["Text Frontend"]
  node_n_cleaners["Cleaners<br/>text-normalization<br/>[cleaners.py]"]
  node_n_symbols["Symbols<br/>symbol-table<br/>[symbols.py]"]
  node_n_labels["Hindi Labels<br/>label-table"]
  node_n_dict["G2G Dict<br/>dictionary"]
  node_n_mfa["IndicMFA<br/>alignment-subproject"]
  node_n_mfa_prep["Corpus Prep<br/>alignment-prep"]
end

subgraph group_grp_model["Synthesis Core"]
  node_n_data["Data Utils<br/>data-loader<br/>[data_utils.py]"]
  node_n_transforms["Transforms<br/>audio-preprocess<br/>[transforms.py]"]
  node_n_mel["Mel Features<br/>feature-extract<br/>[mel_processing.py]"]
  node_n_models["Models<br/>model-core<br/>[models.py]"]
  node_n_modules["Modules<br/>neural-blocks<br/>[modules.py]"]
  node_n_attn["Attentions<br/>alignment-attn<br/>[attentions.py]"]
  node_n_commons["Commons<br/>shared-utils<br/>[commons.py]"]
  node_n_predictors["Predictors<br/>duration-rhythm"]
  node_n_losses["Losses<br/>training-objectives<br/>[losses.py]"]
  node_n_vocoder["Phase Vocoder"]
end

subgraph group_grp_runtime["Runtime & Config"]
  node_n_train["Train<br/>entrypoint<br/>[train.py]"]
  node_n_train_ms["Train MS<br/>entrypoint<br/>[train_ms.py]"]
  node_n_infer["Infer<br/>entrypoint<br/>[infer.py]"]
  node_n_inference["Inference<br/>entrypoint<br/>[inference.py]"]
  node_n_eval["Evaluate<br/>entrypoint<br/>[evaluate_tts.py]"]
  node_n_config["Hinglish Config<br/>[hindi_tts.config]"]
  node_n_utils["Utils<br/>support<br/>[utils.py]"]
  node_n_requirements["Requirements<br/>deps<br/>[requirements.txt]"]
  node_n_requirements_mamba["Mamba Deps"]
end

node_n_train -->|"loads"| node_n_config
node_n_train_ms -->|"loads"| node_n_config
node_n_infer -->|"loads"| node_n_config
node_n_inference -->|"loads"| node_n_config
node_n_eval -->|"loads"| node_n_config
node_n_train -->|"uses"| node_n_text
node_n_infer -->|"uses"| node_n_text
node_n_text -->|"includes"| node_n_cleaners
node_n_text -->|"includes"| node_n_symbols
node_n_text -->|"includes"| node_n_labels
node_n_text -->|"uses"| node_n_dict
node_n_mfa -->|"contains"| node_n_mfa_prep
node_n_train -->|"aligns with"| node_n_mfa
node_n_data -->|"feeds"| node_n_transforms
node_n_transforms -->|"produces"| node_n_mel
node_n_train -->|"loads"| node_n_data
node_n_models -->|"composes"| node_n_modules
node_n_models -->|"uses"| node_n_attn
node_n_models -->|"uses"| node_n_commons
node_n_models -->|"uses"| node_n_predictors
node_n_models -->|"outputs to"| node_n_vocoder
node_n_train -->|"trains"| node_n_models
node_n_infer -->|"runs"| node_n_models
node_n_eval -->|"evaluates"| node_n_models
node_n_train -->|"optimizes"| node_n_losses
node_n_models -->|"trained by"| node_n_losses
node_n_train -->|"depends on"| node_n_requirements
node_n_models -->|"depends on"| node_n_requirements_mamba

click node_n_train "https://github.com/speechforge/tts_hindi/blob/main/train.py"
click node_n_train_ms "https://github.com/speechforge/tts_hindi/blob/main/train_ms.py"
click node_n_infer "https://github.com/speechforge/tts_hindi/blob/main/infer.py"
click node_n_inference "https://github.com/speechforge/tts_hindi/blob/main/inference.py"
click node_n_eval "https://github.com/speechforge/tts_hindi/blob/main/evaluate_tts.py"
click node_n_config "https://github.com/speechforge/tts_hindi/blob/main/configs/hindi_tts.config"
click node_n_text "https://github.com/speechforge/tts_hindi/tree/main/text"
click node_n_cleaners "https://github.com/speechforge/tts_hindi/blob/main/text/cleaners.py"
click node_n_symbols "https://github.com/speechforge/tts_hindi/blob/main/text/symbols.py"
click node_n_labels "https://github.com/speechforge/tts_hindi/blob/main/text/hindi_common_labels.py"
click node_n_dict "https://github.com/speechforge/tts_hindi/blob/main/IndicMFA/Hindi_Dictionary_g2g.txt"
click node_n_mfa "https://github.com/speechforge/tts_hindi/tree/main/IndicMFA"
click node_n_mfa_prep "https://github.com/speechforge/tts_hindi/blob/main/IndicMFA/prepare_hindi_mfa_corpus.py"
click node_n_data "https://github.com/speechforge/tts_hindi/blob/main/data_utils.py"
click node_n_transforms "https://github.com/speechforge/tts_hindi/blob/main/transforms.py"
click node_n_mel "https://github.com/speechforge/tts_hindi/blob/main/mel_processing.py"
click node_n_models "https://github.com/speechforge/tts_hindi/blob/main/models.py"
click node_n_modules "https://github.com/speechforge/tts_hindi/blob/main/modules.py"
click node_n_attn "https://github.com/speechforge/tts_hindi/blob/main/attentions.py"
click node_n_commons "https://github.com/speechforge/tts_hindi/blob/main/commons.py"
click node_n_predictors "https://github.com/speechforge/tts_hindi/blob/main/styletts2_predictors.py"
click node_n_losses "https://github.com/speechforge/tts_hindi/blob/main/losses.py"
click node_n_vocoder "https://github.com/speechforge/tts_hindi/blob/main/phase_aware_vocoder.py"
click node_n_utils "https://github.com/speechforge/tts_hindi/blob/main/utils.py"
click node_n_requirements "https://github.com/speechforge/tts_hindi/blob/main/requirements.txt"
click node_n_requirements_mamba "https://github.com/speechforge/tts_hindi/blob/main/requirements-mamba.txt"

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_n_text,node_n_cleaners,node_n_symbols,node_n_labels,node_n_dict,node_n_mfa,node_n_mfa_prep toneBlue
class node_n_data,node_n_transforms,node_n_mel,node_n_models,node_n_modules,node_n_attn,node_n_commons,node_n_predictors,node_n_losses,node_n_vocoder toneAmber
class node_n_train,node_n_train_ms,node_n_infer,node_n_inference,node_n_eval,node_n_config,node_n_utils,node_n_requirements,node_n_requirements_mamba toneMint
```

## Components

### Frontend & Alignment

Hindi text normalization, symbol mapping, and forced-alignment corpus preparation.

- [Text Frontend](https://github.com/speechforge/tts_hindi/tree/main/text): package · Hindi text normalization and tokenization boundary. · `text`
- [Cleaners](https://github.com/speechforge/tts_hindi/blob/main/text/cleaners.py): text-normalization · Text cleanup and normalization rules. · `text/cleaners.py`
- [Symbols](https://github.com/speechforge/tts_hindi/blob/main/text/symbols.py): symbol-table · Token inventory and symbol mapping. · `text/symbols.py`
- [Hindi Labels](https://github.com/speechforge/tts_hindi/blob/main/text/hindi_common_labels.py): label-table · Hindi-specific grapheme label definitions. · `text/hindi_common_labels.py`
- [G2G Dict](https://github.com/speechforge/tts_hindi/blob/main/IndicMFA/Hindi_Dictionary_g2g.txt): dictionary · Grapheme-to-grapheme dictionary support. · `IndicMFA/Hindi_Dictionary_g2g.txt`
- [IndicMFA](https://github.com/speechforge/tts_hindi/tree/main/IndicMFA): alignment-subproject · Forced-alignment corpus preparation and resources. · `IndicMFA`
- [Corpus Prep](https://github.com/speechforge/tts_hindi/blob/main/IndicMFA/prepare_hindi_mfa_corpus.py): alignment-prep · Builds Hindi MFA-ready corpora. · `IndicMFA/prepare_hindi_mfa_corpus.py`

### Synthesis Core

Training, model internals, predictors, losses, and waveform generation.

- [Data Utils](https://github.com/speechforge/tts_hindi/blob/main/data_utils.py): data-loader · Dataset loading and batching. · `data_utils.py`
- [Transforms](https://github.com/speechforge/tts_hindi/blob/main/transforms.py): audio-preprocess · Waveform and feature transforms. · `transforms.py`
- [Mel Features](https://github.com/speechforge/tts_hindi/blob/main/mel_processing.py): feature-extract · Mel spectrogram processing utilities. · `mel_processing.py`
- [Models](https://github.com/speechforge/tts_hindi/blob/main/models.py): model-core · Main VITS-style speech synthesis model. · `models.py`
- [Modules](https://github.com/speechforge/tts_hindi/blob/main/modules.py): neural-blocks · Reusable neural network components. · `modules.py`
- [Attentions](https://github.com/speechforge/tts_hindi/blob/main/attentions.py): alignment-attn · Attention and alignment mechanisms. · `attentions.py`
- [Commons](https://github.com/speechforge/tts_hindi/blob/main/commons.py): shared-utils · Shared math and utility functions. · `commons.py`
- [Predictors](https://github.com/speechforge/tts_hindi/blob/main/styletts2_predictors.py): duration-rhythm · StyleTTS2-inspired duration and rhythm predictors. · `styletts2_predictors.py`
- [Losses](https://github.com/speechforge/tts_hindi/blob/main/losses.py): training-objectives · Optimization targets for acoustic and alignment learning. · `losses.py`
- [Phase Vocoder](https://github.com/speechforge/tts_hindi/blob/main/phase_aware_vocoder.py): vocoder · Final waveform synthesis stage. · `phase_aware_vocoder.py`

### Runtime & Config

Entrypoints, experiment configuration, and dependency boundaries.

- [Train](https://github.com/speechforge/tts_hindi/blob/main/train.py): entrypoint · Main training script. · `train.py`
- [Train MS](https://github.com/speechforge/tts_hindi/blob/main/train_ms.py): entrypoint · Multi-speaker or alternate training path. · `train_ms.py`
- [Infer](https://github.com/speechforge/tts_hindi/blob/main/infer.py): entrypoint · Synthesis entrypoint. · `infer.py`
- [Inference](https://github.com/speechforge/tts_hindi/blob/main/inference.py): entrypoint · Alternate inference runner. · `inference.py`
- [Evaluate](https://github.com/speechforge/tts_hindi/blob/main/evaluate_tts.py): entrypoint · Evaluation script for TTS outputs. · `evaluate_tts.py`
- [Hinglish Config](https://github.com/speechforge/tts_hindi/blob/main/configs/hindi_tts.config): config · Central experiment and hyperparameter definition. · `configs/hindi_tts.config`
- [Utils](https://github.com/speechforge/tts_hindi/blob/main/utils.py): support · General helper functions. · `utils.py`
- [Requirements](https://github.com/speechforge/tts_hindi/blob/main/requirements.txt): deps · Base Python and PyTorch dependency set. · `requirements.txt`
- [Mamba Deps](https://github.com/speechforge/tts_hindi/blob/main/requirements-mamba.txt): deps · Additional runtime dependencies for Mamba blocks. · `requirements-mamba.txt`

## Connections

- Train → Hinglish Config: loads · Training is driven by the central experiment config.
- Train MS → Hinglish Config: loads · Alternate training path uses the same config boundary.
- Infer → Hinglish Config: loads · Inference follows the configured model and data settings.
- Inference → Hinglish Config: loads · Alternate inference runner uses shared config.
- Evaluate → Hinglish Config: loads · Evaluation uses the same experiment definition.
- Train → Text Frontend: uses · Training consumes the Hindi text frontend.
- Infer → Text Frontend: uses · Inference converts raw text through the frontend.
- Text Frontend → Cleaners: includes · Text package includes normalization rules.
- Text Frontend → Symbols: includes · Text package defines the model symbol set.
- Text Frontend → Hindi Labels: includes · Text package includes Hindi label tables.
- Text Frontend → G2G Dict: uses · Frontend relies on grapheme-to-grapheme dictionary support.
- IndicMFA → Corpus Prep: contains · Alignment subproject provides corpus preparation tooling.
- Train → IndicMFA: aligns with · Training depends on forced-alignment resources.
- Data Utils → Transforms: feeds · Data loading uses preprocessing transforms.
- Transforms → Mel Features: produces · Transforms feed mel feature extraction.
- Train → Data Utils: loads · Training consumes dataset loaders.
- Models → Modules: composes · Core model is built from reusable neural blocks.
- Models → Attentions: uses · Model uses alignment and attention components.
- Models → Commons: uses · Model shares common utilities.
- Models → Predictors: uses · Model includes duration and rhythm predictors.
- Models → Phase Vocoder: outputs to · Acoustic representations are converted to waveform audio.
- Train → Models: trains · Training optimizes the synthesis model.
- Infer → Models: runs · Inference executes the trained model.
- Evaluate → Models: evaluates · Evaluation measures the model outputs.
- Train → Losses: optimizes · Training uses task losses and alignment objectives.
- Models → Losses: trained by · Model is supervised through these objectives.
- Train → Requirements: depends on · Base runtime dependencies for training.
- Models → Mamba Deps: depends on · Custom encoder requires Mamba runtime support.
