On this page

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

There 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

FeatureBehavior
transcribeReturns the text encoded by mock.audio, or ok: false with no_speech for any other bytes
listenYields scripted transcripts, each as one partial then one final
speakReturns silent PCM about as long as the text would take to say
listVoicesReturns two fake voices, mock-a and mock-b
EventsEmits speech.start, speech.end, and transcript in the same order as real providers
Errorsmock({ fail: "rate_limited" }) makes the next call throw that VoiceError code

Limitations

  • Mock doesn't recognize real speech. Audio not made with mock.audio comes back as no_speech.
  • Timings are simulated. Don't use mock to measure latency.

Next steps

Was this page helpful?

Esc

Loading…

↑↓ navigate openCtrl J preview