Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / speech / src / main / assets / supertonic / README.md
| 1 | # Supertonic 3, bundled |
| 2 | |
| 3 | `SupertonicSynthesizer.inAssets` reads these six files, and `SupertonicBundle.isPresent` refuses to |
| 4 | advertise the TTS engine unless they are all here. They are **not in version control** — see the |
| 5 | entry in `/.gitignore` for why — so a fresh checkout has to build them: |
| 6 | |
| 7 | ``` |
| 8 | python scripts/ml/fetch_supertonic.py |
| 9 | ``` |
| 10 | |
| 11 | That fetches `Supertone/supertonic-3` pinned to one revision, checks all four ONNX SHA-256s, and |
| 12 | runs both converters. Each converter also checks its own layer-table digest against |
| 13 | `maml_convert.EXPECTED_DIGEST`, so a bundle built from a moved upstream fails loudly rather than |
| 14 | producing a net that reads the right shapes holding the wrong numbers. |
| 15 | |
| 16 | | File | What it is | |
| 17 | | :--- | :--- | |
| 18 | | `supertonic_dp.maml` | duration predictor — one number, the utterance's length in seconds | |
| 19 | | `supertonic_ttl.maml` | text encoder — characters to a `[256, chars]` conditioning | |
| 20 | | `supertonic_ve.maml` | flow-matching sampler — the expensive one, 32 passes per sentence | |
| 21 | | `supertonic_voc.maml` | ConvNeXt vocoder — latent to 44,100 Hz samples | |
| 22 | | `unicode_indexer.bin` | 65,536 `int16`, one per BMP codepoint; the whole front end | |
| 23 | | `style_F1.bin` … `style_M5.bin` | ten voices, ~25 KB each; two style tensors, not a model | |
| 24 | |
| 25 | At int8 the four nets come to 107.6 MiB, which with Whisper's 74.3 MiB puts `:speech`'s assets at |
| 26 | 181.9 MiB — 190.7 MB, under the 200 MB target. Every ungrouped `1 x 1` convolution is quantised in |
| 27 | the sampler, the vocoder and the duration predictor; the text encoder stays fp16 on measurement, and |
| 28 | each net's `INT8_CONVS` doc says exactly what is excluded and why. |
| 29 | |
| 30 | `onnx_parity.py` against this revision, fp16 and int8 side by side, correlation with onnxruntime: |
| 31 | |
| 32 | | net | fp16 | int8 | size | |
| 33 | | :--- | ---: | ---: | ---: | |
| 34 | | `supertonic_dp` | 0.99999975 | 0.99999250 | 1.73 → 1.44 MB | |
| 35 | | `supertonic_ttl` | 0.99900006 | *not quantised* | 17.77 MB | |
| 36 | | `supertonic_voc` | 0.99999858 | 0.99909061 | 50.67 → 28.70 MB | |
| 37 | | `supertonic_ve` | 0.99999981 | 0.99996750 | 127.64 → 64.48 MB | |
| 38 | |
| 39 | **The vocoder is the one to listen to first.** 0.99909 clears the 0.999 bar the conversion was gated |
| 40 | on, but it implies roughly −27 dB of error against fp16's −55 dB, and no correlation can say whether |
| 41 | that is audible. Holding it at fp16 costs 21 MB and still fits the target. |
| 42 | |
| 43 | Verified by `library/ml/src/main/rust/tests/assets.rs`, which builds all four forward passes against |
| 44 | these files and checks the codepoint table and every style is the size the runtime assumes. Those |
| 45 | tests **skip** when the bundle is absent, so they pass on a fresh checkout and fail on a wrong one. |
| 46 | |
| 47 | ## Uncompressed, and it has to stay that way |
| 48 | |
| 49 | `noCompress += "maml"` in `speech/build.gradle.kts` is load-bearing rather than an optimisation: |
| 50 | `AssetManager.openFd` throws for a deflated entry, and the fd is how the weights reach the GPU |
| 51 | without being copied through the Java heap three times. Adding a `.bin` entry would be worth it too |
| 52 | if the codepoint table ever grew, but at 128 KB it is read whole anyway. |
| 53 | |
| 54 | ## Licence |
| 55 | |
| 56 | Supertonic 3 is **OpenRAIL**, which is use-restricted — the first such licence in this tree, and the |
| 57 | reason `SUPPLY_CHAIN_RISKS.md` calls it out separately. It ships in the APK rather than being |
| 58 | downloaded, so the restriction travels with every release. |