Moroccan Darija TTS training pipeline based on FastPitch + HiFi-GAN, using the DODa dataset.
- Downloads and formats DODa audio/text data
- Merges datasets and ensures WAV-ready training data
- Extracts F0 (pitch) features
- Generates a training config automatically
- Fine-tunes FastPitch + HiFi-GAN
- Runs checkpoint-based inference tests
- Linux environment recommended (local Linux, cloud VM, Vast, etc.)
- Python 3.10+ (3.12 supported in current workflow)
- NVIDIA GPU + CUDA
ffmpeg- Hugging Face account with access to DODa
Install ffmpeg:
sudo apt update && sudo apt install -y ffmpeggit clone --recurse-submodules https://github.com/K-BEL/Voice_trainer.git
cd Voice_trainer--recurse-submodules is required to pull models/tts/tts-arabic-pytorch.
Each stage is independent so you can review the dataset before committing to a long training run:
# Stage 1 — Install Python packages + pretrained weights (once per instance)
bash scripts/setup-deps.sh
# Stage 2 — Download + format the DODa dataset
bash scripts/download-dataset.shManually review the raw dataset before continuing:
datasets/doda-dataset/doda/data.csv ← spot-check audio/caption pairs
datasets/doda-dataset/doda/audios/ ← listen to a few files
Delete any rows where the caption does not match the audio.
# Run the interactive review tool (plays 20 random samples)
python3 scripts/review_dataset.py \
--dataset-dir datasets/doda-dataset/doda \
--n 20
# Controls: Enter/k = keep | r = remove | q = quit
# Rejected rows are removed from data.csv automatically.Then continue:
# Stage 3 — Merge, convert to WAV, extract F0, generate config
bash scripts/prepare-dataset.sh
# Stage 4 — Train
bash models/tts/src/finetune.shSkips the manual review step — runs all stages in sequence:
bash scripts/setup_tts_doda.shCommon options:
# Skip dataset download (dataset already exists)
bash scripts/setup_tts_doda.sh --skip-download
# Skip pretrained model download
bash scripts/setup_tts_doda.sh --skip-pretrained
# Customize training length at config-generation time
bash scripts/setup_tts_doda.sh --epochs 200 --save-interval 1000The setup script creates a virtual environment at ./venv. To activate it for ad-hoc commands:
source venv/bin/activatebash models/tts/src/finetune.shOutputs:
- Checkpoints:
models/tts/checkpoints/ - TensorBoard logs:
models/tts/logs/
Generate test audio for all .pth checkpoints in a directory:
bash models/tts/src/test-ckpts.sh models/tts/checkpointsGenerated audio is saved under:
models/tts/results/<checkpoint_name>/
- Run setup once
- Start training
- Let it run for a while
- Test checkpoints periodically (or use the Gradio demo)
- Best checkpoints are saved automatically as
best_model.pth
Test any checkpoint interactively in your browser:
bash models/tts/src/demo.sh models/tts/checkpointsThen open http://0.0.0.0:7860 in your browser. Features:
- Text input with Darija/Arabic
- Checkpoint selector (auto-discovers all
.pthfiles) - Adjustable speaker ID and pace
- Real-time audio playback
If the demo is running on a remote server, use SSH port forwarding to see it on your local browser:
# Run this on your LOCAL machine
ssh -L 7860:localhost:7860 user@remote-ipThen open http://localhost:7860 on your local browser. Alternatively, use the --share flag to get a public URL:
bash models/tts/src/demo.sh models/tts/checkpoints --shareEnabled by default. Gives ~2x speedup and uses ~40% less VRAM.
# Disable if you encounter issues
VT_AMP=0 bash models/tts/src/finetune.shCosine annealing with warm-up (1000 iters by default). Gradually decays the learning rate for better convergence.
Automatically splits your dataset 90/10 and tracks validation loss. Saves best_model.pth when validation improves. Stops training if no improvement for 10 epochs.
Automatically deletes old numbered checkpoints, keeping only the 3 most recent. Prevents disk-full crashes.
All training features are controllable via environment variables:
| Variable | Default | Description |
|---|---|---|
VT_AMP |
1 |
Enable mixed precision training |
VT_KEEP_CKPTS |
3 |
Number of checkpoints to keep (0 = disable cleanup) |
VT_VAL_SPLIT |
0.1 |
Validation split ratio (0 = disable validation) |
VT_PATIENCE |
10 |
Early stopping patience (0 = disable) |
VT_WARMUP_ITERS |
1000 |
LR warmup iterations |
VT_LR_MIN_RATIO |
0.01 |
Minimum LR as ratio of initial LR |
VT_GAN_WARMUP_ITERS |
1000 |
GAN loss warmup iterations |
VT_RESUME_OPTIMIZERS |
0 |
Resume optimizer states from checkpoint |
VT_RESUME_PROGRESS |
0 |
Resume epoch/iter counters from checkpoint |
VT_DISABLE_TB |
0 |
Disable TensorBoard logging |
Example with custom settings:
VT_KEEP_CKPTS=5 VT_PATIENCE=20 VT_AMP=1 bash models/tts/src/finetune.shBefore terminating your VM/instance, archive and download outputs:
cd /workspace/Voice_trainer
tar -czf export_voice_trainer_$(date +%Y%m%d_%H%M).tar.gz \
models/tts/checkpoints \
models/tts/src/config.yaml \
models/tts/results \
models/tts/logsThen copy locally with scp:
scp -P <PORT> root@<IP>:/workspace/Voice_trainer/export_voice_trainer_*.tar.gz .- Use
hf auth login(new CLI) in the same environment running setup. - Confirm access to DODa on Hugging Face.
- Verify with:
python -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'no-gpu')"- Some rows may be skipped by tokenizer/phonemizer logic.
- A small amount is expected; too many may reduce final quality.
- AMP handles most NaN/Inf gradient issues automatically now.
- If problems persist:
VT_AMP=0to disable mixed precision. - Reduce learning rates in
models/tts/src/config.yaml(g_lr,d_lr).
- Auto-cleanup is now enabled by default (keeps 3 checkpoints).
- Adjust with
VT_KEEP_CKPTS=5for more safety margin.
Voice_trainer/
├── scripts/
│ ├── setup-deps.sh ← Stage 1: install packages + weights
│ ├── download-dataset.sh ← Stage 2: download + format DODa
│ ├── prepare-dataset.sh ← Stage 3: merge, WAV, F0, config
│ ├── setup_tts_doda.sh ← All-in-one (chains the 3 above)
│ └── download_format_doda.py
├── models/
│ └── tts/
│ ├── src/
│ │ ├── finetune.sh
│ │ ├── test-ckpts.sh
│ │ ├── demo.sh
│ │ ├── demo.py
│ │ ├── train_fp_adv.py
│ │ ├── generate-config.py
│ │ ├── extract_f0_penn.py
│ │ ├── download_files.py
│ │ └── test_raw_model.py
│ └── tts-arabic-pytorch/
├── tools/dataset/
│ ├── merge-datasets.py
│ └── mp3-to-wav.sh
├── requirements.txt
└── pyproject.toml
AGPL-3.0. See LICENSE.