⚙️ Engineering Deep Dive
How Client-Side WebGPU & WebAssembly Neural Text-to-Speech Works
An inside look at the PureTTS architecture: executing an 82-million-parameter neural speech synthesis model directly inside a browser Web Worker with zero cloud servers.
1. Why Traditional Cloud TTS Services Have Strict Character Paywalls
For the past decade, high-fidelity neural text-to-speech required massive server-side data center GPUs (such as NVIDIA A100 or H100 clusters). Every time a user clicked "Generate" on a traditional cloud TTS website, their text was sent over an HTTPS API to a remote GPU cluster, synthesized into an audio file, stored in cloud object storage, and streamed back to the browser.
Because cloud GPU compute costs money for every second of inference, cloud TTS providers must enforce strict character limits (often 10,000 characters per month on free tiers), require account sign-ups to prevent abuse, and charge $5 to $99+ per month for longer documents. Worse yet, every confidential document or personal script must be uploaded to third-party servers.
PureTTS eliminates the server entirely. By combining two breakthrough web standards—WebGPU and SIMD WebAssembly (WASM)—with the compact, high-efficiency Kokoro-82M neural model, PureTTS shifts 100% of the compute to the processor already sitting on your desk or in your pocket.
2. Inside the Kokoro-82M Neural Architecture
One might wonder how an 82-million-parameter model can rival or outperform text-to-speech models that are 10x larger. The answer lies in the architectural efficiency of Kokoro-82M v1.0 (built upon a streamlined StyleTTS 2 and ISTFTNet decoder design):
- Decoupled Acoustic & Prosody Modeling: Rather than using a monolithic autoregressive transformer that slowly predicts one audio token at a time, Kokoro uses a lightweight phoneme encoder, a duration predictor, and style diffusion vectors that map phoneme sequences directly to acoustic features in parallel.
- ISTFTNet Vocoder (Inverse Short-Time Fourier Transform): Traditional neural vocoders (like WaveNet or full HiFi-GAN) spend enormous compute generating raw time-domain samples at 24,000 Hz. By predicting magnitude and phase spectrograms and using a deterministic Inverse STFT layer for the final waveform reconstruction, Kokoro achieves studio-clarity 24kHz audio at a fraction of the floating-point operations (FLOPs).
- Expressive Style Vectors: Each of the 10 American and British voices in PureTTS is represented as a compact acoustic style embedding vector that modulates pitch contour, timbre, and cadence across varying sentence lengths.
3. The 4-Stage In-Browser Synthesis Pipeline
When you click Convert Text to Speech in PureTTS, all execution happens asynchronously inside an isolated browser Web Worker (`tts-worker.js`) so the main UI thread stays 100% responsive:
Stage 1: Intelligent Sentence Segmentation & Normalization
Long documents (such as 50-page PDFs or full audiobook chapters) are cleaned to repair line-break hyphens and segmented into natural prosodic chunks of ~250–400 characters along punctuation boundaries. This bounds peak RAM usage regardless of whether your input is 100 words or 100,000 words.
Stage 2: Grapheme-to-Phoneme (G2P) Tokenization
Each sentence is converted from English spelling (graphemes) into International Phonetic Alphabet (IPA) phoneme tokens with primary and secondary lexical stress markers. Context-aware rules resolve heteronyms (such as "read" present tense vs. "read" past tense) before tokenization.
Stage 3: ONNX Runtime Web Inference (WebGPU vs. WASM)
The phoneme tensor and the selected voice's style embedding are fed into ONNX Runtime Web (`@huggingface/transformers` + `ort-web`). Depending on your device hardware and selected engine mode, the neural network executes either via WGSL compute shaders on your GPU (WebGPU) or multi-threaded 128-bit SIMD instructions on your CPU (WebAssembly).
Stage 4: Real-Time Streaming & 24kHz PCM WAV Concatenation
As each sentence chunk finishes inference, its 32-bit floating-point audio array is immediately dispatched to the main thread for optional real-time playback (`AudioContext`) and combined into a lossless, 24,000 Hz 16-bit PCM `.wav` file ready for one-click download.
4. WebGPU (FP32) vs. WebAssembly (Turbo q4 & Fast q8) Empirical Benchmarks
Different devices have vastly different memory ceilings, network bandwidth, and graphics capabilities. A desktop workstation with a dedicated GPU or Apple M-Series unified memory handles unquantized 32-bit floating-point tensors effortlessly, whereas mobile browsers on iOS and Android impose strict per-tab memory limits and benefit from compact quantized weights. PureTTS automatically detects your hardware environment and offers five specialized execution paths:
| Engine Mode |
Weight Precision |
Download Size (Cached) |
Target Hardware |
Audio & Performance Characteristics |
| ⚡⚡ Turbo Mode (Default) |
4-bit Quantized (wasm-q4) |
~45 MB (cached locally) |
All Desktop & Mobile Browsers (Chrome, Safari, Firefox, Edge, iOS, Android) |
Fastest initial download (7× smaller than FP32) and 35% faster CPU inference than 8-bit WASM (~0.96× real-time on single-core SIMD). |
| ⚡ Fast Mode (WASM q8) |
8-bit Quantized (wasm / wasm-mobile) |
~85 MB (cached locally) |
Desktop & Mobile Multi-Core CPUs |
100% immune to GPU driver timeouts, low memory footprint, higher quantization bit-depth (~0.72× real-time on single-core SIMD). |
| 🚀 WebGPU Studio Mode |
Full 32-bit Float (fp32) |
~326 MB (cached locally) |
Desktop Chrome, Edge, Brave with Dedicated or Apple M-Series GPU |
Maximum dynamic range, zero quantization noise, fastest real-time factor (9.4× to 10.9× faster than real-time). |
| 📱 Mobile WebGPU (Low-VRAM) |
32-bit Float (fp32) + 110-char Micro-Chunking |
~326 MB (cached locally) |
Modern Android & Mobile GPUs with WebGPU enabled |
Pairs hardware WGSL shader execution (9.1×–10.0× real-time) with 110-character micro-chunking so transient GPU activation tensors stay well below mobile OS tab memory limits. |
Live Benchmark Results Across Text Sizes (Apple M5 Pro / Chromium 157)
To quantify real-world conversion speed and streaming latency, we benchmarked all synthesis engines across four standardized text corpora using voice am_adam at 0.95x speed. We measure both Time to First Audio (TTFA)—the moment real-time streaming playback begins—and Total Synthesis Time to produce the complete gapless 24kHz WAV master:
| Corpus Size & Audio Length |
Engine Mode |
Chunks |
Time to First Audio (TTFA) |
Total Synthesis Time |
Speedup (Real-Time) |
Real-Time Factor (RTF) |
Throughput (Chars / Sec) |
Short (108 chars / 17 words) ~7.9s generated audio |
🚀 WebGPU Studio (fp32) ⚡ Mobile WebGPU (fp32) ⚡⚡ Turbo Mode (wasm-q4) ⚡ Fast Mode (wasm-q8) |
1 1 1 1 |
0.84 s 0.79 s 8.21 s 10.83 s |
0.84 s 0.79 s 8.21 s 10.83 s |
9.40× 10.00× 0.96× 0.73× |
0.106 0.100 1.039 1.371 |
128.6 c/s 136.7 c/s 13.2 c/s 10.0 c/s |
Medium (300 chars / 38 words) ~20.6s generated audio |
🚀 WebGPU Studio (fp32) ⚡ Mobile WebGPU (fp32) ⚡⚡ Turbo Mode (wasm-q4) ⚡ Fast Mode (wasm-q8) |
2 3 2 2 |
0.88 s 0.88 s 10.07 s 13.40 s |
1.96 s 2.23 s 21.40 s 28.08 s |
10.92× 9.82× 0.96× 0.72× |
0.092 0.102 1.043 1.383 |
153.1 c/s 134.5 c/s 14.0 c/s 10.7 c/s |
Long (938 chars / 117 words) ~63.2s generated audio |
🚀 WebGPU Studio (fp32) ⚡ Mobile WebGPU (fp32) ⚡⚡ Turbo Mode (wasm-q4) ⚡ Fast Mode (wasm-q8) |
7 10 5 5 |
1.07 s 1.08 s 10.12 s 13.55 s |
6.17 s 7.26 s 66.36 s 87.84 s |
10.71× 9.44× 0.95× 0.72× |
0.093 0.106 1.050 1.392 |
152.0 c/s 129.2 c/s 14.1 c/s 10.7 c/s |
Full Article (1,488 chars / 193 words) ~100.6s generated audio |
🚀 WebGPU Studio (fp32) ⚡ Mobile WebGPU (fp32) ⚡⚡ Turbo Mode (wasm-q4) ⚡ Fast Mode (wasm-q8) |
10 17 8 8 |
1.03 s 1.09 s 10.15 s 13.60 s |
9.53 s 12.03 s 106.35 s 140.32 s |
10.85× 9.09× 0.95× 0.71× |
0.092 0.110 1.057 1.400 |
156.1 c/s 123.7 c/s 14.0 c/s 10.6 c/s |
Adaptive First-Chunk Micro-Chunking for Instant Audio Streaming
A critical insight from our benchmark telemetry is that perceived latency is governed by Time to First Audio (TTFA) rather than total document synthesis time. When real-time audio streaming is enabled (the default in PureTTS), the browser begins playing Chunk 0 as soon as it finishes synthesizing, while Chunks 1 through N continue generating inside the background Web Worker.
To minimize TTFA on CPU/WASM devices, PureTTS implements an asymmetric two-tier chunking algorithm (`chunkText(text, maxChars = 240, firstChunkMaxChars = 90)`): the opening sentence or clause is capped at 90 characters (~6–8 seconds of spoken audio), while subsequent chunks expand to 240 characters for optimal SIMD matrix throughput. This cuts initial wait time by more than 53% on long paragraphs without increasing total generation time.
5. Multilingual Client-Side Grapheme-to-Phoneme (G2P) Architecture Across 10 Languages
While default browser wrappers for Kokoro-82M rely on English-only eSpeak-NG WebAssembly bindings, PureTTS implements a custom, zero-dependency client-side multilingual IPA Grapheme-to-Phoneme (G2P) engine directly inside tts.worker.js. This allows PureTTS to synthesize 33 studio voices across 10 languages and regional dialects with authentic phonological rules and zero external API calls:
- 🇺🇸 / 🇬🇧 American & British English (
en-US, en-GB): Context-aware heteronym resolution, currency/date expansion, and lexical stress assignment across 10 studio voices (Heart, Bella, Sky, Sarah, Adam, Michael, Emma, Isabella, George, Lewis).
- 🇵🇹 European Portuguese (
pt-PT — Lisbon/Coimbra Standard): Models unstressed vowel reduction (a → ɐ, e → ɨ, o → u), coda sibilant palatalization ("chiado": syllable-final s/z → ʃ), cross-word sibilant sandhi (liaison before vowels and voiced consonants), and non-palatalized dental stops (/t/ and /d/ before /i/ and /ɨ/).
- 🇧🇷 Brazilian Portuguese (
pt-BR — São Paulo/Rio Standard): Models dental stop affrication before front high vowels (t → tʃ, d → dʒ before /i/ and unstressed final -e), coda -l vocalization to labiovelar /w/ (e.g., Brasil → bɾazˈiw), and open pretonic vowels.
- 🇪🇸 / 🇲🇽 Castilian & Latin American Spanish (
es-ES, es-419): Full syllabification and penultimate/oxytone stress derivation, differentiating Castilian distinción (c/z → θ before front vowels, s → s) from Latin American seseo (merged /s/) and spirantization of voiced stops (b/d/g → β/ð/ɣ).
- 🇫🇷 French (
fr-FR), 🇮🇹 Italian (it-IT), 🇮🇳 Hindi (hi-IN), 🇯🇵 Japanese (ja-JP), & 🇨🇳 Mandarin Chinese (zh-CN): Dedicated orthographic-to-IPA transducers handling French nasal vowels (ɑ̃, ɛ̃, ɔ̃) and silent final consonants, Italian geminate consonants and palatal digraphs (gli → ʎ, gn → ɲ), Hindi Devanagari schwa-deletion (halant & word-final schwa dropping) + retroflex stops, Japanese Kanji/Hiragana/Katakana mora phonemization, and Mandarin Hanzi/Pinyin tonal IPA mapping.
Experience Local WebGPU & WASM Speech Synthesis
Test Turbo Mode (WASM q4), Fast Mode (WASM q8), and FP32 WebGPU Studio Mode across 33 voices and 10 languages directly in your browser.
⚡ Launch PureTTS Studio