transcribeStream

fun transcribeStream(audioFlow: Flow<FloatArray>, sampleRate: Int = SAMPLE_RATE, channels: Int = 1, options: StreamingOptions = StreamingOptions.DEFAULT): Flow<TranscriptionEvent>(source)

Transcribes a live stream of interleaved float PCM chunks in [-1, 1] into a cold Flow of TranscriptionEvents. Nothing is written to disk: audio flows from audioFlow through the native streaming resampler (skipped for 16 kHz mono) into an in-memory ring buffer, a voice-activity turn detector, and whisper_full_with_state() on a whisper_state owned by this collection.

Events, in order:

Exceptions thrown by audioFlow itself propagate to the collector unchanged. Cancelling the collector aborts a running native decode through whisper.cpp's abort callback and frees the stream's whisper_state and resampler on the engine thread before the collection finishes.

The audio flow is collected on kotlinx.coroutines.Dispatchers.Default. If the decoder falls behind by StreamingOptions.bufferMs, collection of audioFlow is suspended (back-pressure) — audio is never dropped.

Parameters

sampleRate

input sample rate in Hz, 1000..384000.

channels

interleaved channel count, 1..8; every chunk's size must be a multiple of it.

Throws

immediately for an unsupported sampleRate / channels.

immediately if the engine is closed.


@JvmName(name = "transcribeStreamPcm16")
fun transcribeStream(audioFlow: Flow<ShortArray>, sampleRate: Int = SAMPLE_RATE, channels: Int = 1, options: StreamingOptions = StreamingOptions.DEFAULT): Flow<TranscriptionEvent>(source)

transcribeStream for interleaved signed 16-bit PCM chunks (normalized natively as sample / 32768). See the FloatArray overload for the event contract. (On the JVM this overload is named transcribeStreamPcm16, since both overloads erase to Flow.)