Streaming Transcription
WhisperKit supports real-time streaming transcription using theAudioStreamTranscriber class. This enables live transcription from the microphone with automatic voice activity detection and segment confirmation.
AudioStreamTranscriber
TheAudioStreamTranscriber 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
Basic Setup
Initialize Streaming Transcriber
Start and Stop Streaming
State Management
TheAudioStreamTranscriber.State tracks the current transcription 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: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:Segment Confirmation
The transcriber uses a sliding window approach:- Audio is continuously buffered and transcribed
- New segments are added to
unconfirmedSegments - When segment count exceeds
requiredSegmentsForConfirmation, earlier segments move toconfirmedSegments - Confirmed segments are unlikely to change as more audio is processed
Voice Activity Detection
WhenuseVAD is enabled, the transcriber skips silent segments:
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:Complete Example
Permissions
Streaming transcription requires microphone access: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