@sidevoice/engine
v0.15.0
Published
Sidevoice engine for the web: local voice models in the browser, as WebAssembly.
Maintainers
Readme
@sidevoice/engine
The Sidevoice engine for the web: it knows a catalogue of local voice models, works
out which build of each fits the device, and takes the chosen one from absent to ready. This package is its
WebAssembly build (wasm-bindgen --target web).
import init, { WebEngine } from "@sidevoice/engine";
await init();
// The page says what it has; the engine keeps its files in OPFS and downloads them with fetch.
const engine = await WebEngine.create({
async capabilities() {
return { os: "web", arch: "wasm32", accelerators: navigator.gpu ? ["webgpu", "wasm"] : ["wasm"] };
},
credential(provider) { // optional: a remote provider's key ("openai", "elevenlabs"), or null
return localStorage.getItem(`key:${provider}`);
},
});
const local = engine.localCatalog();
const models = await local.models(); // LocalModelInfo[]: each with its builds ranked, whether it is installed, lastUsedAt
const whisper = await engine.load("whisper-small", undefined, (progress) => show(progress), abort.signal);
const stt = whisper.asStt();
const text = await stt.transcribe(samples, 48000, "es"); // any rate: the engine resamples
const kokoro = await engine.load("kokoro-82m-v1.0");
const { samples: speech, sampleRate } = await kokoro.asTts().speak("Hola", "ef_dora", "es");
const silero = await engine.load("silero-vad");
const mic = await silero.asVad().stream({ minSilenceMs: 500 }); // a state of its own; mic.sampleRate is 16000
const { frames, events } = await mic.accept(pcm); // events: { type: "speech-start", at } | { type: "speech-end", start, end }
const smartTurn = await engine.load("smart-turn-v3.2");
const p = await smartTurn.asEndOfTurn().probability(turnSoFar, 48000); // the probability the speaker has finished
stt.free(); // the model leaves memory once its LocalModel and the Stt and Tts it handed out are freed
whisper.free(); // (or collected)
// Every catalogue alike: "local", then each remote provider, listed live with the app's keys, kept in memory only.
for (const catalog of engine.catalogs()) {
const { reason, stale, detail } = await catalog.status(); // reason absent when current
const speakers = await catalog.models("tts"); // each { id, capabilities, languages, voices, speed? }, and its own fields
}
const elevenlabs = engine.remoteCatalog("elevenlabs");
await elevenlabs.refresh(); // read again now
const scribe = await elevenlabs.load("scribe_v2"); // a RemoteModel: the same asStt(), asTts()
const heard = await scribe.asStt().transcribe(samples, 48000, "es");Every promise rejects with an Error carrying the engine's stable code and its params, for the page to
translate. Models run through transformers.js, a dependency of
this package that the engine imports only when a model is loaded; Kokoro's phonemes come from eSpeak NG (the
espeak-ng package), under the GPL-3.0-or-later: see THIRD_PARTY_NOTICES.md.
Source, documentation and issues: https://github.com/sidevoice/sidevoice-engine
Apache-2.0. Sidevoice is a trademark; see TRADEMARKS.md in the repository.
