tiny-voca-arabic-code-switching
A text-to-speech model for Modern Standard Arabic with English words mixed in, as people write about work, technology
and daily life ("ุงุฌุชู
ุงุน ุงูู team ุนูู Zoom"). Two voices, male (arcs_male) and female (arcs_female).
It has 4.54M parameters and was trained from scratch, with no pretrained weights, on
oddadmix/tiny-voca-arabic-code-switching-dataset (133 h after alignment checks, synthetic speech;
about 80% of the texts mix in English, 20% are plain MSA).
It is built on the architecture and training code of tiny-voca by Muhammed Nazeem (Apache-2.0).
Demo: tiny-voca-arabic-code-switching.
Input
- Arabic in Arabic script, English in Latin script, in the same sentence.
- The Arabic article on an English word is written
ุงููwith a tatweel:ุงูู meeting,ุจุงูู email,ููู team,ูุงูู app. It is pronounced the Arabic way, including assimilation before English sun sounds (ุงูู teamโ at-team). - Numbers are read in Arabic, except inside English names (
iPhone 15,GPT-4,5G).
Front end
- Arabic runs: vowelled by CATT (Apache-2.0, ONNX), then MSA pronunciation rules, the same as tiny-voca-arabic.
- English runs: dizione (Apache-2.0), the tiny-voca English phonemizer (CMUdict-derived lexicon, a small neural G2P for unknown words).
- One 86-symbol inventory: Arabic phonemes plus English phonemes, shared IPA symbols counted once.
Evaluation
Speech from the model was transcribed with Jais-ASR (code-switching mode, which keeps English in Latin script) 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. Phone error turns the transcript and the text into phonemes, folded into accent-neutral classes, and compares them; English recall is the share of the text's English words that the transcript writes back in English.
| voice | word error | word error, recordings | phone error | phone error, recordings | English recall | duration vs recordings | pauses vs recordings | |
|---|---|---|---|---|---|---|---|---|
| test (50 per voice) | male | 4.5% | 4.3% | 0.042 | 0.037 | 91.5% | 1.00 | 1.18 |
| test (50 per voice) | female | 4.1% | 3.6% | 0.032 | 0.028 | 87.6% | 1.01 | 1.14 |
| validation (50 per voice) | male | 6.4% | 7.2% | 0.049 | 0.057 | 94.2% | 1.02 | 1.28 |
| validation (50 per voice) | female | 7.1% | 7.9% | 0.051 | 0.061 | 75.9% | 1.01 | 0.99 |
8 new code-switched sentences written for the evaluation, dense with English: male: word error 11.3%, phone error 0.096; female: word error 9.8%, phone error 0.086.
Files
model.safetensors: the same weights in safetensors format (metadata holds the config).tiny-voca-arabic-code-switching.pt: the checkpoint (weights, config, front-end fingerprint, duration calibration phone +0.008 / pause +0.000).onnx/model.onnx+onnx/model.json: the same model as one ONNX graph (phoneme ids in, 24 kHz audio out) and its metadata (voices, symbols, front-end fingerprint).code/tiny_voca/: inference code, the front end (text.py,arabic_frontend.py,numbers.py) and the ONNX exporter (export.py).code/dizione/andphonemizer/: the English phonemizer and its data (CMUdict license inphonemizer/LICENSE.cmudict).samples/: the same texts in both voices (texts.txt).
Use
pip install torch soundfile onnxruntime catt-tashkeel==1.0.2 # torch only for the .pt checkpoint
import os, sys, soundfile as sf
os.environ["DIZIONE_DATA"] = "phonemizer"
sys.path.insert(0, "code")
from tiny_voca.infer import load_model, speak_text
model = load_model("tiny-voca-arabic-code-switching.pt")
wave, spoken = speak_text(model, "ุงุฌุชู
ุงุน ุงูู team ุณูููู ุบุฏุง ุนูู Zoomุ ููุง ุชูุณ ู
ุฑุงุฌุนุฉ ุงูู slides.", "arcs_female") # or "arcs_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.
ONNX
The speech model runs in ONNX Runtime; the text front end stays in Python (the tiny_voca package still imports PyTorch).
It gives the same audio as the PyTorch checkpoint (same durations, sample differences at float-rounding level).
import os, sys, json, numpy as np, onnxruntime as ort, soundfile as sf
os.environ["DIZIONE_DATA"] = "phonemizer"
sys.path.insert(0, "code")
from tiny_voca.text import phonemize
meta = json.load(open("onnx/model.json"))
session = ort.InferenceSession("onnx/model.onnx", providers=["CPUExecutionProvider"])
p = phonemize("ุฃุฑุณูุช ูู ุงูู link ุนูู ุงูู email.") # one sentence per call
audio, durations = session.run(None, {
"tokens": np.array([p.ids], dtype=np.int64), "stress": np.array([p.stress], dtype=np.int64),
"voice": np.array([meta["voices"].index("arcs_female")], dtype=np.int64),
"speed": np.array([1.0], np.float32), "pitch_shift": np.array([0.0], np.float32), "pitch_range": np.array([1.0], np.float32)})
sf.write("out.wav", audio[0], meta["sample_rate"])
Limitations
- English is spoken with an Arabic accent, as in the training voices; long all-English sentences are outside what it was trained on.
- Arabic short vowels come from the CATT diacritizer, which sometimes picks the wrong reading of an unvowelled word; adding the vowel marks yourself fixes it.
- Pauses run longer than in the recordings: about 15% on average, up to 28% for the male voice on validation.
- All voices are synthetic.
- Downloads last month
- -