Skip to content

About

Offline browser text-to-speech SDK with direct MSE/Opus and Web Audio playback, built on n4ze3m/tiny-voca.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Tiny-voca Web SDK

Offline English text-to-speech in the browser. Type text and hear it directly, with sentence-by-sentence inference, MSE/Opus streaming, or direct Web Audio playback. No cloud inference, API key, or runtime npm dependencies.

With gratitude to tiny-voca by Muhammed Nazeem (n4ze3m), and the dizione phonemizer. The model, training work, GGUF reader, JavaScript inference engine, and phonemizer are their work. This repository is an independent community adaptation that makes those capabilities easier to embed and use offline. We have not trained a new model or claimed upstream work as our own.

中文使用说明 · Downloads · Upstream provenance · Verification

Try it

Download tiny-voca-offline.html from the latest release. It contains the model, dictionary, SDK, Worker, and interface in one file. Enter English text, choose a voice, and click 朗读文本. Speech plays directly; there is no generate-file or download step. You can stop the task, change speed and pitch, or switch playback engines.

For the broadest MSE/WebCodecs compatibility, serve the file over localhost or HTTPS. A static server only delivers the page; all inference and encoding remain in the browser. For example, with Python installed:

python3 -m http.server 8000 --directory /path/to/downloads

Open http://localhost:8000/tiny-voca-offline.html. All page resources and license notices are embedded, and its CSP blocks network connections. Internet access is unnecessary after downloading it.

Direct local-file opening depends on browser support for Blob Workers and WebCodecs. File-origin operation has not been verified across browsers. If MSE is unavailable, select Web Audio. See the compatibility notes.

Embed the SDK

Download and extract tiny-voca-web-sdk.zip, or install the release .tgz into your application. The release directory contains the ESM SDK, classic-script SDK, declarations, model, notices, and standalone page. It does not depend on this repository at runtime. The package is distributed through GitHub Releases; it is not currently published to npm.

import { TinyVocaClient } from './tiny-voca.esm.js';

const tts = new TinyVocaClient();
await tts.load(modelFile); // User-selected File, Blob, Uint8Array or ArrayBuffer

// Call from a click handler so the browser can authorize audio playback.
playButton.onclick = async () => {
  await tts.speak('Hello! This works offline.', {
    audio: document.querySelector('audio'),
    transport: 'mse',
    voice: 'F2',
    speed: 0.8,
    onProgress: ({ completed, total }) => console.log(completed, total),
  });
};
stopButton.onclick = () => tts.cancel();
// tts.dispose() when your application no longer needs the model.

Use transport: 'web-audio' to play PCM directly without encoding. The default 'auto' selects MSE when its required APIs are present, otherwise Web Audio. MSE failures are reported rather than silently replaying the text through another engine.

The SDK accepts a model URL only when explicitly supplied by your application. There is no default remote model URL, telemetry, or implicit network fallback. Allow worker-src blob: and media-src blob: in the host CSP.

How playback works

Text → bundled Worker → tiny-voca + dizione → sentence PCM
                                            ├─ WebCodecs Opus → WebM fragments → MSE → audio
                                            └─ Web Audio → audio output

The upstream model produces 24 kHz mono PCM. MSE generally cannot accept raw PCM, so this SDK uses the browser's Opus encoder and a small WebM fragment writer. MediaSource object URLs reference a stream; no WAV file or complete encoded recording is created. Web Audio skips encoding entirely.

Streaming is at sentence/utterance boundaries. The first sentence must finish inference before playback begins; a slower device can pause for buffering. Playback applies backpressure to the Worker and evicts older MSE buffers. This does not make the model itself sample-level autoregressive streaming.

API

Method Purpose
load(source) Load model bytes, File/Blob, or an explicit URL
speak(text, options) Infer and play utterances; resolves when playback ends
cancel() / stop() Stop playback and inference; keep model bytes for recovery
dispose() Release model, Worker and playback resources
synthesize(text, options) Lower-level complete PCM result for custom processing

speak() supports voice, speed, pitchShift, pitchRange, signal, onProgress, onChunk, onPlayback, audio, and transport. It returns duration, sample rate, utterance count, elapsed inference/queue time, and actual transport. Concurrent jobs on one client are rejected. Stopping terminates the Worker, so the next call has initialization overhead.

The optional legacy encodeWav() / toWav() helpers remain for applications that explicitly need export; direct speech and the standalone interface do not use them. See the TypeScript declarations and detailed guide.

Compatibility

  • Base SDK: modern ES2022 browser, Web Worker, Blob Worker, and DecompressionStream.
  • Web Audio: AudioContext support.
  • MSE: WebM/Opus SourceBuffer support, WebCodecs AudioEncoder/AudioData, and Opus encoding support. WebCodecs normally requires a secure context such as HTTPS or localhost.
  • Current model: English only, F2/M2 American English voices, 4,537,291 parameters. Bundled GGUF is 7,988,384 bytes; working memory is substantially larger.
  • Chromium localhost MSE playback, cancellation, replay, pause/resume, and Web Audio have been checked. Other browsers and file origins are not universally verified.
  • Very long utterances or slow speech can exceed upstream frame limits. Shorter sentences are more reliable.

Build from source

Node.js 22 or later is needed for development only. Everything needed for inference is committed: pinned upstream JavaScript under vendor/ and the checked model under models/. No submodules, external checkout, or build-time model download is required.

git clone https://github.com/feworker/tiny-voca-web-sdk.git
cd tiny-voca-web-sdk
npm ci
npm run check
npm run release:assets

dist/ contains the standalone SDK and page. releases/ contains release assets and SHA-256 checksums. Dependency installation requires network access once; the build and model tests can then run offline. React/Radix/Tailwind are used by the interface; the standalone SDK has no third-party runtime library dependencies.

Open-source lineage and contribution

The vendored inference and phonemizer sources are byte-identical to upstream commit 61b258fd2f2aeaad27818fcc6f097674cd609108. The model is pinned to Hugging Face revision 5fe06641d0afecb3c04bc9faca2cf64d9b2b1600. npm run verify:upstream checks every vendored file and the model against UPSTREAM.json.

Our additions are the SDK lifecycle, cancellable Worker protocol, streaming playback, browser integration types, offline interface, packaging, and tests. Improvements to model quality or the core phonemizer should be discussed with the relevant upstream project; integration and playback improvements belong here. Please acknowledge original authors when building on this work.

Contributions, reproducible bug reports, compatibility findings, and documentation improvements are welcome. Read CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.

License and thanks

Apache-2.0 for the SDK adaptation, upstream code, and model. Preserve LICENSE, NOTICE, model/dictionary licenses, and bundled UI dependency notices when redistributing. Third-party dictionaries and UI packages retain their own licenses.

Thank you to tiny-voca and dizione for sharing not only runnable code, but the model, training recipe, and data. This project aims to extend that openness through readable source, reproducible builds, transparent attribution, and freely reusable offline tooling. It is not an official upstream release or an endorsement by its authors.

About

Offline browser text-to-speech SDK with direct MSE/Opus and Web Audio playback, built on n4ze3m/tiny-voca.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages