Kabyle TTS
# Kabyle TTS - ONNX Inference with Correct Tokenization
A production-ready Kabyle (Taqbaylit) text-to-speech solution using the `facebook/mms-tts-kab` ONNX model with correct MMS tokenization.
## Overview
This script works around critical bugs in the `phoonnx` library (all versions including 1.3.4a1) that prevent proper Kabyle speech synthesis:
- **Bug 1:** `VoiceConfig.from_dict()` overwrites `config["blank"] = "_"` instead of using `"|"` from the config
- **Bug 2:** `TTSTokenizer.from_phoonnx_config()` ignores config fields (`add_blank_char`, `blank_between`, etc.)
- **Bug 3:** The phoneme map doesn't include `"_"`, so `blank_id` becomes `None`
- **Bug 4:** Without valid `blank_id`, `intersperse_blank_char()` does nothing
- **Bug 5:** Result: tokens without blanks → gibberish audio
## Solution
This implementation:
1. Uses the **original MMS tokenizer** (`transformers.VitsTokenizer`) for correct tokenization
2. Runs **ONNX inference directly** via `onnxruntime`
3. Manually implements blank token insertion matching MMS VITS behavior
4. Maps missing characters (p, v, o) to closest Kabyle equivalents
## Requirements
```bash
pip install transformers torch onnxruntime-gpu huggingface_hub scipy
```
For CPU-only:
```bash
pip install transformers torch onnxruntime huggingface_hub scipy
```
## Quick Start
### In Python
```python
from kabyle_tts_suppress_mapped import KabyleTTS
# Initialize
tts = KabyleTTS(use_cuda=True)
# Synthesize
tts.speak("Azul, amek i telliḍ ?", "output.wav")
# With speed control (0.8 = slower, 1.2 = faster)
tts.speak("Taqbaylit d tutlayt tamezwarut n Lezzayer.", speed=0.8)
```
### In Google Colab
Copy the entire script into a single cell and run. All dependencies will be installed automatically.
## Character Mapping
The MMS model was trained on Kabyle text without certain characters. The following mappings are applied:
| Character | Maps To | Reason |
|---|---|---|
| `p` | `b` | 'p' not in Kabyle alphabet |
| `v` | `f` | 'v' not in …