transcribeStream
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:
TranscriptionEvent.PartialHypothesis — unstable text of the speech turn in progress, re-decoded every StreamingOptions.partialStepMs of new audio (conflated when the engine is behind).
TranscriptionEvent.CommittedSegment — locked, timestamped segments of a finished turn (a pause of com.donfuldauer.kggml.whisper.streaming.VadConfig.trailingSilenceMs, a 30 s window split, or the end of the input). Indices increase monotonically from 0 and timestamps are milliseconds from the start of the stream. The text tokens of committed segments are carried forward as
prompt_tokensof later decodes (StreamingOptions.carryPromptTokens) across pauses and 30 s windows.TranscriptionEvent.Completed — after audioFlow completed and the last turn was committed; the last event.
TranscriptionEvent.Error — a typed com.donfuldauer.kggml.core.InferenceException (native failure, malformed chunk, abortActiveTranscription, or close of the engine, reported as InferenceCancelledException). It is terminal: no event follows it and the flow then completes normally rather than throwing.
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
input sample rate in Hz, 1000..384000.
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.
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.)