Instructions to use litert-community/Kokoro-82M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/Kokoro-82M with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Restore Kokoro-82M LiteRT (free-text 3-bundle + fixed-length sample build)
Browse files- README.md +105 -0
- istft_Wi_f32.bin +3 -0
- istft_Wr_f32.bin +3 -0
- kokoro_82m_fixedlen_fp32.tflite +3 -0
- kokoro_predictor.tflite +3 -0
- kokoro_prosody.tflite +3 -0
- kokoro_vocoder.tflite +3 -0
README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: litert
|
| 4 |
+
pipeline_tag: text-to-speech
|
| 5 |
+
base_model: hexgrad/Kokoro-82M
|
| 6 |
+
tags:
|
| 7 |
+
- litert
|
| 8 |
+
- tflite
|
| 9 |
+
- tts
|
| 10 |
+
- text-to-speech
|
| 11 |
+
- on-device
|
| 12 |
+
- kokoro
|
| 13 |
+
- free-text
|
| 14 |
+
- preview
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Kokoro-82M — LiteRT (free-text, bucketed)
|
| 18 |
+
|
| 19 |
+
> ⚠️ **Labeled preview — FP32, CPU.** Arbitrary free text → speech (not a single baked
|
| 20 |
+
> sentence). The neural graphs are LiteRT `.tflite`; two small steps run host-side (the
|
| 21 |
+
> hn-NSF source STFT and the final iSTFT overlap-add). GPU + quantization are the next steps.
|
| 22 |
+
|
| 23 |
+
A [LiteRT](https://ai.google.dev/edge/litert) (`.tflite`) conversion of
|
| 24 |
+
[hexgrad/Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M) (StyleTTS2 + ISTFTNet) for
|
| 25 |
+
on-device **free-text** text-to-speech (arbitrary text in, 24 kHz speech out). **Audio fidelity
|
| 26 |
+
≈ 0.9994 magnitude-spectrogram correlation to the PyTorch reference** (verified across multiple
|
| 27 |
+
held-out sentences, not just the export sample).
|
| 28 |
+
|
| 29 |
+
Kokoro has one data-dependent length (the duration→alignment expansion `L = sum(pred_dur)`),
|
| 30 |
+
which `litert_torch` cannot keep dynamic (the LSTM sequence axis specializes). It is therefore
|
| 31 |
+
split into **three fixed-bucket bundles** with host steps between them, so arbitrary text works
|
| 32 |
+
by left-padding to the bucket and trimming the output (longer text is split into sentences
|
| 33 |
+
host-side, each ≤ the bucket):
|
| 34 |
+
|
| 35 |
+
```
|
| 36 |
+
text --(G2P, host)--> phoneme ids
|
| 37 |
+
1. kokoro_predictor.tflite : ids[1,128], ref_s[1,256], attn[1,128] -> duration, d, t_en
|
| 38 |
+
host: pred_dur = round(duration); alignment one-hot aln[1,128,512]; frame_mask[1,512]
|
| 39 |
+
2. kokoro_prosody.tflite : d, t_en, aln, ref_s, frame_mask -> asr, F0, N
|
| 40 |
+
host: har = STFT(SineGen(f0_upsamp(F0))) (the hn-NSF excitation)
|
| 41 |
+
3. kokoro_vocoder.tflite : asr, F0, N, har, ref_s, frame_mask -> spec, phase
|
| 42 |
+
host: iSTFT overlap-add(spec, phase) -> 24 kHz waveform; trim to L*600
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## Files
|
| 46 |
+
|
| 47 |
+
| File | Precision | Size | Role |
|
| 48 |
+
|---|---|---|---|
|
| 49 |
+
| `kokoro_predictor.tflite` | fp32 | ~91 MB | PL-BERT + duration/text encoders (masked unrolled bi-LSTMs) |
|
| 50 |
+
| `kokoro_prosody.tflite` | fp32 | ~37 MB | shared prosody LSTM + F0/N (masked) |
|
| 51 |
+
| `kokoro_vocoder.tflite` | fp32 | ~236 MB | iSTFTNet decoder → magnitude/phase spectrogram |
|
| 52 |
+
| `istft_Wr_f32.bin`, `istft_Wi_f32.bin` | fp32 | 880 B each | inverse-DFT bases for the host-side iSTFT |
|
| 53 |
+
| `kokoro_82m_fixedlen_fp32.tflite` | fp32 | ~338 MB | single-graph **fixed-length demo build** used by the litert-samples `text_to_speech` sample (see below) |
|
| 54 |
+
|
| 55 |
+
Token bucket `T = 128`, frame bucket `L = 512` (≈ 12.8 s of audio per chunk at 24 kHz).
|
| 56 |
+
Bundles are **voice-independent** — the voice is the `ref_s` input (a `voices/*.pt` from the
|
| 57 |
+
base repo, indexed by token-sequence length).
|
| 58 |
+
|
| 59 |
+
## Fixed-length demo build (litert-samples)
|
| 60 |
+
|
| 61 |
+
`kokoro_82m_fixedlen_fp32.tflite` is the earlier single-graph build (fixed-length input, baked
|
| 62 |
+
demo sentence length, spec+phase out, host-side iSTFT) kept for the official
|
| 63 |
+
[litert-samples `text_to_speech` sample](https://github.com/google-ai-edge/litert-samples/pull/159),
|
| 64 |
+
which downloads it by this name. Measured on Pixel 8a (fp32, CPU, 4 threads): **RTF ≈ 1.8**
|
| 65 |
+
(~6.6 s to synthesize 3.7 s of audio) — quantization is the path to realtime on-device.
|
| 66 |
+
|
| 67 |
+
## Specs
|
| 68 |
+
|
| 69 |
+
| | |
|
| 70 |
+
|---|---|
|
| 71 |
+
| Task | Text-to-speech (English), free text, 24 kHz mono |
|
| 72 |
+
| Source | [hexgrad/Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M) (StyleTTS2 + ISTFTNet) |
|
| 73 |
+
| Fidelity | **magspec-corr 0.9994** vs PyTorch (waveform corr ≈ 0.98 — the bounded bucket pad-boundary effect; the spectrum is what's perceived) |
|
| 74 |
+
| Runtime | CPU (LiteRT CompiledModel API) |
|
| 75 |
+
|
| 76 |
+
## How it was converted
|
| 77 |
+
- Stock official converter (`litert_torch`), **general path** — Kokoro is StyleTTS2/ISTFTNet, not a transformer LLM, so the Generative-API re-authoring path does not apply.
|
| 78 |
+
- **Three fixed-bucket bundles** because the dynamic alignment length can't stay symbolic through the converter (the dynamic-LSTM wall). Every workaround is load-bearing and numerically faithful: the 6 bidirectional LSTMs are **unrolled as masked bi-LSTMs** that carry state through right-padding (a fused `nn.LSTM` leaks pad tokens into the backward pass and wrecks prosody); the 58 AdaIN InstanceNorms **normalize over real frames only** so bucket pad frames don't poison the statistics; the hn-NSF **source STFT runs host-side** (its atan2 phase flips at the F0→0 pad boundary on-device).
|
| 79 |
+
- **iSTFT runs host-side** (vocoder emits spec+phase): the in-graph conv-transpose iSTFT hits a converter weight-dedup bug that fuses the cos/sin DFT bases. The host overlap-add (no learned weights) is numerically exact.
|
| 80 |
+
|
| 81 |
+
## Training data
|
| 82 |
+
Inherited from [hexgrad/Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M): a few hundred hours of **permissive / non-copyrighted audio** — public-domain audio, audio under permissive licenses (e.g. Koniwa `tnc` CC BY 3.0, SIWIS CC BY 4.0), and synthetic audio from large-provider TTS — paired with IPA phoneme labels. No proprietary or scraped personal recordings, no custom voice clones. This LiteRT artifact is a format conversion of the released weights and introduces no additional training data.
|
| 83 |
+
|
| 84 |
+
## PII
|
| 85 |
+
No personally identifiable information is included. Per the base model's disclosure the training audio is permissive / public-domain / synthetic rather than scraped personal recordings; to the best of our knowledge the released weights contain no PII, and the conversion adds none.
|
| 86 |
+
|
| 87 |
+
## Front-end (free-text G2P)
|
| 88 |
+
For arbitrary text with no dropped words (names, brands, numbers), pair with the neural grapheme-to-phoneme front-end: [litert-community/Kokoro-G2P-en-US](https://huggingface.co/litert-community/Kokoro-G2P-en-US).
|
| 89 |
+
|
| 90 |
+
## Sample / code
|
| 91 |
+
- Official Android sample (Interpreter API, fixed-length demo build): [google-ai-edge/litert-samples #159](https://github.com/google-ai-edge/litert-samples/pull/159)
|
| 92 |
+
- Conversion / pipeline code: https://github.com/john-rocky/LiteRT-Models
|
| 93 |
+
|
| 94 |
+
## Roadmap
|
| 95 |
+
- **GPU**: the attention's fused-QKV >4-D layout + mask `EQUAL`/`SELECT` keep it on CPU; decomposing attention to ≤4-D would let it ride the GPU delegate. In-graph iSTFT on GPU additionally needs an FFT kernel in the LiteRT GPU delegate (ML Drift).
|
| 96 |
+
- **Quantization** (int8/int4) is the obvious next step.
|
| 97 |
+
|
| 98 |
+
## Status
|
| 99 |
+
Labeled preview — the converted model is parity-verified. The official litert-samples
|
| 100 |
+
`text_to_speech` sample (fixed-length demo build) is in review at
|
| 101 |
+
[google-ai-edge/litert-samples #159](https://github.com/google-ai-edge/litert-samples/pull/159);
|
| 102 |
+
a free-text sample (3-bundle + G2P front-end) is in progress.
|
| 103 |
+
|
| 104 |
+
## License
|
| 105 |
+
Apache-2.0, inherited from [hexgrad/Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M).
|
istft_Wi_f32.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:72414803f6e0acad9f459cfacb4511c6f0bc5bbf239a6db8a7b78880d06b2cad
|
| 3 |
+
size 880
|
istft_Wr_f32.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89ac7e7cd20ef63055b80cbf8864ff7c1ea214069e97d5039a4f5cc3df87bf44
|
| 3 |
+
size 880
|
kokoro_82m_fixedlen_fp32.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c5a066787eeffd73c0f10d5abf54813f3baa9020bbf1b32ef25473906e411d3c
|
| 3 |
+
size 337596032
|
kokoro_predictor.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:696847964d2537fe8d72fd71b77c1fde9ba49f33cbc0ba09fa0329680cf42241
|
| 3 |
+
size 90741756
|
kokoro_prosody.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:60c3154a4afc4626db51d7f9382ec8b87cfe2ea7979a098c52739454fdd9fe43
|
| 3 |
+
size 37393104
|
kokoro_vocoder.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:acf5043fea1fa4c522095e81f2f7c5892eb178fb1bd154ae34fb21cb60948dff
|
| 3 |
+
size 236130056
|