On this page

Gladia

Transcribe live and recorded audio with gladia(): streaming partials, word timings, speaker labels, and language detection. No Gladia package needed.

gladia() is a speech-to-text provider. listen starts a live session over Gladia's WebSocket API and transcribe uses its pre-recorded endpoint.

Install

npm install voiceai-sdk

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

Quickstart

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

await using session = await createSession(gladia());
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 labelsYesBatch transcripts only
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 { gladia } from "voiceai-sdk/gladia";

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

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

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

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

Configuration

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

OptionTypeDefaultEnv var
apiKeystringGLADIA_API_KEY
detectLanguagebooleanfalse
diarizationbooleanfalse

Call the API directly

session.native is the live session socket while listen runs.

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

await using session = await createSession(gladia());
session.native.send(JSON.stringify({ type: "stop_recording" }));

Limitations

  • speak fails with unsupported. Pair Gladia with a text-to-speech provider.
  • With detectLanguage, the language session option is ignored only if you leave it unset. Setting both fails with unsupported.

How it works

  • listen first creates a live session over HTTP, then connects to the WebSocket URL it returns.
  • Detected languages are reported on each final result's language field.

Next steps

Was this page helpful?

Esc

Loading…

↑↓ navigate openCtrl J preview