File size: 8,492 Bytes
2e0d354
 
 
 
 
 
 
 
 
 
 
 
f1a5159
2e0d354
f1a5159
2e0d354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1a5159
2e0d354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1a5159
2e0d354
 
 
 
 
 
 
 
 
 
 
f1a5159
2e0d354
 
233fb41
f1a5159
2e0d354
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
license: apache-2.0
language: [en]
pipeline_tag: text-to-speech
base_model: Zyphra/ZONOS3-Mini-hf
base_model_relation: quantized
library_name: litert
tags: [litert, tflite, android, text-to-speech, zonos3]
---

# ZONOS3-Mini for LiteRT

This repository contains [Zyphra/ZONOS3-Mini-hf](https://huggingface.co/Zyphra/ZONOS3-Mini-hf/tree/e39d30df560125d9c434acd5cb0e83e4c2d64e0d), Zyphra's text-to-speech model, as three float32 LiteRT `.tflite` graphs for the CPU, with a prebuilt Android runner and a desktop Python script. On a Pixel 11 Pro's CPU, one prepared sentence of about 4 s took 23.5 to 31.4 s from start to WAV, loading the graphs included. Speed still being tuned (updates follow).

On a Mac's CPU, the graphs gave the same audio codes as the publisher's PyTorch model in 60 of 60 test runs. On a Pixel 11 Pro and a Galaxy S26 (Snapdragon, SM8850), six prepared sentences gave the same codes as on the Mac in every frame. The language-model graph has since been replaced by a faster one with the same inputs and outputs. On the Mac and on each phone, it gave the same codes and the same WAV for these six sentences as the earlier one did on the same device.

On an Android phone, one command of the runner `android/zonos_host` speaks one of the six prepared sentences in `kit/` to a WAV file ([Use it](#use-it)). The runner takes no text, only these prepared inputs. An English sentence of your own goes through `desktop/speak.py`, which needs the publisher's files and which we ran on a Mac. On a GPU, the output was not shown to match: run the graphs on the CPU ([Notes](#notes)).

## Use it

### 1. Download

<!-- usage:download -->
```bash
pip install -U huggingface_hub
hf download litert-community/ZONOS3-Mini --local-dir ZONOS3-Mini
cd ZONOS3-Mini
```

The download is about 4.7 GB.

### 2. Speak a prepared sentence on an Android phone

You need an arm64 Android phone with USB debugging on, `adb`, and about 4.8 GB free on the phone. The runner's peak memory on both phones was 2.91 to 3.15 GB.

<!-- usage:android -->
```bash
adb shell mkdir -p /data/local/tmp/zonos3
adb push android graphs kit /data/local/tmp/zonos3/
adb shell "cd /data/local/tmp/zonos3 && chmod 755 android/zonos_host && LD_LIBRARY_PATH=android android/zonos_host kit s00 graphs/lm_step_p768.tflite graphs/codec_dec_f150.tflite out/s00"
adb pull /data/local/tmp/zonos3/out/s00/waveform.wav s00.wav
```

The runner speaks `s00`, the first prepared sentence. It writes three files into `out/s00`, which must not exist yet: `waveform.wav` (mono, 16-bit, 44.1 kHz), `waveform.f32` (the same audio in float32) and `codes.i32` (ten codes per frame). On standard error it prints `TAKE s00 frames=62 samples=182280 wall_s=…`, where `wall_s` is the time from its start to the written WAV. Replace `s00` with `s01` to `s05` for the other sentences.

Every input the runner reads is prepared. `kit/takes/s00/prompt.f32` contains the sentence and the voice Savannah as rows of 1,024 numbers, made in Python on a Mac, and `draws.f32` contains the random draws for sampling. This release has no text front end for Android, so the runner speaks only these six sentences:

| sentence | text |
|---|---|
| `s00` | The quick brown fox jumps over the lazy dog near the riverbank. |
| `s01` | Please remember to bring an umbrella, because it might rain this afternoon. |
| `s02` | She opened the window and listened to the birds singing in the garden. |
| `s03` | The train leaves at 7:45 and arrives in Boston about 3 hours later. |
| `s04` | Thank you for calling. Your order has been shipped and will arrive soon. |
| `s05` | a Japanese sentence, written in `kit/takes/s05/request.json` |

### 3. Speak your own English sentence on a Mac

This needs Python 3.12 and the publisher's files at commit e39d30df (2.39 GB: code, tokenizer, voices and weights).

<!-- usage:desktop -->
```bash
hf download Zyphra/ZONOS3-Mini-hf --revision e39d30df560125d9c434acd5cb0e83e4c2d64e0d --local-dir ZONOS3-Mini-hf
python3.12 -m venv .venv
source .venv/bin/activate
pip install -r desktop/requirements.txt
MODEL=ZONOS3-Mini-hf
python -I -B desktop/speak.py "Please remember to bring an umbrella." --model "$MODEL" --graphs graphs --out umbrella
```

The script loads the publisher's model and code from `$MODEL` (with `trust_remote_code`) and runs the graphs with ai-edge-litert 2.3.0 on 4 CPU threads. It writes `umbrella/speech.wav` (mono, 16-bit, 44.1 kHz), `umbrella/codes.npy`, `umbrella/waveform.npy` and `umbrella/run.json`, and `umbrella` must not exist yet. It speaks English in the voice Savannah and samples with PyTorch's generator from `--seed` (1000 by default). With `--speaker-wav <file.wav>`, it takes the voice of a recording instead: the speaker graph reads only the first 10 s, where the publisher's model reads up to 60 s.

## Files

| file | bytes | what |
|---|---|---|
| `graphs/lm_step_p768.tflite` | 3,342,589,152 | the language model |
| `graphs/codec_dec_f150.tflite` | 572,522,276 | the decoder: audio codes in, spectral rows out |
| `graphs/spk_enc_t998.tflite` | 45,122,316 | the speaker encoder: a voice embedding from a recording, used by the desktop script only |
| `android/zonos_host` | 7,139,128 | the Android runner, built for arm64-v8a and Android API level 28; its C++ source is in `host/` and `include/` |
| `android/libLiteRt.so` | 5,629,696 | LiteRT 2.3.0, the runtime library the runner loads (`com.google.ai.edge.litert:litert:2.3.0` on Google Maven) |
| `desktop/speak.py` | | speaks an English sentence to a WAV file with Python; `host.py`, `requirements.txt` and `README.md` sit beside it |
| `kit/` | 768,008,027 in 59 files | the prepared inputs: six sentences in `kit/takes/`, the tables they share in `kit/shared/`, and reference outputs |
| [`HOST.md`](https://huggingface.co/litert-community/ZONOS3-Mini/blob/main/HOST.md) | | how to rebuild the runner (Android NDK 29.0.13113456) and call it, and the files of `kit/` |
| `NOTICE`, `licenses/` | | the publisher's notice and license texts, LiteRT's license and notices, and the Android NDK toolchain notice ([License](#license)) |

## Notes

- **GPU.** On a Mac's GPU, the earlier language-model graph did not match the publisher's model in 910 of 910 steps. The current one was not tried on a GPU.
- **Length.** One call of the decoder graph speaks at most 150 frames (10 s, the three silence frames that open the speech included). Longer speech stops with `BucketExceeded`: split longer text and speak each part.
- **Positions.** The prompt and the generated speech share 768 positions of the language-model graph. When they are used up, generation stops with `CapacityReached`.
- **Random draws.** The prepared inputs carry their random draws, which is why both phones gave the same codes as the reference in `kit/takes/<sentence>/reference/`. For each of the six sentences, the WAV from both phones still differs from the reference WAV in 140 to 236 of its 16-bit samples (193 of 182,280 for `s00`), each by 1, because the phones' float32 audio differs from the reference by at most 3.44e-6 before rounding. An app supplies its own draws, and its codes then differ from the reference.
- **How the files were made.** The three graphs were exported in float32 with litert-torch 0.10.0 from the publisher's weights at commit e39d30df. The language-model graph computes only the two experts that the router picks in each of its ten MoE layers, not all 64.

## License

The graphs and the tables in `kit/` are derived from the publisher's weights, which the publisher releases under the Apache License 2.0 ([NOTICE](https://huggingface.co/litert-community/ZONOS3-Mini/blob/main/NOTICE)). The publisher's repository has no LICENSE file. Our own files in this repository are released under the Apache License 2.0, like the weights: the runner's source in `host/`, `HOST.md` and the scripts in `desktop/`.

`NOTICE` and the four texts in `licenses/` that it names come unchanged from that repository at commit e39d30df: the MIT license of the original ZONOS3-Mini code and the licenses of the AntSpeaker, Hugging Face Transformers and torchaudio code that the publisher's model code adapts. `android/libLiteRt.so` is LiteRT 2.3.0 from Google Maven, with its license and third-party notices in `licenses/LiteRT-LICENSE.txt` and `licenses/LiteRT-THIRD_PARTY_NOTICE.txt`. The runner links the Android NDK's C++ runtime statically (notice: `licenses/NDK-NOTICE.toolchain`), and `include/pocketfft.h` carries its own BSD license.