Local (Whisper)
Run speech-to-text with whisper.cpp and text-to-speech with Piper on your own machine with local(). No account, and audio never leaves the process host.
local() runs whisper.cpp for speech-to-text and Piper for text-to-speech as child processes. Audio goes over pipes to the binaries, so nothing is sent over the network after the models are downloaded.
Install
npm install voiceai-sdkpnpm add voiceai-sdkyarn add voiceai-sdkbun add voiceai-sdkThere is no key. Install whisper-cli and piper and make sure both are on PATH, or pass their paths as options. npx voiceai-sdk doctor checks both.
Quickstart
import { createSession } from "voiceai-sdk";
import { local } from "voiceai-sdk/local";
await using session = await createSession(local());
const result = await session.transcribe(await Bun.file("meeting.wav").bytes());
console.log(result.ok, result.text);This prints true and the transcript. If the file has no speech, ok is false and reason is "no_speech". await using closes the session when the block ends.
What it supports
| Feature | Support | Notes |
|---|---|---|
Speech-to-text (transcribe) | Yes | |
Streaming transcripts (listen) | Yes | Partials come from re-running the model on a sliding window, so they arrive less often than from cloud providers |
Text-to-speech (speak) | Yes | |
| Streaming speech | Yes | |
| Speech-to-speech | No | |
| Word timings | Yes | |
| Speaker labels | No | whisper.cpp doesn't label speakers |
| Interruptions | Yes | |
Voice list (listVoices) | Yes | The Piper voices installed in modelDir |
pause() and resume() | Yes | Pausing stops feeding audio to the model |
The capability matrix compares these with every other provider.
Stream transcripts
Iterate session.listen to get partial transcripts while someone speaks and a final one when they stop.
import { createSession } from "voiceai-sdk";
import { local } from "voiceai-sdk/local";
await using session = await createSession(local(), { language: "en", sampleRate: 16000 });
for await (const t of session.listen(microphone())) {
if (t.type === "final") console.log(`[${t.startMs}ms] ${t.text}`);
}microphone() stands for any AsyncIterable<Uint8Array> of 16-bit PCM, such as a transport or a file stream.
Speak
Iterate session.speak to send audio as it is produced. Pass an async iterable of text, such as a model's output, and speech starts before the text is finished.
import { createSession } from "voiceai-sdk";
import { local } from "voiceai-sdk/local";
await using session = await createSession(local());
for await (const chunk of session.speak("Let me check that for you.")) {
player.write(chunk.data);
}Voices
listVoices returns the voices you can pass as voice.
import { listVoices } from "voiceai-sdk";
import { local } from "voiceai-sdk/local";
const voices = await listVoices(local());
console.log(voices.filter((v) => v.language.startsWith("en")).map((v) => v.id));Hold a conversation
converse calls your handler for each final transcript and speaks what it returns. Return an async iterable to start speaking before the reply is complete.
import { createSession } from "voiceai-sdk";
import { local } from "voiceai-sdk/local";
await using session = await createSession(local());
session.connect(transport);
await session.converse(async (text, { signal }) => model.stream(text, { signal }));Configuration
Pass options to local(). Options that have an environment variable fall back to it.
| Option | Type | Default | Env var |
|---|---|---|---|
model | string | "base.en" | |
voice | string | "en_US-amy-medium" | |
modelDir | string | ~/.cache/voiceai-sdk | VOICEAI_MODEL_DIR |
whisperPath | string | "whisper-cli" | |
piperPath | string | "piper" | |
threads | number | Half the CPU cores |
Models are downloaded to modelDir on first use. Larger Whisper models are more accurate and slower; which one fits depends on your machine.
Call the API directly
session.native holds the two child processes, so you can read their stderr when a model fails to load.
import { createSession } from "voiceai-sdk";
import { local } from "voiceai-sdk/local";
await using session = await createSession(local());
session.native.whisper.stderr.on("data", (line) => console.error(String(line)));Limitations
diarizationfails withunsupported.- Speech-to-speech isn't available. A session always runs Whisper, then your handler, then Piper.
- Speed depends entirely on your hardware. Small models are the practical choice on CPU-only CI runners.
How it works
- The SDK starts one whisper.cpp process and one Piper process per session and stops both on
close(). - Incoming audio is resampled to 16 kHz mono PCM before it reaches Whisper.
- Piper's raw PCM output is wrapped in the format you ask for with
format.
Next steps
- Lifecycle and cleanup
- Give your agent a voice
- Compare providers: the same features on every other provider