I build Elsewhere, a browser-based ebook reader that reads DRM-free books aloud. The voice is made on the reader's own machine, inside the browser tab, with Piper neural voices running through ONNX Runtime Web on its WebAssembly backend. The text is not sent to a cloud speech API.
This post covers that part: how it is wired, what the thread count turned out to depend on, what the numbers look like, and a WebGPU experiment that stalled my laptop.
How it is wired
ONNX Runtime Web runs the Piper model on its WASM backend.
eSpeak NG turns the text into phonemes first.
One speech worker holds one voice. Switching voice terminates that worker and starts another.
ONNX Runtime starts its own threads inside the worker.
A second, long-lived worker encodes MP3. More on that below.
Threads only exist if the page is cross-origin isolated
ONNX Runtime's WASM backend gets its extra threads from SharedArrayBuffer, and browsers only expose that to cross-origin isolated pages.…