Speech to text
and back.
voxxy is a TypeScript library that runs speech recognition and synthesis on the device using web APIs.
See code examplesTry voice chat
Enable voice to download the English models.
Speech engines
Microphone audio stays on your device. Online playback sends reply text to the browser’s speech service. Chat text may be sent to for replies.
Choose your speech providers
Pick one provider for recognition and another for synthesis. Your app asks for download consent and decides how to show progress and playback controls.
-
Audio in
Speech to text
Pass microphone audio to the recognition provider and get a transcript.
-
Text in and out
Your application
Use the transcript in a form, run a command or send it to an LLM.
-
Audio out
Text to speech
Speak a finished response or play sentences as text streams in.
Quickstart
Run either example here, or copy it as index.html in a Vite project.
npm install voxxy v0.1.2
Run locally
- For a new project, run
npm init -yandnpm install -D vite@8. - Run
npm install voxxy. - Save the copied snippet as
index.html, runnpx vite, and open the localhost URL.
For a preview build, download voxxy.tgz and run npm install ./voxxy.tgz.
Write a speech adapter
Implement SttAdapter or TtsAdapter from voxxy to run your own speech engine in a worker.
Host the adapter with serveStt or serveTts from voxxy/serve. In your app, create a provider with workerStt or workerTts and pass it to voice.select().
For an engine that handles recording or playback itself, implement SttProvider or TtsProvider from voxxy and select it directly.
Worker adapter interfaces
import type { AdapterLoadContext } from "voxxy";
interface SttAdapter {
readonly id: string;
load(context?: AdapterLoadContext): Promise<void>;
transcribe(
pcm16k: Float32Array,
signal?: AbortSignal,
): Promise<string>;
dispose(): Promise<void>;
}
interface TtsAdapter {
readonly id: string;
load(context?: AdapterLoadContext): Promise<void>;
synthesize(
text: string,
signal?: AbortSignal,
): Promise<{ pcm: Float32Array; sampleRate: number }>;
dispose(): Promise<void>;
}
Recognition receives mono 16 kHz PCM. Synthesis returns PCM and its sample rate. Use the supplied abort signal to cancel work.