WhisperEngine

suspend fun WhisperEngine(modelPath: String, backendConfig: BackendConfig = BackendConfig.DEFAULT, options: WhisperEngineOptions = WhisperEngineOptions()): WhisperEngine(source)

Loads a whisper.cpp ggml model and returns a ready WhisperEngine.

The model is loaded on the new engine's own dedicated thread. backendConfig is enforced at load time:

  • ComputeBackend.CPU_ONLY sets whisper_context_params.use_gpu = false before whisper_init_from_file_with_params(), so ggml never creates a GPU backend. On iOS all work then runs on Apple Accelerate / ARM NEON, which remains legal while the app is in the background.

  • ComputeBackend.GPU_METAL / ComputeBackend.GPU_VULKAN set use_gpu = true on that device kind.

  • ComputeBackend.NPU_COREML additionally enables the Core ML encoder (iOS builds with WHISPER_COREML); it uses <model>-encoder.mlmodelc next to the model when present and otherwise falls back to Metal/CPU.

  • ComputeBackend.AUTO picks the first available of CoreML, Metal, Vulkan, CPU on Apple platforms and the JVM desktop, and always the CPU on Android, where whisper runs several times slower on OpenCL / Vulkan than on the CPU (see WhisperAutoPolicy). An explicit GPU_OPENCL or GPU_VULKAN request still uses that GPU. On the iOS simulator Metal (and with it CoreML) is unavailable, because the simulator's Metal device aborts the process on whisper's buffer allocations: there AUTO resolves to the CPU, and an explicit GPU_METAL or NPU_COREML falls back to it (or throws com.donfuldauer.kggml.core.BackendUnavailableException when WhisperEngineOptions.allowBackendFallback is false).

BackendConfig.useFlashAttention maps to whisper's flash attention (on when null, matching whisper.cpp; about twice as fast as without on mobile CPUs) and cpuThreads to the decoder thread count (BackendConfig.AUTO_THREADS = number of performance cores). gpuLayers and useMmap do not apply to Whisper models and are ignored.

Throws

if the file is missing or not a whisper model.

if the native libraries cannot be loaded.