Most modern text-to-speech tools make a frustrating trade-off: you either settle for the robotic built-in voices from the Windows 98 era, or you stream every sentence you read to a paid cloud API like ElevenLabs or OpenAI.
Streaming your personal documents, private codebases, and research papers to a remote server just to have them read aloud never sat right with me. When the open-weight Kokoro-82M model arrived with human-level voice quality in an architecture compact enough for consumer hardware, I decided to build a complete, zero-telemetry reading suite around it: AlVox.
The project consists of two coordinated tools:
- A Manifest V3 Chrome Extension that parses web pages and PDFs in-browser via WebGPU and WASM, synchronizing DOM-level word highlights as audio plays.
- A Windows Desktop Companion (Electron + C# UI Automation) that works system-wide across any application (Notepad, VS Code, Word, native PDFs) with a click-through screen overlay and optional local CUDA GPU acceleration.
Here is the engineering breakdown of how it works, the architectural hurdles I ran into, and why certain technologies failed along the way.
1. System Architecture
2. Part 1: The Chrome Extension (In-Browser WebGPU)
To make an extension that runs entirely client-side without a mandatory background server, the neural network needs to execute inside the browser engine itself.
The Manifest V3 Audio Problem
Under Chrome's Manifest V3, background service workers do not have access to the DOM or the AudioContext API, and they get terminated by the browser when idle. To sustain audio playback and run heavy WebGPU pipelines without blocking user tabs, I routed the synthesis engine through an Offscreen Document.
When text is selected on a page:
- The content script breaks the paragraph into sentences and dispatches an execution request.
- The offscreen document receives the payload and runs Kokoro-82M using
@huggingface/transformerscompiled againstonnxruntime-web. - If WebGPU is supported by the user's browser, the model runs directly on the GPU in 32-bit floating point; if WebGPU is unavailable or fails, it falls back cleanly to 8-bit quantized WASM SIMD execution across CPU threads.
- Synthesized audio chunks are converted to local
BlobURLs, cached in memory, and played through an audio pipeline that sends precise millisecond playback timestamps back to the content script.
DOM Word Highlighting
Reading along with spoken text requires synchronization down to the individual token. Because spoken normalizers expand symbols (e.g., "$15" becomes "fifteen dollars", or chemical formulas like "H₂O" expand into spoken syllables), mapping audio time back to raw character offsets in the DOM can easily drift.
To solve this, I built a two-way text normalizer that generates character alignment index maps between the original visual DOM string and the synthesized phonetic string. As audio plays, the extension maps the current timestamp to the exact sentence range and wraps the active word in a highlight span without breaking existing page styling or layout.
3. Part 2: The Desktop Companion & The Screen Highlight Challenge
A browser extension is confined to its sandbox: it cannot read your desktop IDE, cannot hook global hotkeys reliably outside the active tab, and cannot see text inside native Windows software.
The desktop app solves this, but presenting speech across any arbitrary Windows program introduced unexpected low-level challenges.
Windows UI Automation via C#
To highlight words on screen over apps like Visual Studio Code, Word, or native PDF readers, the app needs the exact physical screen pixel coordinates of the words being spoken.
Node.js native add-ons for Windows accessibility APIs are notorious for thread affinity crashes because Windows UI Automation (UIA) relies heavily on Single-Threaded Apartment (STA) COM models.
Instead of embedding fragile C++ COM wrappers directly into Electron's Node runtime, I wrote a dedicated C# helper (uia-helper.cs) that compiles on the fly using the Windows built-in .NET compiler (csc.exe). The helper runs as a separate background worker communicating over standard I/O via a structured JSON-lines protocol:
- It inspects
AutomationElement.FocusedElement. - Queries
TextPatternorValuePatternto extract selected text and bounding rectangles (GetBoundingRectangles()). - Translates logical text indices into physical screen bounding boxes and passes them back to Electron.
Electron then draws sentence and word highlight bounding boxes onto a borderless, click-through, hardware-accelerated transparent overlay (WS_EX_TRANSPARENT | WS_EX_LAYERED) pinned above the target window.
private static List<Dictionary<string, object>> ConvertBoundingRects(Rect[] rawRects)
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
if (rawRects == null) return list;
for (int i = 0; i < rawRects.Length; i++)
{
Rect rr = rawRects[i];
if (rr.IsEmpty) continue;
if (double.IsNaN(rr.X) || double.IsNaN(rr.Y) || double.IsNaN(rr.Width) || double.IsNaN(rr.Height)) continue;
if (double.IsInfinity(rr.X) || double.IsInfinity(rr.Y) || double.IsInfinity(rr.Width) || double.IsInfinity(rr.Height)) continue;
if (rr.Width <= 0.5 || rr.Height <= 0.5) continue;
int x = (int)Math.Round(rr.X);
int y = (int)Math.Round(rr.Y);
int w = Math.Max(1, (int)Math.Round(rr.Width));
int h = Math.Max(1, (int)Math.Round(rr.Height));
Dictionary<string, object> d = new Dictionary<string, object>();
d["x"] = x;
d["y"] = y;
d["w"] = w;
d["h"] = h;
list.Add(d);
}
return list;
}4. Engineering Failures & Roadblocks
A project like this rarely goes smoothly on the first try. A few notable dead ends:
Why DirectML Failed on Kokoro-82M
I initially wanted to compile the desktop engine against DirectML (DmlExecutionProvider). DirectML is built into Windows 10/11 and runs across NVIDIA, AMD, and Intel GPUs without requiring proprietary CUDA libraries.
The session initialized without errors, but the moment inference executed, the DirectML runtime crashed:
Non-zero status code returned while running ConvTranspose node.
Name: '/encoder/F0.1/pool/ConvTranspose'
Status Message: DmlExecutionProvider ... Exception(2) tid(b0f0) 80070057 The parameter is incorrect.
Kokoro's acoustic encoder uses depthwise 1D transposed convolutions (ConvTranspose with group > 1) for pitch and F0 upsampling. DirectML's ONNX implementation rejects grouped transposed convolutions on 1D tensor shapes.
Because rewriting the model's computation graph would alter the weights and voice reproduction, DirectML was off the table. I pivoted to packaging an isolated NVIDIA CUDA 13 + cuDNN 9 engine with an automatic, validated fallback to multi-threaded native C++ CPU inference.
sess_opts = ort.SessionOptions()
sess_opts.intra_op_num_threads = max(1, (os.cpu_count() or 4) // 2)
sess_opts.inter_op_num_threads = 1
avail_providers = ort.get_available_providers()
if "CUDAExecutionProvider" in avail_providers:
candidate_provider_lists = [
["CUDAExecutionProvider", "CPUExecutionProvider"],
["CPUExecutionProvider"],
]
else:
candidate_provider_lists = [["CPUExecutionProvider"]]
sess = None
kokoro = None
for candidate in candidate_provider_lists:
try:
candidate_sess = ort.InferenceSession(model_path, sess_options=sess_opts, providers=candidate)
candidate_kokoro = kokoro_onnx.Kokoro.from_session(candidate_sess, voices_path)
candidate_kokoro.create("Ready.", voice="af_heart", speed=1.0)
sess = candidate_sess
kokoro = candidate_kokoro
break
except Exception as e:
print(f"[ONNX Runtime] Provider init notice ({candidate}): {e}")
if kokoro is None:
sess = ort.InferenceSession(model_path, sess_options=sess_opts, providers=["CPUExecutionProvider"])
kokoro = kokoro_onnx.Kokoro.from_session(sess, voices_path)
kokoro.create("Ready.", voice="af_heart", speed=1.0)
active_providers = sess.get_providers()
print(f"[Kokoro Server] Loaded ONNX model from {model_path} with providers: {active_providers}")The Double-Tap Ctrl+C Trigger
Originally, I implemented Alt + Select to instantly read highlighted text. While it worked in simple text editors, browsers and Electron apps capture the Alt key to trigger window menu bars (e.g., File, Edit, View), causing focus to jump away from the text selection.
I replaced this with Double-Tap Ctrl+C: tap Ctrl+C twice within 500ms anywhere in Windows, and AlVox immediately captures the clipboard, queries UIA for screen coordinates, and begins playback. Alongside this, I added a centered floating pill that appears above selected text for mouse-driven reading.
Packaging a Python GPU Engine inside an Electron Installer
Users shouldn't have to install Python, configure virtual environments, or manage pip dependencies just to run a desktop app.
I created an automated build pipeline using PyInstaller to bundle the entire Python runtime, FastAPI server, Kokoro ONNX bindings, and 13 specific NVIDIA CUDA 13/cuDNN 9 dynamic link libraries into a standalone executable (alvox-server.exe).
Electron's packaging config unpacks this executable alongside native Node modules (uiohook-napi) using asarUnpack, while storing downloaded model weights in %LOCALAPPDATA%\AlVox\models.
def _preload_cuda_runtime():
exe_dir, internal_dir = _get_base_dirs()
candidate_dirs = [
os.path.join(internal_dir, "cuda_dlls"),
os.path.join(exe_dir, "cuda_dlls"),
os.path.join(exe_dir, "_internal", "cuda_dlls"),
]
ort_parent = os.path.dirname(os.path.dirname(os.path.realpath(ort.__file__)))
nvidia_pkg_dir = os.path.join(ort_parent, "nvidia")
if os.path.isdir(nvidia_pkg_dir):
for root, _, files in os.walk(nvidia_pkg_dir):
if any(f.lower().endswith(".dll") for f in files):
candidate_dirs.append(root)
cuda_dll_dir = None
for d in candidate_dirs:
if os.path.isdir(d):
if hasattr(os, "add_dll_directory"):
try:
os.add_dll_directory(d)
except Exception as e:
print(f"[ONNX Runtime] add_dll_directory notice ({d}): {e}")
if d not in os.environ.get("PATH", ""):
os.environ["PATH"] = d + os.pathsep + os.environ.get("PATH", "")
if cuda_dll_dir is None and (
os.path.isfile(os.path.join(d, "cudart64_13.dll"))
or os.path.isfile(os.path.join(d, "cudnn64_9.dll"))
):
cuda_dll_dir = d
if hasattr(ort, "preload_dlls"):
try:
if cuda_dll_dir:
ort.preload_dlls(directory=cuda_dll_dir)
else:
ort.preload_dlls()
except Exception as e:
print(f"[ONNX Runtime] preload_dlls notice: {e}")Benchmark Results
Benchmarking Kokoro-82M on an NVIDIA GeForce RTX 2070 desktop setup on a representative sentence producing 4.63 seconds of 24kHz audio (af_heart voice, 1.0x speed):
| Execution Backend | Cold Session Init | First Sentence (Warmup) | Subsequent Synthesis | Real-Time Factor (RTF) |
|---|---|---|---|---|
| CUDA GPU (RTX 2070) | 3.05s | 0.86s | 0.59s | ~7.8x faster than real-time |
| C++ Native CPU (Multi-threaded) | 1.29s | 1.86s | 1.39s | ~3.3x faster than real-time |
| In-Browser WebGPU (fp32) | 2.10s | 1.15s | 0.82s | ~5.6x faster than real-time |
| In-Browser WASM SIMD (q8) | 1.45s | 2.60s | 1.95s | ~2.4x faster than real-time |
Because Kokoro synthesizes each sentence ahead of time into an in-memory queue while the previous sentence is already playing through your speakers, any backend with a synthesis time under the audio duration results in gapless playback with zero buffering delay.
5. Current State & Open Source Release
AlVox is published as free software under the GNU General Public License v3.0 (GPL-3.0).
- Source Code: github.com/TheChos3nOne/AlVox
- Downloads: Standalone Windows installers (
.exe), portable builds, and Chrome Extension packages (.zip) are available on the GitHub Releases page.
Building this proved to me that modern open-source speech models are fast and compact enough to eliminate reliance on external cloud services. With WebGPU in the browser and native hardware acceleration on the desktop, you can have high-fidelity voice reading that never leaves your machine.
