Deepgram
Stream transcripts with word timings and speaker labels, and speak with Aura voices, using deepgram(). No Deepgram package needed.
deepgram() uses Deepgram's live transcription WebSocket for listen, its pre-recorded endpoint for transcribe, and its text-to-speech API for speak. It calls the API directly, so you install no Deepgram package.
Install
npm install voiceai-sdkpnpm add voiceai-sdkyarn add voiceai-sdkbun add voiceai-sdkSet DEEPGRAM_API_KEY on your server, and keep it out of browser bundles.
Quickstart
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession(deepgram());
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
| Feature | Support | Notes |
|---|---|---|
Speech-to-text (transcribe) | Yes | |
Streaming transcripts (listen) | Yes | Partials and finals from the live WebSocket |
Text-to-speech (speak) | Yes | |
| Streaming speech | Yes | |
| Speech-to-speech | No | |
| Word timings | Yes | |
| Speaker labels | Yes | Set diarize: true; speaker is a number as a string |
| Interruptions | Yes | |
Voice list (listVoices) | Yes | |
pause() and resume() | Yes | Sends KeepAlive messages while paused so the socket stays open |
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.
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession(deepgram(), { 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.
Speak
Iterate session.speak to send audio as it is produced. Pass an async iterable of text, such as a model's output, and speech starts before the text is finished.
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession(deepgram());
for await (const chunk of session.speak("Let me check that for you.")) {
player.write(chunk.data);
}Voices
listVoices returns the voices you can pass as voice. The default is aura-2-thalia-en.
import { listVoices } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
const voices = await listVoices(deepgram());
console.log(voices.filter((v) => v.language.startsWith("en")).map((v) => v.id));Hold a conversation
converse calls your handler for each final transcript and speaks what it returns. Return an async iterable to start speaking before the reply is complete.
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession(deepgram());
session.connect(transport);
await session.converse(async (text, { signal }) => model.stream(text, { signal }));Configuration
Pass options to deepgram(). Options that have an environment variable fall back to it.
| Option | Type | Default | Env var |
|---|---|---|---|
apiKey | string | DEEPGRAM_API_KEY | |
model | string | "nova-3" | |
voice | string | "aura-2-thalia-en" | |
diarize | boolean | false | |
smartFormat | boolean | true | |
baseUrl | string | https://api.deepgram.com |
Call the API directly
session.native is the live transcription socket while listen runs.
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
await using session = await createSession(deepgram());
session.native.send(JSON.stringify({ type: "Finalize" }));Limitations
- Speech-to-speech isn't available. Use Deepgram in a pipeline, or with a
conversehandler that calls your model. - Diarization and some models depend on the language. An unsupported pair fails with
unsupportedwhen the session opens.
How it works
- Session options map to query parameters on the live URL, such as
encoding,sample_rate,languageanddiarize. - Turn ends come from Deepgram's
UtteranceEndmessages, and barge-in fromSpeechStarted. speakstreams the text-to-speech response body as chunks, so playback can start before the audio is complete.
Next steps
- Lifecycle and cleanup
- Give your agent a voice
- Compare providers: the same features on every other provider