Getting started
Install the packages, add the Vite plugin, and speak your first sentence.
Install
Add the engines you need. Each one pulls in @kucukkanat/speech-core and @kucukkanat/speech-audio.
bun add @kucukkanat/tts @kucukkanat/stt @kucukkanat/voices # or npm i / pnpm add
bun add @kucukkanat/speech-react # optional: React hooksConfigure your bundler
The models run in Web Workers that ship inside the packages. Vite, esbuild and Bun take one plugin (webpack 5, Next.js and Rspack need none; see Bundlers for each setup). With Vite:
// vite.config.ts
import { speechSdk } from "@kucukkanat/speech-core/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [react(), speechSdk({ isolation: true })],
});Speak
import { createTTS } from "@kucukkanat/tts";
const tts = createTTS();
// Call from a click handler the first time: browsers only allow audio after a user gesture.
document.querySelector("button")?.addEventListener("click", async () => {
await tts.speak("Hello! This voice is generated entirely inside your browser.");
});Listen
import { createSTT } from "@kucukkanat/stt";
const stt = createSTT();
const session = stt.listen(); // loads the model on first use, then opens the microphone
session.on("update", ({ committed, partial }) => console.log(committed, partial));
setTimeout(() => session.stop(), 10_000);
console.log("Final:", (await session).text);Browser requirements
| Needs | |
|---|---|
| Text-to-speech | WebGPU (recent Chrome/Edge, Safari 26+). Without it, load() rejects with webgpu-required. |
| Speech-to-text | WebGPU or WASM with Moonshine; WebGPU with Voxtral Realtime. |
| Microphone | A secure context: HTTPS or localhost. |
| Cross-origin isolation | Optional. Makes the WASM fallback multi-threaded. |
Check up front instead of waiting for an error:
import { detectCapabilities } from "@kucukkanat/speech-core";
const caps = await detectCapabilities(); // never throws; everything is false during SSR
if (!caps.webgpu) console.warn("No WebGPU: text-to-speech won't run here.");
if (!caps.secureContext) console.warn("The microphone needs HTTPS or localhost.");