How speechforge/tts_hindi works
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 Models · train.py Train · text Text Frontend · hindi_tts.config Hinglish Config
Components 26
Frontend & Alignment
Hindi text normalization, symbol mapping, and forced-alignment corpus preparation.
- Text Frontend · Hindi text normalization and tokenization boundary.
text - Cleaners · Text cleanup and normalization rules.
text/cleaners.py - Symbols · Token inventory and symbol mapping.
text/symbols.py - Hindi Labels · Hindi-specific grapheme label definitions.
text/hindi_common_labels.py - G2G Dict · Grapheme-to-grapheme dictionary support.
IndicMFA/Hindi_Dictionary_g2g.txt - IndicMFA · Forced-alignment corpus preparation and resources.
IndicMFA - Corpus Prep · Builds Hindi MFA-ready corpora.
IndicMFA/prepare_hindi_mfa_corpus.py
Synthesis Core
Training, model internals, predictors, losses, and waveform generation.
- Data Utils · Dataset loading and batching.
data_utils.py - Transforms · Waveform and feature transforms.
transforms.py - Mel Features · Mel spectrogram processing utilities.
mel_processing.py - Models · Main VITS-style speech synthesis model.
models.py - Modules · Reusable neural network components.
modules.py - Attentions · Attention and alignment mechanisms.
attentions.py - Commons · Shared math and utility functions.
commons.py - Predictors · StyleTTS2-inspired duration and rhythm predictors.
styletts2_predictors.py - Losses · Optimization targets for acoustic and alignment learning.
losses.py - Phase Vocoder · Final waveform synthesis stage.
phase_aware_vocoder.py
Runtime & Config
Entrypoints, experiment configuration, and dependency boundaries.
- Train · Main training script.
train.py - Train MS · Multi-speaker or alternate training path.
train_ms.py - Infer · Synthesis entrypoint.
infer.py - Inference · Alternate inference runner.
inference.py - Evaluate · Evaluation script for TTS outputs.
evaluate_tts.py - Hinglish Config · Central experiment and hyperparameter definition.
configs/hindi_tts.config - Utils · General helper functions.
utils.py - Requirements · Base Python and PyTorch dependency set.
requirements.txt - Mamba Deps · Additional runtime dependencies for Mamba blocks.
requirements-mamba.txt
Connections 28
- 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.