File size: 3,478 Bytes
5fb7215 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | ---
license: apache-2.0
language:
- fa
pipeline_tag: text-to-speech
library_name: pytorch
datasets:
- oddadmix/tiny-voca-persian-dataset
tags:
- persian
- farsi
- tts
- tiny-voca
- multi-speaker
---
# tiny-voca-persian
A Persian (Farsi) text-to-speech model with two voices, **male** (`fa_male`) and **female** (`fa_female`). It has 4.53M
parameters and was trained from scratch, with no pretrained weights, on
[oddadmix/tiny-voca-persian-dataset](https://huggingface.co/datasets/oddadmix/tiny-voca-persian-dataset) (145 h after alignment checks, synthetic speech).
It is built on the architecture and training code of [tiny-voca](https://huggingface.co/n4ze3m/tiny-voca) by Muhammed Nazeem (Apache-2.0).
Demo: [oddadmix/tiny-voca-persian](https://huggingface.co/spaces/oddadmix/tiny-voca-persian).
Input is ordinary Persian text. The front end writes numbers out in words, normalizes letter forms and half-spaces, gets the
pronunciation (including ezafe) from [mehdi-hf/persian-g2p-tiny](https://huggingface.co/mehdi-hf/persian-g2p-tiny) (MIT), and
adds word stress by rule. The model then produces 24 kHz audio. The speech model runs about 90× faster than real time on one CPU thread;
the G2P adds roughly 0.15–0.2 s for each new sentence on CPU.
## Evaluation
Speech from the model was transcribed with Whisper large-v3 and compared with the text. The held-out texts were never seen in training.
"Recordings" means the training-voice audio of the same texts, transcribed the same way.
| | voice | word error | char error | word error, recordings | char error, recordings | duration vs recordings |
|---|---|---|---|---|---|---|
| test (50 per voice) | male | 11.4% | 2.7% | 16.2% | 4.0% | 1.01 |
| test (50 per voice) | female | 12.5% | 2.6% | 18.4% | 4.2% | 1.00 |
| validation (50 per voice) | male | 14.6% | 2.9% | 19.5% | 4.5% | 1.00 |
| validation (50 per voice) | female | 13.3% | 2.8% | 18.0% | 4.2% | 1.00 |
Whisper's Persian spelling (half-spaces, joined words) differs from the reference text in many places, so word error is high
even on the recordings; character error is the more telling number.
## Files
- `tiny-voca-persian.pt`: the checkpoint (weights, config, front-end fingerprint, duration calibration phone +0.05 / pause −0.06).
- `code/tiny_voca/`: inference code and the Persian front end (`text.py`, `fa_normalize.py`).
- `samples/`: the same texts in both voices (`texts.txt`).
## Use
```bash
pip install torch transformers soundfile huggingface_hub
```
```python
import os, sys, soundfile as sf
os.environ["TV_FA_G2P_REVISION"] = "3f6994c82e52628fe948102a7009d281fc9aa99d" # the G2P revision used in training
sys.path.insert(0, "code")
from tiny_voca.infer import load_model, speak_text
model = load_model("tiny-voca-persian.pt")
wave, spoken = speak_text(model, "سلام، وقت بخیر. سفارش شما با موفقیت ثبت شد.", "fa_female") # or "fa_male"
sf.write("out.wav", wave.numpy(), 24000)
```
`speak_text` reads text of any length sentence by sentence and also takes `speed` (1.0 = normal), `pitch_shift` and `seed`.
The G2P runs on CUDA when available; set `TV_FA_G2P_DEVICE=cpu` to force CPU.
## Limitations
- Persian in Arabic script only. Latin-script words are skipped.
- The G2P sometimes adds an ezafe where none belongs, or misses one; stress is rule-based (last syllable; first for می/نمی verbs).
- ONNX export is not available for this model yet.
- All voices are synthetic.
|