On this page

Speechmatics

Transcribe live and recorded audio with speechmatics(): real-time partials, speaker labels, and custom vocabulary. No Speechmatics package needed.

speechmatics() is a speech-to-text provider. listen uses the real-time WebSocket API and transcribe submits a batch job and waits for it.

Install

npm install voiceai-sdk

Set SPEECHMATICS_API_KEY on your server, and keep it out of browser bundles.

Quickstart

TypeScript
import { createSession } from "voiceai-sdk";
import { speechmatics } from "voiceai-sdk/speechmatics";

await using session = await createSession(speechmatics());
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)Yes
Text-to-speech (speak)NoUse a pipeline with a text-to-speech provider
Streaming speechNo
Speech-to-speechNo
Word timingsYes
Speaker labelsYesSet diarization: "speaker"
InterruptionsNo
Voice list (listVoices)No
pause() and resume()No

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 { speechmatics } from "voiceai-sdk/speechmatics";

await using session = await createSession(speechmatics(), { 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.

Use it in a pipeline

Speechmatics only transcribes. For a conversation, combine it with a provider that speaks.

TypeScript
import { createSession } from "voiceai-sdk";
import { speechmatics } from "voiceai-sdk/speechmatics";
import { elevenlabs } from "voiceai-sdk/elevenlabs";

await using session = await createSession({ stt: speechmatics(), tts: elevenlabs({ voice: process.env.VOICE_ID }) });
await session.converse(async (text) => answer(text));

Configuration

Pass options to speechmatics(). Options that have an environment variable fall back to it.

OptionTypeDefaultEnv var
apiKeystringSPEECHMATICS_API_KEY
operatingPoint"standard" | "enhanced""enhanced"
diarization"none" | "speaker""none"
vocabularystring[][]

Call the API directly

session.native is the real-time socket while listen runs.

TypeScript
import { createSession } from "voiceai-sdk";
import { speechmatics } from "voiceai-sdk/speechmatics";

await using session = await createSession(speechmatics());
session.native.send(JSON.stringify({ message: "EndOfStream", last_seq_no: 0 }));

Limitations

  • speak fails with unsupported. Pair Speechmatics with a text-to-speech provider.

How it works

  • AddPartialTranscript messages become partial events and AddTranscript messages become final events.
  • vocabulary is sent as additional vocabulary in the transcription config.

Next steps

Was this page helpful?

Esc

Loading…

↑↓ navigate openCtrl J preview