streamTranscribe
Transcribe live audio as it arrives.
Streams audio to a transcription model over a WebSocket and yields text as it is recognized.
Interim guesses arrive as .partialTranscript, which replaces the current
partial, while settled text arrives as .transcriptDelta, which appends.
Keeping those separate is what stops revisions from double-counting.
for try await part in streamTranscribe(
model: DeepgramTranscriptionModel("nova-3"),
audio: micStream
) {
switch part {
case .partialTranscript(let text): showInterim(text)
case .transcriptDelta(let text): append(text)
default: break
}
}Signature
func streamTranscribe(
model: any TranscriptionModel,
audio: AsyncThrowingStream<Data, Error>,
mediaType: String,
providerOptions: JSONValue? = nil
) throws -> StreamTranscriptionResultDefined in Sources/AI/Core/StreamTranscription.swift.
Parameters
| Parameter | Type | Default |
|---|---|---|
model | any TranscriptionModel | required |
audio | AsyncThrowingStream<Data, Error> | required |
mediaType | String | required |
providerOptions | JSONValue? | nil |
Returns
A StreamTranscriptionResult whose stream yields TranscriptionStreamPart
values, plus an awaitable final result.