Skip to main content

Audio Transcription

WhisperKit provides flexible APIs for transcribing audio from files, arrays, or live input. All transcription methods return TranscriptionResult objects containing the recognized text and detailed metadata.

Basic Transcription

Transcribe from File Path

The simplest way to transcribe audio:
See WhisperKit.swift:840-872

Transcribe from Audio Array

For pre-loaded audio samples:
See WhisperKit.swift:896-960

Decoding Options

Customize transcription behavior with DecodingOptions:
See DecodingOptions

Key DecodingOptions Parameters

DecodingTask
default:".transcribe"
  • .transcribe - Transcribe audio in its original language
  • .translate - Translate to English
String?
default:"nil"
Language code (e.g., “en”, “es”, “fr”). If nil, language is auto-detected for multilingual models.
Float
default:"0.0"
Sampling temperature. 0.0 uses greedy decoding (most accurate), higher values increase randomness.
Bool
default:"false"
Enable word-level timestamps in the output.
Bool
default:"false"
Disable all timestamps (faster decoding).
Float?
default:"2.4"
If text compression ratio exceeds this, mark as failed (indicates repetition/hallucination).
Float?
default:"-1.0"
If average log probability is below this, mark as failed (low confidence).
Int
default:"16 (macOS) / 4 (iOS)"
Number of concurrent workers for parallel transcription of multiple audio files.

Batch Transcription

Transcribe Multiple Files

See WhisperKit.swift:599-673

Using Results for Error Handling

See WhisperKit.swift:624-673

TranscriptionResult Structure

Each transcription returns a TranscriptionResult with:
See TranscriptionResult

TranscriptionSegment Properties

  • id: Int - Segment identifier
  • seek: Int - Seek position in audio samples
  • start: Float - Start time in seconds
  • end: Float - End time in seconds
  • text: String - Transcribed text
  • tokens: [Int] - Token IDs
  • words: [WordTiming]? - Word-level timestamps (if enabled)

Language Detection

Detect the language of an audio file:
See WhisperKit.swift:533-593
Language detection only works with multilingual models. English-only models (tiny.en, base.en, etc.) will throw an error.

Progress Tracking

Monitor transcription progress with a callback:

TranscriptionProgress Properties

  • windowId: Int - Current audio window being processed
  • text: String - Current decoded text
  • tokens: [Int] - Generated tokens
  • avgLogprob: Float? - Average log probability
  • timings: TranscriptionTimings - Performance metrics

Advanced Features

Clip Timestamps

Transcribe specific time segments:

Prompt Tokens

Provide context to improve accuracy:

Temperature Fallback

Automatically retry with higher temperature on failure:
See DecodingOptions

Best Practices

Audio Format

WhisperKit expects 16kHz mono audio. Use AudioProcessor.loadAudio() to convert formats automatically.

Model Selection

Use smaller models (tiny, base) for real-time needs and larger models (medium, large) for accuracy.

Error Handling

Use transcribeWithResults() for robust error handling when processing multiple files.

Memory Management

Unload models when not in use: await whisperKit.unloadModels()

Next Steps

Streaming

Learn real-time transcription

Voice Activity Detection

Optimize with VAD