Skip to main content

Overview

The WhisperKit class is the main entry point for performing speech-to-text transcription using Apple’s Core ML framework. It manages model loading, audio processing, and provides both synchronous and asynchronous transcription methods.

Class Definition

Initializers

init(_:)

Initializes WhisperKit with a configuration object.
WhisperKitConfig
Configuration object for WhisperKit initialization. See WhisperKitConfig for details.
Throws: An error if model setup or loading fails.

Convenience Initializer

Initializes WhisperKit with individual parameters.
String?
Name of the Whisper model variant to use (e.g., “tiny”, “base”, “small”, “medium”, “large”)
URL?
Base URL for downloading models
String?
Repository name for downloading models (default: “argmaxinc/whisperkit-coreml”)
String?
Local folder path containing pre-downloaded models
URL?
Folder containing tokenizer files
ModelComputeOptions?
Options for ML compute units (CPU, GPU, Neural Engine)
AudioProcessing?
Custom audio processor implementation
FeatureExtracting?
Custom feature extractor implementation
AudioEncoding?
Custom audio encoder implementation
TextDecoding?
Custom text decoder implementation
[LogitsFiltering]?
Array of logits filters to apply during decoding
SegmentSeeking?
Custom segment seeker implementation
Bool
default:"true"
Enable verbose logging
Logging.LogLevel
default:".info"
Maximum log level to display
Bool?
Enable model prewarming to reduce peak memory during initialization
Bool?
Whether to load models immediately
Bool
default:"true"
Download models if not available locally
Bool
default:"false"
Use background download session for model downloads

Properties

Model State

ModelVariant
Currently loaded model variant (tiny, base, small, medium, large, etc.)
ModelState
Current state of the model (unloaded, loading, loaded, prewarming, etc.)
ModelComputeOptions
Compute options for the loaded models
WhisperTokenizer?
The tokenizer used for encoding/decoding text

Processing Components

AudioProcessing
Audio processor for handling audio input and preprocessing
FeatureExtracting
Feature extractor for converting audio to mel spectrograms
AudioEncoding
Audio encoder for encoding mel spectrograms to embeddings
TextDecoding
Text decoder for generating text from audio embeddings
SegmentSeeking
Segment seeker for managing audio window processing
VoiceActivityDetector?
Optional voice activity detector for chunking audio

Configuration

AudioInputConfig
Configuration for audio input processing
URL?
Path to the folder containing model files
URL?
Path to the folder containing tokenizer files

Progress and Callbacks

TranscriptionTimings
Timing information for the current/last transcription
Progress
Progress object for tracking transcription progress
SegmentDiscoveryCallback?
Callback invoked when new transcription segments are discovered
ModelStateCallback?
Callback invoked when model state changes
TranscriptionStateCallback?
Callback invoked when transcription state changes

Constants

Int
default:"16000"
Sample rate used for audio processing (16 kHz)
Int
default:"160"
Hop length for mel spectrogram computation
Float
default:"0.02"
Duration in seconds represented by each time token (20ms)

Static Methods

deviceName()

Returns the device identifier string.
String
Device identifier (e.g., “iPhone15,2”)

recommendedModels()

Returns recommended models for the current device.
ModelSupport
Model support information including default and supported model variants

recommendedRemoteModels(from:downloadBase:token:remoteConfigName:endpoint:)

Fetches recommended models from a remote repository.
String
default:"argmaxinc/whisperkit-coreml"
Repository to fetch model configuration from
URL?
Base URL for downloads
String?
Authentication token for the repository
String
Name of the remote configuration file
String
API endpoint for the repository
ModelSupport
Model support information from the remote repository

fetchAvailableModels(from:matching:downloadBase:token:remoteConfigName:endpoint:)

Fetches list of available models from a remote repository.
String
default:"argmaxinc/whisperkit-coreml"
Repository to fetch models from
[String]
default:"[\"*\"]"
Glob patterns to filter model names
[String]
Array of available model names

download(variant:downloadBase:useBackgroundSession:from:token:endpoint:progressCallback:)

Downloads a specific model variant.
String
Model variant to download (e.g., “tiny”, “base”, “small”)
((Progress) -> Void)?
Optional callback for download progress updates
URL
Local URL of the downloaded model folder

Instance Methods

loadModels(prewarmMode:)

Loads the models into memory.
Bool
default:"false"
If true, loads models in prewarm mode to reduce peak memory usage

prewarmModels()

Prewarms the models by loading them sequentially.

unloadModels()

Unloads all models from memory.

clearState()

Clears the current transcription state.

detectLanguage(audioPath:)

Detects the language of audio from a file path.
String
Path to the audio file
(language: String, langProbs: [String: Float])
Tuple containing detected language code and probability distribution over all languages

detectLangauge(audioArray:)

Detects the language of audio from sample array.
[Float]
Array of 16kHz audio samples
(language: String, langProbs: [String: Float])
Tuple containing detected language code and probability distribution

transcribe(audioPath:decodeOptions:callback:)

Transcribes audio from a file path.
String
Path to the audio file to transcribe
DecodingOptions?
Options for transcription (language, task, temperature, etc.)
TranscriptionCallback
Optional callback for progress updates during transcription
[TranscriptionResult]
Array of transcription results. See TranscriptionResult for details.

transcribe(audioArray:decodeOptions:callback:segmentCallback:)

Transcribes audio from a sample array.
[Float]
Array of 16kHz mono audio samples
DecodingOptions?
Options for transcription
TranscriptionCallback
Optional callback for progress updates
SegmentDiscoveryCallback?
Optional callback invoked when segments are discovered
[TranscriptionResult]
Array of transcription results

transcribe(audioPaths:decodeOptions:callback:)

Transcribes multiple audio files.
[String]
Array of audio file paths to transcribe
[[TranscriptionResult]?]
Array of optional transcription result arrays (nil if transcription failed for that file)

transcribe(audioArrays:decodeOptions:callback:)

Transcribes multiple audio sample arrays.
[[Float]]
Array of audio sample arrays to transcribe
[[TranscriptionResult]?]
Array of optional transcription result arrays

loggingCallback(_:)

Sets a custom logging callback.
Logging.LoggingCallback?
Custom logging callback function

Example Usage

Basic Transcription

Custom Configuration

Language Detection

With Progress Callback