File size: 6,886 Bytes
a09a359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55d3971
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
tags:
  - text-to-speech
  - coreai
  - ios
  - iphone
  - arm64
  - kokoro
  - supertonic
---

# TTS Core AI Lab — converted for iOS / iPhone

This repository contains **Core AI `.aimodel` assets converted for an arm64
iOS application running on physical iPhone hardware**. It is the model-asset
companion to the [TTSCoreAILab iOS app](https://github.com/augustzheng-RED/TTSCoreAILab).

**Deployment target:** iOS 27.0+ on arm64 iPhone hardware.

**Benchmark device:** iPhone 17 Pro. This identifies the device used for the
current RTF benchmark; it is not a guarantee that every included profile has
passed end-to-end validation on every iPhone.

## What was converted

| Runtime | Upstream model | Conversion output | Intended use |
| --- | --- | --- | --- |
| Kokoro | [`hexgrad/Kokoro-82M`](https://huggingface.co/hexgrad/Kokoro-82M) PyTorch model | 11-stage Core AI `.aimodel` pipeline plus fixed-shape profiles | On-device iOS TTS research and profiling |
| Supertonic 3 | [`Supertone/supertonic-3`](https://huggingface.co/Supertone/supertonic-3) ONNX pipeline | Four Core AI `.aimodel` stages per fixed-shape profile | On-device iOS TTS research and profiling |

Kokoro subgraphs are exported through `torch.export` and converted with
`coreai_torch`. Supertonic ONNX graphs are recovered at fixed shapes, converted
through `onnx2torch` and `torch.export`, then converted with `coreai_torch`.
The resulting assets use the versioned AICode layout required by the iOS 27
device compiler.

These are deployment assets, not general-purpose PyTorch, ONNX, Core ML, web,
Android, macOS, or iOS Simulator models. Use them only with the matching
`TTSCoreAILab` app and its Core AI runtime integration.

## Device and profile notes

- The app targets `arm64` iPhone hardware with deployment target iOS 27.0.
- The iPhone 17 Pro is the current benchmark device.
- Kokoro packages include `64x64`, `128x256`, and `256x512` routed profiles,
  plus legacy/reference profiles.
- Supertonic packages include `64x32`, `128x64`, `128x128`, and `128x256`
  fixed-shape profiles.
- Asset presence does not imply physical-device validation. Validate the exact
  app revision, profile, prompt, and device before shipping or profiling.

## App integration

The iOS project downloads the two directories below into its repository root:

- `TTSCoreAILab/Models`
- `TTSCoreAILab/SupertonicResources`

From the app repository, run:

```bash
./scripts/download-assets.sh
```

---

## Project overview

Local iOS workbench for incrementally porting and profiling the split Kokoro
pipeline in Swift.

The app integrates the official KittenTTS Swift package and Supertonic 3
ONNX pipeline, and provides four modes:

- KittenTTS: ONNX Runtime CPU, eight voices, configurable speed.
- Kokoro: the existing 11-stage split Core AI pipeline.
- Supertonic 3: four Core AI models, ten voices, configurable flow steps,
  44.1 kHz.
- Compare: sequentially generates all three models for the same text, preserves
  PCM results for independent playback, and displays wall time, inference
  time, RTF, Core AI coverage, and speedup.

KittenTTS downloads its Nano model and phonemizer assets on first use. Kokoro
and Supertonic 3 use Core AI model assets hosted separately on Hugging Face:
<https://huggingface.co/augustZheng/TTS-Core-AI>.

## Model Assets

The Xcode project expects these asset directories:

- `TTSCoreAILab/Models`
- `TTSCoreAILab/SupertonicResources`

They are not committed to GitHub because the full asset bundle is about 4.2 GB
and contains files larger than GitHub's regular 100 MB file limit.

Download them from Hugging Face before building:

```bash
./scripts/download-assets.sh
```

The script uses `uv` to run the Hugging Face CLI without creating a project
virtual environment.

The current stage runs a fixed `Hi.` text-to-acoustic-feature chain:

```text
fixed token ids + attention mask
-> ALBERT
-> BERT projection
-> fixed-length duration encoder
-> duration head
-> Swift duration/alignment calculation
-> text encoder CNN + LSTM
-> Swift ASR alignment
-> F0/noise shared LSTM + residual blocks
```

Bundled assets:

- `kokoro_bert_eager_64.aimodel`
- `kokoro_bert_projection.aimodel`
- `kokoro_duration_encoder_no_pack_64_intmask.aimodel`
- `kokoro_duration_head.aimodel`
- `kokoro_text_encoder_conv_64_intmask.aimodel`
- `kokoro_text_encoder_lstm.aimodel`
- `kokoro_f0n_shared_lstm_64.aimodel`
- `kokoro_f0n_blocks_64.aimodel`

## How to Try

1. Open `TTSCoreAILab.xcodeproj` in Xcode.
2. Select the same physical iPhone target that passed the original smoke test.
3. Run the `TTSCoreAILab` app target.
4. Tap `Run Acoustic Stage`.

Expected reference result from the Python CoreAI runtime:

- shapes: `[1,64,768]`, `[1,512,64]`, `[1,64,640]`, `[1,64,50]`
- valid-token durations: `[18, 2, 5, 9, 6, 1]`
- raw predicted frames: `41`
- fixed target frames: `64`
- aligned ASR: `[1, 512, 64]`
- F0: `[1, 128]`
- noise: `[1, 128]`

Python CoreAI reference mean-absolute values:

- shared features: `0.35923`
- F0: `72.4452`
- noise: `6.59444`
- text conv: `0.02399`
- text hidden: `0.16430`
- aligned ASR: `0.18732`

The current build now also includes:

- `kokoro_decoder_pre.aimodel`
- `kokoro_generator_core.aimodel`
- `kokoro_istft.aimodel`
- fixed `Hi.` decoder style and harmonic-source fixtures
- Swift PCM-to-WAV playback through `AVAudioPlayer`

The current UI mirrors the browser Local Lab:

- editable text and `af_heart` voice selection;
- selectable bundled Core AI budgets (`64 / 64`, `128 / 256`, and `256 / 512`), with automatic profile escalation for longer segments;
- optional automatic segmentation;
- total time, Core AI inference time, audio duration, and RTF;
- per-stage Core AI timing bars;
- generated audio playback controls and a detailed run log.

The PyTorch reference and native Kokoro comparison controls are visible but
disabled because those runtimes are not bundled in the iOS app.

The bundled profiles increase the text/frame budget from `64 / 64` to
`128 / 256` and `256 / 512`; automatic mode chooses the smallest profile that
fits a segment. Supertonic ships its validated `64 / 32` baseline assets under
`SupertonicResources/coreai-assets-baseline`.

Tap `Generate Locally`. A successful run should play generated audio and report:

- generator input: `[1, 512, 128]`
- spec/phase: `[1, 22, 7681]`
- audio: `[1, 1, 38400]`
- audio mean absolute value: approximately `0.01756`
- audio min/max: approximately `-0.2076 / 0.3555`

- ## RTF Result

The current benchmark on iPhone 17 Pro.

**RTF (Real-Time Factor)** measures how long it takes to generate one second of audio.

- **RTF < 1.0** → Faster than real time (suitable for interactive TTS)

- **Lower is better**

The benchmark below compares the same prompt on the same device across different runtimes.

<p align="center">

  <img src="docs/images/rtf-result.png" width="900">

</p>