WhisperEngine
whisper.cpp speech-to-text engine.
Create instances with the WhisperEngine factory function. Engines are ordinary objects — never singletons — and any number of them (with the same or different models and backends) can coexist and transcribe concurrently: each owns its native whisper context and a dedicated single-threaded dispatcher (SerialExecutor) that serializes model loading, transcribe, reinitialize and the native release in close.
Audio crosses into native code zero-copy: 16 kHz mono FloatArrays are read in place by whisper.cpp; other rates / channel counts and ShortArray input are converted natively (pinned input, one output buffer).
Cancellation is cooperative and prompt: cancelling the coroutine that called transcribe sets the native abort flag, which whisper.cpp polls inside every ggml graph computation, so decoding stops within one graph step and the call throws CancellationException. The engine stays usable afterwards.
Live audio is transcribed with transcribeStream, which turns a Flow of PCM chunks into a Flow<TranscriptionEvent> without writing any audio to disk. Each collection owns its own native whisper_state, so streams, one-shot transcribe calls and other streams on the same engine never disturb each other's decoder state; their decodes are serialized on the engine's thread like every other native call.
Types
Constants and factory functions of WhisperEngine.
Properties
The backend whisper.cpp actually runs on (never ComputeBackend.AUTO).
The GPU whisper.cpp runs on, or null on the CPU (see InferenceEngine.activeDeviceName).
The configuration of the currently loaded model (see reinitialize).
Why activeBackend is not the requested backend, or null (see InferenceEngine.backendFallbackReason).
true while a transcribe call or a transcribeStream decode is executing native code.
Whisper-specific construction options.
whisper_context_params.use_gpu of the loaded model: always false for ComputeBackend.CPU_ONLY.
Functions
Requests the native abort of the transcription currently executing, if any; it then fails with InferenceCancelledException (a transcribeStream decode ends its stream with a terminal TranscriptionEvent.Error). Safe from any thread. Queued calls are not affected.
Closes the engine: aborts a running transcription, rejects queued and future calls with IllegalStateException, ends running transcribeStream collections with a terminal TranscriptionEvent.Error (InferenceCancelledException), frees their native states and then the native context on the engine's thread, and stops that thread. Idempotent and safe from any thread.
closes the engine and suspends until its native memory has been freed on the engine thread (after a running call has been aborted and left native code). Idempotent; cancelling the caller stops the wait, not the release. See InferenceEngine.closeAndAwait.
Reloads the model with backendConfig on this engine's thread, after any transcription already queued. The old native context is freed before the new one is created, so GPU resources are released promptly (e.g. when switching to ComputeBackend.CPU_ONLY as an iOS app enters the background).
Transcribes interleaved float PCM in [-1, 1].
Transcribes interleaved signed 16-bit PCM (normalized as sample / 32768). The array is read in place by the native converter; see the FloatArray overload for the remaining semantics.
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.
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.)