Skip to main content

Streaming Transcription

WhisperKit supports real-time streaming transcription using the AudioStreamTranscriber class. This enables live transcription from the microphone with automatic voice activity detection and segment confirmation.

AudioStreamTranscriber

The AudioStreamTranscriber actor manages the complete streaming pipeline:
  • Captures live audio from the microphone
  • Detects voice activity
  • Transcribes audio in real-time
  • Manages segment confirmation and state updates
See AudioStreamTranscriber

Basic Setup

Initialize Streaming Transcriber

See AudioStreamTranscriber.init

Start and Stop Streaming

See AudioStreamTranscriber.swift:73-93

State Management

The AudioStreamTranscriber.State tracks the current transcription state:
See AudioStreamTranscriber.State

State Properties

Bool
Whether audio is currently being recorded and transcribed.
String
The most recent transcription text (may be unconfirmed).
[TranscriptionSegment]
Segments that have been confirmed and are unlikely to change.
[TranscriptionSegment]
Segments that may still be refined as more audio is processed.
[Float]
Audio energy levels for voice activity detection.

Configuration Options

Customize the streaming behavior with initialization parameters:
See AudioStreamTranscriber.init

Configuration Parameters

Int
default:"2"
Number of segments that must be decoded before earlier segments are confirmed. Higher values provide more stability but increase latency.
Float
default:"0.3"
Energy threshold for voice activity detection. Lower values are more sensitive to quiet speech.
Int
default:"60"
Number of tokens to check for repetition/hallucination. Helps detect when the model is producing gibberish.
Bool
default:"true"
Enable voice activity detection to skip silent segments. Improves performance and accuracy.

State Change Callback

The callback receives both old and new states for comparison:
See AudioStreamTranscriberCallback

Segment Confirmation

The transcriber uses a sliding window approach:
  1. Audio is continuously buffered and transcribed
  2. New segments are added to unconfirmedSegments
  3. When segment count exceeds requiredSegmentsForConfirmation, earlier segments move to confirmedSegments
  4. Confirmed segments are unlikely to change as more audio is processed
See AudioStreamTranscriber.transcribeCurrentBuffer

Voice Activity Detection

When useVAD is enabled, the transcriber skips silent segments:
See AudioStreamTranscriber.transcribeCurrentBuffer

Benefits of VAD

  • Reduces unnecessary computation during silence
  • Improves transcription accuracy by avoiding false positives
  • Lowers battery consumption
  • Reduces hallucinations from background noise

Early Stopping

The transcriber implements early stopping to prevent hallucinations:
See AudioStreamTranscriber.shouldStopEarly

Complete Example

Permissions

Streaming transcription requires microphone access:
The transcriber automatically requests permission:
See AudioStreamTranscriber.startStreamTranscription

Performance Considerations

Model Size

Use smaller models (tiny, base) for real-time streaming. Larger models may not keep up with live audio.

Buffer Management

The transcriber maintains an audio buffer. Long recordings consume more memory.

VAD Optimization

Enable VAD to skip silent portions and reduce computation.

Confirmation Latency

Higher requiredSegmentsForConfirmation improves stability but increases latency before segments are confirmed.

Next Steps

Voice Activity Detection

Deep dive into VAD configuration

Configuration

Advanced configuration options