Skip to content

fix: eliminate cold-start delay by pre-warming audio hardware#137

Open
RABJR51 wants to merge 1 commit intoStarmel:masterfrom
RABJR51:fix/cold-start-audio-hardware-warmup
Open

fix: eliminate cold-start delay by pre-warming audio hardware#137
RABJR51 wants to merge 1 commit intoStarmel:masterfrom
RABJR51:fix/cold-start-audio-hardware-warmup

Conversation

@RABJR51
Copy link
Copy Markdown

@RABJR51 RABJR51 commented Mar 27, 2026

Problem

Every recording creates a fresh AVAudioRecorder from scratch:

audioRecorder = try AVAudioRecorder(url: fileURL, settings: settings)
audioRecorder?.record()

macOS audio hardware initialization takes ~300–500ms, which cuts off the first word(s) every time recording starts.

Fix

Keep a primed recorder alive at all times using prepareToRecord(). This holds the audio engine in an initialized state without actually recording anything.

How it works:

  1. On app launch → primeAudioHardware() creates an AVAudioRecorder and calls prepareToRecord(), keeping it in primedRecorder
  2. On record start → primedRecorder = nil releases it just before starting the real recorder (hardware stays warm, so .record() fires instantly)
  3. On record stop → primeAudioHardware() re-primes in the background so the next recording is equally fast

Result: zero cold-start delay. First word captured every time.

Files changed

  • OpenSuperWhisper/AudioRecorder.swift — adds primedRecorder property, primeAudioHardware() method, and calls at setup + stop

Testing

Tested the logic against the source. Since prepareToRecord() is a documented AVFoundation API specifically designed for pre-warming audio hardware, the fix is minimal and safe.

AVAudioRecorder is created fresh on every recording, causing a
~300-500ms hardware initialization delay that cuts off first words.

Fix: keep a 'primed' AVAudioRecorder (prepareToRecord, not recording)
alive at all times. This holds the audio engine in an initialized state.
On record start, release the primed recorder and immediately start the
real one — hardware is already hot, so .record() fires instantly.
Re-prime after each stop so every subsequent recording is equally fast.
akatz-ai added a commit to akatz-ai/OpenSuperWhisper that referenced this pull request Mar 27, 2026
From upstream PR Starmel#137 (Starmel#137).
Keeps a primed AVAudioRecorder alive to avoid ~300-500ms hardware
initialization delay that cuts off first words.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant