Pocket TTS (Kyutai, ~100M params) running
on-device with LiteRT CompiledModel. Pocket TTS is a flow-matching LM over continuous
32-dim Mimi latents: per 12.5 Hz frame a 6-layer/1024-wide causal transformer conditions a
6-block AdaLN MLP flow head that turns one Gaussian draw into the next latent (Lagrangian
Self Distillation, 1 step — no diffusion loop); a 20M tiny Mimi (×16 ConvTranspose upsample +
2-layer transformer + SEANet) decodes latents to 24 kHz audio. No FFT anywhere in the
pipeline, which is exactly why this architecture fits the LiteRT delegates.
This was the first flow-matching LM in the parent zoo, and the first TTS there whose entire pipeline — language model, flow head and codec decoder — ran on the GPU.
| Model | kyutai/pocket-tts (CC-BY-4.0); ungated weights: pocket-tts-without-voice-cloning |
| Converted | mlboydaisuke/Pocket-TTS-LiteRT |
| Backbone | 6-layer transformer, d=1024, 16 heads, GELU FFN ×4, LayerNorm, RoPE |
| Flow head | SimpleMLPAdaLN, 6 res blocks × 512, 2 time conditions (LSD) |
| Codec | pocket Mimi: quantizer-free 32-dim latents, ×16 upsample, 2-layer transformer (context 250), SEANet (ratios 6·5·4) |
| Rates | 12.5 Hz latent frames · 1920 samples/frame · 24 kHz mono |
| Voices | precomputed prompt-state KV caches (alba, marius, javert, charles, mary, eve — CC-BY-4.0/CC0 only) |
| App | com.pockettts — pick a voice, type text, generate, play |
Measured on a Pixel 11 (cubs, Tensor G6, Android 17): ~0.85x real-time
on a 14 s paragraph (16.4 s wall, first audio ~3.3 s). The same split that wins
on G5 still wins here: int8 flow-LM on CPU, Mimi decoder transformer on
CPU, SEANet on GPU. The NPU is available through on-device JIT, but is
slower than CPU on this release pair; the AOT files the 2.3.0 compiler SDK
produces do not load on the public 2.3.x runtime. Details and numbers:
docs/pixel11-g6.md.
| stage | graph | where | why |
|---|---|---|---|
| flow-LM (fused step + flow head) | pt_flowlm_fused_dyn8_all.tflite |
CPU, dynamic-range int8 | The step is DRAM-bandwidth-bound: int8 weights cut the per-frame stream 4x. On G6 the NPU JIT path is slower (7.69 s vs 6.43 s LM stage on the paragraph test). |
| Mimi decoder transformer | pt_mimi_dec_tx_fp16.tflite |
CPU | The G5 NPU graph gave 131 ms vs 489 ms CPU, but the 2.3.0 compiler aborts on this graph for G6, so the NPU path does not exist here. |
| SEANet decoder | pt_mimi_deconly_w512_fp16.tflite |
GPU, sliding 512-position window | Runs behind the LM over a window instead of the full 4096 positions, so audio starts as soon as the first window is decodable. |
The app picks this automatically. force_npu.txt (write lm) opts into the
NPU JIT graph; force_cpu.txt / force_gpu.txt / force_fp32.txt still
override. Decisions and rejected variants: docs/int8_lm.md,
docs/streaming.md, docs/pixel11-g6.md; the joint CPU/GPU/NPU timing tables:
docs/RESULTS.md; the library API: docs/library.md.
scripts/reproduce_best.sh runs all of these in order; each stage also runs alone
(build, quant, stream, aot, shim, push, apk, env, summary). All
of it must run under Linux or WSL2 — litert-converter has no Windows wheel.
- Reference clone at the pinned commit:
git clone https://github.com/kyutai-labs/pocket-tts.git references/pocket-tts git -C references/pocket-tts checkout 001cf6e
- Conversion venv (Python 3.10, CPU torch, pinned stack) — see
AGENTS.mdandscripts/requirements-convert.txt. Defaults to~/pockettts-conv/.venv. - Base graphs + host assets —
python scripts/build_pockettts.py all. Downloads the ungatedkyutai/pocket-tts-without-voice-cloningweights, runs ~3 minutes, and writes the fp16 graphs, the host.binassets, the tokenizer and the voices intoscripts/out/. - int8 flow-LM —
PT_QUANT=dyn8_all python scripts/build_pockettts.py quant. Dynamic-range int8, channelwise weights, fp32 activations, no calibration; the graph's inputs and output stay fp32, so nothing in the host protocol changes. - AOT-compile for a Tensor NPU (optional) —
python scripts/aot_tensor_npu.py pt_mimi_dec_tx_fp16 --soc g6(defaultg6; use--soc g5for a Pixel 10). It needs its own venv:ai-edge-litert==2.3.0plusai-edge-litert-sdk-google-tensor==2.3.0, built withGOOGLE_TENSOR_SDK_BETA=litert_plugin_compiler.tar.gz. On G6 the decoder transformer does not compile and the resulting AOT models do not load on the public 2.3.x runtime, so the app uses on-device JIT for the opt-in NPU path (pt_flowlm_fused_dyn8_all_contiguous_jit.tflite) and keepsdec_txon CPU. Seedocs/pixel11-g6.md. - Streaming SEANet windows —
python scripts/build_pockettts.py streamexportspt_mimi_deconly_w{512,1024,2048}{,_fp16}.tflite(PT_STREAM_Woverrides the list). Each is a prefix-exact copy of the full 4096-position window on the host; the app streams through the 512 one. Without it the app falls back to one-shot decoding — correct, but audio only starts once the whole utterance is decoded. - NPU runtime — LiteRT 2.3.x supplies the dispatch shim and the on-device
compiler plugin through the Maven dependency
com.google.ai.edge.litert:litert-npu-runtime-google-tensor:2.3.2(the app also pinslitert:2.3.2andlitert-gpu:2.3.2). No manual.sodownload is needed. - Device —
scripts/install_to_device.sh, then./gradlew :app:installDebug.ADB=<path>overrides the adb binary; setADB_SERIALwhen more than one device is attached.
The int8 flow-LM and the G6 model files are produced by this branch and are not in the published mlboydaisuke/Pocket-TTS-LiteRT bundle, which carries the fp16 graphs.
Two ways to add a voice. Both write pt_voice_<name>.bin, and both are picked up
by scripts/install_to_device.sh, the demo app and the Android TTS service.
Fetch a preset that ships upstream (--list shows them, with licence notes):
PYTHONPATH="$PWD/references/pocket-tts" PT_OUT="$PWD/scripts/out" \
python scripts/download_voices.py # permissive presets not bundled
scripts/install_to_device.sh scripts/outOr clone one from your own recording (a clean WAV plus its UTF-8 transcript):
PYTHONPATH="$PWD/references/pocket-tts" PT_OUT="$PWD/scripts/out" \
python scripts/create_voice.py sample.wav sample.txt my_voice --preview
scripts/install_to_device.sh scripts/outNames must start with a lowercase letter and contain only lowercase letters,
digits, _ or -; add --force to replace an existing voice.
create_voice.py keeps the transcript as pt_voice_my_voice.txt and uses it for
the optional --preview. Pocket TTS computes the voice state from the WAV alone,
so the transcript never affects the embedding. Both scripts need the model
weights, which live in the gated kyutai/pocket-tts on Hugging Face: accept its
terms and authenticate first. Use only recordings you have permission to clone.
The upstream embeddings are not redistributable wholesale: download_voices.py
excludes the two names whose source datasets are CC-BY-NC, and asks for
--include-restricted before fetching them. Installed voices appear in the
engine's voice list and the system TTS settings without an app rebuild.
Every graph is stateless; KV caches, RoPE tables, the token-embedding lookup, the
32→1024 latent projection, noise draws and EOS logic live in Kotlin
(PocketTtsEngine.kt / PocketTtsSession.kt in :pockettts-core) — the
dia2/vibevoice packed-KV pattern.
| graph | I/O | fp16 size |
|---|---|---|
pt_flowlm_fused |
emb[1,1,1024] + cos/sin[1,1,1,64] + mask[1,16,1,513] + pk/pv[1,96,512,64] + noise[1,32] → [1,12321] = eos ∣ latent ∣ new-k ∣ new-v | 169 MB |
pt_flowlm_fused_dyn8_all |
the same I/O (int8 weights only, activations still fp32) | 82 MB |
pt_mimi_dec_tx |
lat[1,65,32] → feat[1,512,1024] | 17 MB |
pt_mimi_deconly |
feat[1,512,4096] → audio[1,1,491520] | 11 MB |
pt_mimi_deconly_w{512,1024,2048} |
feat[1,512,W] → audio[1,1,W*120] — the same decoder over a shorter window, for streaming | 8.3 / 8.6 / 9.3 MB |
pt_flowlm_step / pt_flow_head |
the same frame split into two graphs (cond exposed) — reference variant, not loaded by the app | 151 + 18 MB |
The app runs the fused frame graph: on Mali the per-frame cost is dispatch/sync-bound,
not FLOP-bound — with the split graphs one frame measured ~11 ms input write + ~12 ms
run() + ~20 ms readback (the readback hides the asynchronous GPU completion, spread over
four separate output reads) plus a second invocation for the head. Fusing the head and
concatenating everything into one output removes one invocation and three readbacks per
frame (−1.1 s on an 8 s utterance, measured).
Placement: the Mimi decoder transformer (pt_mimi_dec_tx) ships on CPU. Every graph
compiles fully on the GPU (Replacing N out of N node(s) with delegate (LITERT_CL)) on
both devices tried, but on the Pixel 8a's Mali the GPU OUTPUT of that one graph is audibly
degraded — gravelly, hissy voicing. Measured on the alba voice: HNR 0.9 dB and −32 dB
high-band noise on GPU vs 2.8 dB / −37 dB on CPU, which matches the fp32 desktop eager
reference exactly; requesting GpuOptions(precision = FP32) does NOT recover it (0.6 dB),
so this is not fp16 rounding — the same decoder-transformer behavior the mimi/ module
documents, and the σ-VAE class of finding from vibevoice/. The SEANet graph on GPU is
clean (CPU-pinning it changes nothing but speed), as are the LM and flow head. The
transformer is 7 small calls per utterance: 1.03× → 1.01× real-time on the Pixel.
force_gpu.txt containing dectx restores the all-GPU placement for experiments.
Measured with LiteRT 2.1.6, decode included, app process warm:
- Pixel 8a (Tensor G3, Mali-G715), shipped placement: ~1.0× real-time (8.8 s of speech in 8.75 s; 12.5 s in 13.1 s over 3 chunks). The gap to Adreno is per-step overhead (25 MB of packed-KV upload plus ~500 kernel dispatches per 78-MMAC step), not arithmetic. Pinning the flow-LM to CPU instead measures 1.24–1.60× here, but the LM stays on the GPU by policy.
- Samsung SM-S942Q (Snapdragon SM8850, Adreno): 4.3–5.0× real-time (8.2 s in 1.63 s; 13.0 s in 3.05 s over 3 chunks) — measured with the all-GPU placement and the split step+head graphs before the placement change; the dec-tx-on-CPU delta measured ~2% on the Pixel.
Whisper-transcribing the on-device WAVs reproduces the input text on both devices. The
KV-step FULLY_CONNECTED shapes are the class Mali rejects on LiteRT 2.1.3 and accepts
from 2.1.5, hence the 2.1.6 pin here.
| op | rewrite |
|---|---|
| erf-GELU | fitted odd tanh-polynomial tanh(z(c1+z²(c3+z²(c5+z²c7)))), max gelu err 7.1e-5 — ~15× closer than the classic tanh-GELU (which measurably shifted latents); z clamped to ±5.5 with RELUs so fp16 never sees big powers |
| interleaved RoPE | de-interleave permutation baked into the QKV projection rows (bit-exact: q and k share it, so q·k is unchanged); host feeds per-step cos/sin |
| rank-5 QKV reshape | slice the packed projection into thirds (GPU max rank is 4) |
| attention mask | runtime additive input, host-expanded to [1,16,1,513] (fp16-safe −1e4) |
| causal/banded mask (Mimi) | baked const additive bias [1,1,S,S], window 250 |
| ConvTranspose1d (×16 depthwise, SEANet) | ZeroStuffConvT1d (nearest-upsample × const stuff-mask + flipped grouped conv), streaming-trim reproduced by cropping |
| streaming conv state | constant left zero-pad (= fresh-state streaming, pad_mode constant) |
| ELU | relu(x) − relu(1 − exp(min(x,0))) (SELECT-free, exact) |
| LayerNorm (Mimi tx) | scaled-reduction form (exact; guards fp16 var against |x|≈59 activations) |
| LayerScale (Mimi tx) | baked into out_proj / linear2 rows |
| LSD time embeddings | s=0, t=1 are constants → folded into the flow head's cond bias; the +noise integration is in-graph |
1. The Mimi decoder transformer's receptive field stacks. Its sliding window is 250 positions, but with 2 layers a kept output needs 2·249 = 498 positions of exact left context. Decoding in 512-position blocks with a 256-position overlap looks right and is subtly wrong everywhere after the first block (corr 0.999, max err 0.5). Blocks here are 1024 positions (64 frames) sliding by 32 frames, keeping the right 512 — 512 ≥ 498 ⇒ exact (verified corr 1.000000 against full-sequence eager).
2. The ×16 upsample reaches one frame back. Kernel 32, stride 16: the first 16
positions of a block depend on the previous latent frame. Slot 0 of the dec_tx input is
that context frame; for the very first block the host passes the neutral latent
−emb_mean/emb_std, whose denormalized features are exactly zero — the algebraic
equivalent of "no frame". Feeding zeros instead injects emb_mean and corrupts the seam.
3. The text prompt also "generates". The reference implementation samples (and
discards) one latent right after prompting the text; the first real latent comes from the
BOS embedding, not from the last text position. Replaying text tokens per-step through the
same KV graph reproduces the batched prompt exactly (causal), but the BOS input is
input_linear(bos_emb), a host-side constant.
For the best configuration, use the one-shot script:
scripts/reproduce_best.sh # env + base graphs + int8 LM + stream + AOT + shim
scripts/reproduce_best.sh push apk # push to the device and installBy hand, that is:
# graphs + assets + parity (needs a pocket-tts clone on PYTHONPATH and the
# litert-torch conversion env; downloads the ungated english weights)
PYTHONPATH=/path/to/pocket-tts python scripts/build_pockettts.py all
# int8 flow-LM for the CPU (the single biggest win: 2.27x on the LM step)
PYTHONPATH=/path/to/pocket-tts PT_QUANT=dyn8_all python scripts/build_pockettts.py quant
# sliding-window SEANet decoders, so audio starts during generation
PYTHONPATH=/path/to/pocket-tts python scripts/build_pockettts.py stream
# AOT for a Tensor NPU (optional; G6 can only JIT the FlowLM and lacks dec_tx)
python scripts/aot_tensor_npu.py pt_flowlm_fused_dyn8_all_contiguous --soc g6 --truncation half
# the NPU dispatch shim comes from the litert-npu-runtime-google-tensor Maven AAR
./scripts/install_to_device.sh # pushes scripts/out -> device files dir
./gradlew :app:installDebugEnvironment this was built in, re-run 2026-09-18: Python 3.10, torch 2.12.1, litert-torch 0.9.3,
ai-edge-litert 2.1.6, ai-edge-quantizer 0.8.0, plus pocket-tts' own requirements (sentencepiece,
safetensors, huggingface_hub, scipy); pocket-tts clone at 001cf6e. all takes about 3 minutes
on an M4 Max: it downloads the ungated kyutai/pocket-tts-without-voice-cloning weights, writes
every file the HF repo carries into scripts/out/ (the re-run was byte-identical to the published
files — sha256 of all 20 LFS files matched), and prints the tflite-vs-eager numbers of the
Validation table below. Stages run individually (flowlm, head, fused, dectx, deconly,
assets, pipeline, multistep, quant); PT_OUT=<dir> redirects the output.
First launch before the push fails with "Missing pt_..." by design; run the app once, push, relaunch. Everything (fp16 graphs + assets + 6 voices ≈ 225 MB) loads from the app's external files dir.
The engine, model delivery and TTS service are a reusable library; :app is a thin
demo on top. Full guide: docs/library.md.
| module | what |
|---|---|
:pockettts-core |
dev.pockettts — PocketTtsEngine, PocketTtsSession, ModelSource family |
:pockettts-service |
PocketTtsService, an Android TextToSpeechService registered by its own manifest |
:app |
demo UI — picks a voice, types text, streams to an AudioTrack |
val engine = PocketTtsEngine(context) // once per process; compiles the graphs
val session = engine.newSession("alba")
// streaming, blocking: audio starts during generation
engine.stream("Hello! I am Pocket TTS.", "alba") { chunk ->
track.write(chunk, 0, chunk.size, AudioTrack.WRITE_BLOCKING)
}
// or asynchronous and cancellable, for a voice agent's barge-in
val u = session.speak("Hello!", listener)
u.cancel()Models come from a chained ModelSource: an adb-pushed directory first (so
iterating on a rebuilt graph needs no APK rebuild), then a versioned GitHub release
with a SHA-256 manifest, optionally bundled assets. ReleaseModelSource.ensure()
downloads only the variants the device's placement needs. Pack and publish with
scripts/pack_models.py + a gh release create; test the download path with
scripts/serve_models.py and adb reverse.
| check | result |
|---|---|
| flow-LM step vs eager (teacher-forced, 41 steps) | cond corr 1.000000, latent max|d| 1.4e-2 (all from the GELU polynomial; erf-GELU control: 1.7e-5) |
flow head vs eager lsd_decode |
max|d| 2.4e-7 |
| fused frame graph vs split step+head modules (12 free-run steps) | max|d| 0.0 (identical); tflite corr 1.000000 |
| dec_tx blocks vs full-sequence eager | corr 1.000000, max|d| 5.2e-4 |
dec_tx + SEANet vs eager decode_from_latent |
corr 1.000000, max|d| 2.0e-4 |
| full tflite pipeline vs eager, same noise | audio corr 0.997, identical EOS step |
| tokenizer port vs sentencepiece | 613/613 strings exact |
| on-device WAV → Whisper | input text reproduced |
Voice cloning needs the Mimi encoder, and its weights ship only in the gated
kyutai/pocket-tts repo — the ungated bundle
zeroes them. Accepting Kyutai's terms there unlocks the missing piece; the encoder is the
same SEANet re-authoring as the decoder (the mimi/ module in the parent zoo already has
the recipe), plus a per-step replay of the projected latents to warm the KV cache — the
graphs here would not change.
Extracted from
geneing/LiteRT-Models-Pocket-TTS,
the LiteRT model zoo where this conversion and all of its optimization work were
originally done. That repo is a fork of
john-rocky/LiteRT-Models, which established
the zoo's conventions, the shared Kotlin helpers under common/ and the per-model
conversion recipes. Only the pockettts/ module was carried over, with its full history:
the milestone branches are preserved here as optim/*.
Thanks to Kyutai for
Pocket TTS, and to the Google teams behind
LiteRT and
litert-torch.