Skip to content
// EFFECT DAYS 2026

TranscriptionModel unstable

Defines the provider-neutral service for speech-to-text.

A TranscriptionModel turns a finished recording into text with transcribe, and a live audio stream into segment updates with transcribeLive. Failures are reported as AiError values. A language hint is the only portable option; vocabulary hints, prompts, and other settings belong to each provider. transcribeLiveBuffered wraps the live operation so audio survives a dropped connection.

19 exports Since v4.1.5 Source

Constructors

make

unstable
Since v4.1.5

Creates a TranscriptionModel service from a provider implementation.

Details

A live session lasts as long as the stream transcribeLive returns. When audio ends, the provider must flush, emit the remaining final updates, and complete the stream. Interrupting the stream must close the session. A dropped connection must fail the stream instead of reconnecting.

Gotchas

Without a provider transcribeLive, the service's transcribeLive fails with AiError.InvalidUserInputError.

See

Signature

declare function make(params: {
readonly transcribe: (options: TranscribeOptions) => Effect<ProviderResponse, AiError>;
readonly transcribeLive?: <E, R>(options: TranscribeLiveOptions<E, R>) => Stream<SegmentUpdate, AiError | E, R>;
}): Effect<TranscriptionModel>

Models

AudioDiscarded

interface unstable
Since v4.1.5

Notice that transcribeLiveBuffered dropped buffered audio to stay within its maximum duration. The dropped audio cannot be sent again after a reconnect.

Signature

interface AudioDiscarded {
readonly _tag: "AudioDiscarded";
readonly duration: Duration;
}

AudioFormat

interface unstable
Since v4.1.5

The format of a raw audio stream.

Details

"pcm16" is signed 16-bit little-endian PCM. "mulaw" and "alaw" are 8-bit G.711. Channels are interleaved.

Signature

interface AudioFormat {
readonly channels: number;
readonly encoding: "pcm16" | "mulaw" | "alaw";
readonly sampleRate: number;
}

Example Declaring 24 kHz mono PCM16

import type { TranscriptionModel } from "effect/ai"
const format: TranscriptionModel.AudioFormat = {
encoding: "pcm16",
sampleRate: 24000,
channels: 1
}

ProviderResponse

interface unstable
Since v4.1.5

Provider response for a transcribed recording. usage defaults to no reported values and metadata defaults to {}.

Signature

interface ProviderResponse {
readonly duration?: Duration;
readonly language?: string;
readonly metadata?: TranscribeResponseMetadata;
readonly segments?: readonly Array<Segment>;
readonly text: string;
readonly usage?: {
readonly audioDuration?: Duration;
readonly inputTokens?: number;
readonly outputTokens?: number;
};
}

Recording

interface unstable
Since v4.1.5

A finished audio recording. data is a base64 string, a byte array, or a URL.

Gotchas

Providers do not accept every representation. A provider that cannot take the one given fails with AiError.InvalidUserInputError.

Signature

interface Recording {
readonly data: string | Uint8Array<ArrayBufferLike> | URL;
readonly fileName?: string;
readonly mediaType: string;
}

Segment

interface unstable
Since v4.1.5

A timestamped part of a transcribed recording. Times are offsets from the start of the audio.

Signature

interface Segment {
readonly end: Duration;
readonly start: Duration;
readonly text: string;
}

SegmentUpdate

interface unstable
Since v4.1.5

The current state of one segment of a live transcript.

Details

text is the whole text of the segment so far, not an addition to earlier updates. Keep one entry for each id and replace it on every update. A segment receives no more updates once final is true.

start and end are offsets from the start of the audio and are set only when the provider reports them.

Signature

interface SegmentUpdate {
readonly _tag: "SegmentUpdate";
readonly end?: Duration;
readonly final: boolean;
readonly id: string;
readonly start?: Duration;
readonly text: string;
}

TranscribeResponse

interface unstable
Since v4.1.5

The transcript of a recording with usage and response metadata.

See

Signature

interface TranscribeResponse {
readonly duration?: Duration;
readonly language?: string;
readonly metadata: TranscribeResponseMetadata;
readonly segments?: readonly Array<Segment>;
readonly text: string;
readonly usage: TranscriptionUsage;
}

TranscribeResponseMetadata

interface unstable
Since v4.1.5

Provider-specific response metadata keyed by provider name. Provider packages augment this interface with details the portable response leaves out, such as word timestamps, speaker labels, and confidence.

Signature

interface TranscribeResponseMetadata extends ProviderMetadata {
[key: string]: Json;
}

TranscriptionModel

interface unstable
Since v4.1.5

Transcription of recordings and of live audio.

Signature

interface TranscriptionModel {
readonly "~effect/ai/TranscriptionModel": "~effect/ai/TranscriptionModel";
readonly transcribe: (options: TranscribeOptions) => Effect<TranscribeResponse, AiError>;
readonly transcribeLive: <E, R>(options: TranscribeLiveOptions<E, R>) => Stream<SegmentUpdate, AiError | E, R>;
}
Since v4.1.5

Provider-reported usage. Unreported values are undefined.

Details

Providers bill transcription by tokens, by audio duration, or both.

Signature

declare class TranscriptionUsage extends {
readonly audioDuration?: Duration;
readonly inputTokens?: number;
readonly outputTokens?: number;
} {
constructor(...args: [props?: {
readonly audioDuration?: Duration;
readonly inputTokens?: number;
readonly outputTokens?: number;
}, options?: MakeOptions]);
}

Options

TranscribeLiveOptions

