experimental_streamTranscribe()
experimental_streamTranscribe is an experimental feature.
Streams a transcript from live raw audio using a transcription model with streaming support.
import { experimental_streamTranscribe as streamTranscribe } from 'ai';import { openai } from '@ai-sdk/openai';
const result = streamTranscribe({ model: openai.transcription('gpt-realtime-whisper'), audio: audioStream, // ReadableStream<Uint8Array | string> inputAudioFormat: { type: 'audio/pcm', rate: 24000 },});
for await (const part of result.fullStream) { if (part.type === 'transcript-delta') { process.stdout.write(part.delta); }}
console.log(await result.text);Import
import { experimental_streamTranscribe as streamTranscribe } from "ai"API Signature
Parameters
model:
TranscriptionModelV4
audio:
ReadableStream<Uint8Array | string>
inputAudioFormat:
{ type: string; rate?: number }
providerOptions?:
Record<string, JSONObject>
abortSignal?:
AbortSignal
headers?:
Record<string, string>
includeRawChunks?:
boolean
Returns
fullStream:
AsyncIterableStream<TranscriptionStreamPart>
text:
Promise<string>
segments:
Promise<Array<{ text: string; startSecond: number; endSecond: number }>>
language:
Promise<string | undefined>
durationInSeconds:
Promise<number | undefined>
warnings:
Promise<Warning[]>
responses:
Promise<Array<TranscriptionModelResponseMetadata>>
providerMetadata:
Promise<Record<string, JSONObject>>
The result promises settle as the stream is consumed. If you stop consuming
fullStream early (e.g. break out of the loop), the underlying provider
connection is closed and pending result promises reject.