Menu

Running Piper text-to-speech in the browser with WebAssembly
📰

Running Piper text-to-speech in the browser with WebAssembly

DEV Community: typescript·Ishaan Verma·about 10 hours ago
#6HYS0tWn
#devtotypescript#devto#dev#voice#times
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.