interface unstable
Since v4.1.5

Options for transcribing live audio.

Gotchas

Audio is sent as given. Nothing resamples it, so a provider fails with AiError.InvalidUserInputError for a format it cannot take.

Signature

interface TranscribeLiveOptions<E, R> {
readonly audio: Stream<Uint8Array<ArrayBufferLike>, E, R>;
readonly format: AudioFormat;
readonly language?: string;
}

TranscribeOptions

interface unstable
Since v4.1.5

Options for transcribing a recording.

Signature

interface TranscribeOptions {
readonly audio: Recording;
readonly language?: string;
}

Services

Since v4.1.5

Service key for transcribing speech. Create implementations with make.

See

  • transcribe for transcribing a recording through the current service
  • transcribeLive for transcribing live audio through the current service

Signature

declare const TranscriptionModel: Context.Service<TranscriptionModel, TranscriptionModel>

Transcription

transcribe

unstable
Since v4.1.5

Transcribes a finished recording using the current TranscriptionModel service.

See

Signature

declare function transcribe(options: TranscribeOptions): Effect<TranscribeResponse, AiError, TranscriptionModel>

Example Transcribing a recording

import { Effect } from "effect"
import { TranscriptionModel } from "effect/ai"
const program = Effect.fnUntraced(function*(bytes: Uint8Array) {
const { text, segments } = yield* TranscriptionModel.transcribe({
audio: { mediaType: "audio/wav", fileName: "call.wav", data: bytes },
language: "en"
})
return { text, segments }
})
Since v4.1.5

Transcribes live audio using the current TranscriptionModel service.

Details

The session lasts as long as the returned stream. When audio ends, the provider flushes, the last final updates arrive, and the stream completes. Interrupting the stream closes the session. The provider decides where segments begin and end.

Gotchas

  • A dropped connection fails the stream. Use transcribeLiveBuffered to reconnect without losing audio.
  • A model that only transcribes recordings fails with AiError.InvalidUserInputError.

See

Signature

declare function transcribeLive<E, R>(options: TranscribeLiveOptions<E, R>): Stream<SegmentUpdate, AiError | E, TranscriptionModel | R>

Example Keeping the latest text of each segment

import { Stream } from "effect"
import { TranscriptionModel } from "effect/ai"
const captions = (microphone: Stream.Stream<Uint8Array>) =>
TranscriptionModel.transcribeLive({
audio: microphone,
format: { encoding: "pcm16", sampleRate: 24000, channels: 1 }
}).pipe(
Stream.scan(
() => new Map<string, string>(),
(segments, update: TranscriptionModel.SegmentUpdate) => new Map(segments).set(update.id, update.text)
),
Stream.map((segments) => Array.from(segments.values()).join(" "))
)

Transcribes live audio and reconnects after a dropped connection, sending again the audio the transcript may not cover yet.

Details

Audio is buffered as it arrives and the buffer is emptied each time a final segment arrives. When the session fails with a retryable AiError, a new one opens after the next schedule delay and receives the buffer, followed by the audio that arrived during the outage. The schedule starts over once a session produces an update while audio is still open. Once audio has ended, every new session is sent the same audio, so updates no longer start the schedule over. When it is exhausted the stream fails with the last error.

While a session is connected, audio is pulled only as fast as the provider takes it, so a provider that falls behind slows audio down and nothing queues up outside the buffer. During an outage audio is pulled freely.

Segment ids are issued here, so they stay unique across sessions, and segment times stay relative to the start of audio. Segments that were not final when a session failed receive a last update with empty text, because their audio is sent again and comes back under new ids.

When the buffer would exceed maxDuration, "error" fails the stream with an AiError, and "sliding" drops the oldest audio and emits an AudioDiscarded notice.

Gotchas

  • The replay starts where the last final segment arrived, which is not where its speech ended. Speech that began before that point is not sent again, and text is not de-duplicated.
  • Only final segments empty the buffer. Audio with no speech fills it too, so a pause longer than maxDuration overflows it.
  • maxDuration does not bound a source that cannot wait. Give a live source its own bounded Stream.buffer if a slow provider must not hold it up.

See

Signature

declare function transcribeLiveBuffered<E, R, Strategy extends "sliding" | "error">(options: {
readonly audio: Stream<Uint8Array<ArrayBufferLike>, E, R>;
readonly format: AudioFormat;
readonly language?: string;
readonly maxDuration: Input;
readonly schedule: Schedule<unknown, AiError>;
readonly strategy: Strategy;
}): Stream<SegmentUpdate | Strategy extends "sliding" ? AudioDiscarded : never, AiError | E, TranscriptionModel | R>

Example Reconnecting with a bounded buffer

import { Schedule, Stream } from "effect"
import { TranscriptionModel } from "effect/ai"
const updates = (microphone: Stream.Stream<Uint8Array>) =>
TranscriptionModel.transcribeLiveBuffered({
audio: microphone,
format: { encoding: "pcm16", sampleRate: 24000, channels: 1 },
maxDuration: "30 seconds",
strategy: "sliding",
schedule: Schedule.exponential("200 millis")
}).pipe(
Stream.filter((event) => event._tag === "SegmentUpdate" && event.final)
)

Type IDs

TypeId

unstable
Since v4.1.5

Brand for TranscriptionModel implementations.

Signature

declare const TypeId: "~effect/ai/TranscriptionModel"

TypeId

type unstable
Since v4.1.5

Brand type for TranscriptionModel.

Signature

type TypeId = "~effect/ai/TranscriptionModel"