On this page

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-sdk

There 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

TypeScript
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

FeatureSupportNotes
Speech-to-text (transcribe)Yes
Streaming transcripts (listen)YesPartials 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 speechYes
Speech-to-speechNo
Word timingsYes
Speaker labelsNowhisper.cpp doesn't label speakers
InterruptionsYes
Voice list (listVoices)YesThe Piper voices installed in modelDir
pause() and resume()YesPausing 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.

TypeScript
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.

TypeScript
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.

TypeScript
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.

TypeScript
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.

OptionTypeDefaultEnv var
modelstring"base.en"
voicestring"en_US-amy-medium"
modelDirstring~/.cache/voiceai-sdkVOICEAI_MODEL_DIR
whisperPathstring"whisper-cli"
piperPathstring"piper"
threadsnumberHalf 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.

TypeScript
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

  • diarization fails with unsupported.
  • 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

Esc

Loading…

↑↓ navigate openCtrl J preview