Mock
Run voice sessions inside your test process with mock(): scripted transcripts, fake audio, and silent speech. No network and no key.
mock() is an in-process provider. It implements every session method and reports every capability as supported, so code written against it runs unchanged on a real provider.
Install
npm install voiceai-sdkpnpm add voiceai-sdkyarn add voiceai-sdkbun add voiceai-sdkThere is nothing else to install and no key to set.
Quickstart
TypeScript
import { createSession } from "voiceai-sdk";
import { mock } from "voiceai-sdk/mock";
await using session = await createSession(mock());
const result = await session.transcribe(mock.audio("cancel my order"));
console.log(result.text);This prints cancel my order. mock.audio(text) returns bytes that mock transcribes back to that text.
Script transcripts
Pass transcripts to control what listen yields. Each string becomes one final transcript, in order, regardless of the audio sent.
TypeScript
import { createSession } from "voiceai-sdk";
import { mock } from "voiceai-sdk/mock";
await using session = await createSession(mock({ transcripts: ["hi", "what are your hours?"] }));
const replies: string[] = [];
await session.converse(async (text) => {
replies.push(text);
return "We open at nine.";
});
console.log(replies);converse resolves when the script runs out, so the test ends on its own.
What it supports
| Feature | Behavior |
|---|---|
transcribe | Returns the text encoded by mock.audio, or ok: false with no_speech for any other bytes |
listen | Yields scripted transcripts, each as one partial then one final |
speak | Returns silent PCM about as long as the text would take to say |
listVoices | Returns two fake voices, mock-a and mock-b |
| Events | Emits speech.start, speech.end, and transcript in the same order as real providers |
| Errors | mock({ fail: "rate_limited" }) makes the next call throw that VoiceError code |
Limitations
- Mock doesn't recognize real speech. Audio not made with
mock.audiocomes back asno_speech. - Timings are simulated. Don't use mock to measure latency.