On this page

How it works

What happens between your code and the provider: a session, an adapter, and the provider's own API, all running on your server.

VoiceAI SDK is a library, not a service. When you open a session, it uses the adapter for the provider you chose, and the adapter talks to that provider's API with your key. This page follows a call through those layers.

Three layers

Text
your server ─────────────────────────────────────────────
  your code       createSession(), listen(), speak()
      │
      ▼
  Session         same methods and results on every provider
      │
      ▼
  adapter         voiceai-sdk/deepgram
─────────────────────────────────────────────────────────
      │           HTTP or WebSocket, with your key
      ▼
  provider API    Deepgram
  • Session. The object you hold. It has the same methods on every provider: transcribe, listen, speak, say, converse, connect and close.
  • Adapter. The code behind a provider subpath such as voiceai-sdk/deepgram. It translates between the session API and one provider.
  • Provider API. The provider's own HTTP or WebSocket API, or the vendor SDK for Google Cloud, Azure and AWS.

Each provider factory, such as deepgram() or elevenlabs(), returns an adapter. You pass it to createSession, and the session uses it for every call.

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

await using session = await createSession(deepgram(), { language: "en" });

console.log(session.provider, session.capabilities);

It runs on your server

Every layer runs in your own server process. Most adapters call the provider's HTTP or WebSocket API directly. google(), azure() and aws() call the vendor's SDK, which you install next to voiceai-sdk. local() runs whisper.cpp and Piper on the same machine, and mock() never leaves your process.

Adapters read provider keys from environment variables such as DEEPGRAM_API_KEY. That is why sessions belong on the server: a browser has no safe place for a key. Audio from a browser or a phone reaches your server through a transport, and the session takes it from there.

Bash
# .env on your server
DEEPGRAM_API_KEY=dg_...

What an adapter does

An adapter is a thin translation layer. It does four jobs:

JobWhat it means for you
Maps optionslanguage, voice, sampleRate, encoding and vad become the provider's own request parameters. You never write provider-specific option names.
Normalizes resultsTranscripts come back as { type, text, startMs, endMs, speaker? } and audio as { data, ms } chunks, whatever shape the provider sent.
Declares capabilitiessession.capabilities says what this provider can do, such as streamingStt, wordTimings or diarization.
Fails unsupportedIf the provider can't honour an option, createSession throws VoiceError with code unsupported. The option is never dropped silently.

AssemblyAI only transcribes, so asking it for a voice fails before any audio is sent:

TypeScript
import { createSession, VoiceError } from "voiceai-sdk";
import { assemblyai } from "voiceai-sdk/assemblyai";

try {
  await using session = await createSession(assemblyai(), { voice: "aria" });
} catch (err) {
  if (err instanceof VoiceError) console.log(err.code, err.provider); // "unsupported" "assemblyai"
}

Pipelines

A pipeline is an object with an stt provider and a tts provider. The session sends speech-to-text work to the first and text-to-speech work to the second, each through its own adapter.

TypeScript
import { readFile } from "node:fs/promises";
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
import { elevenlabs } from "voiceai-sdk/elevenlabs";

await using session = await createSession({ stt: deepgram(), tts: elevenlabs() });

const heard = await session.transcribe(await readFile("question.wav")); // Deepgram
const reply = await session.speak(`You asked: ${heard.text}`); // ElevenLabs

transcribe and listen go to Deepgram. speak, say and the spoken half of converse go to ElevenLabs. session.capabilities describes what the pair supports together.

A speech-to-speech provider such as openai() does both halves in one connection, so there is one adapter and one provider API. Choose a provider compares the two setups.

Nothing in between

There is no VoiceAI service in the path. The adapter opens its own connection to the provider with your credentials, so audio and transcripts travel only between your server and the provider you chose. The SDK doesn't store either. What the provider keeps, and for how long, depends on the provider. See Security.

Because the connection is yours, you can reach it. session.native is the provider's own client or socket, and session.ext.<provider> holds helpers specific to that provider. Use them for anything the session API doesn't cover.

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

await using session = await createSession(deepgram());

const client = session.native; // Deepgram's own client or socket

Next steps

Esc

Loading…

↑↓ navigate openCtrl J preview