voice-sdk
Guides

Transcription

Convert a complete recording to a transcript with transcribe().

const result = await voice.transcribe({
  audio: { url: "https://example.com/clip.wav" },
  timestamps: "segment",
  diarize: true,
});

Audio input

The audio field accepts several shapes:

type AudioSource =
  | Uint8Array
  | ArrayBuffer
  | Blob
  | ReadableStream<Uint8Array>
  | AsyncIterable<Uint8Array>
  | { url: string };

Passing { url } lets providers that support remote fetching download the file directly, without routing the bytes through your process.

To read any of these into a single buffer, use the collectAudio helper:

import { collectAudio } from "@swungstudent/voice";

const bytes = await collectAudio(source);

Options

FieldTypeDescription
audioAudioSourceRequired
formatAudioFormatRequired for headerless PCM
modelstringProvider model id
languagestringLanguage hint
timestampsfalse | "word" | "segment" | "character"Timing granularity
diarizebooleanAttribute words and segments to speakers
speakerCountnumberExpected number of speakers, where the provider uses it
keytermsstring[]Terms to bias recognition towards
promptstringFree-text context, where the provider supports it

Headerless audio needs a format

Container formats such as WAV and MP3 declare their own encoding and sample rate. Raw PCM does not, and the SDK does not inspect the bytes, so pass format explicitly when the input is headerless.

Result

interface TranscriptResult {
  text: string;
  language?: string;
  languageConfidence?: number;
  duration?: number;
  confidence?: number;
  words?: TranscriptWord[];
  segments?: TranscriptSegment[];
  requestId?: string;
  raw?: unknown;
}

text is always present. words and segments are populated when timestamps requests them, and each entry carries start and end in seconds. When diarize is enabled, entries also carry a speaker label.

for (const segment of result.segments ?? []) {
  console.log(`[${segment.start.toFixed(2)}] ${segment.speaker}: ${segment.text}`);
}

words and segments are optional and are omitted when the provider reports nothing, so an empty array and a missing array mean different things.

On this page