fix(audio): guard against invalid inputNode format after fresh mic permission grant#81
Merged
Merged
Conversation
…rmission grant After a first-time microphone permission grant, AVAudioEngine.inputNode may report 0 channels / 0 sampleRate while the audio subsystem reconfigures. Proceeding with this invalid format causes audioEngine.start() to throw -10877 (kAudioUnitErr_InvalidElement). - Validate hardwareFormat.channelCount and sampleRate before installing the tap; return NO early with a descriptive log if invalid - Add a single 500ms retry in SPAppDelegate when audio capture fails, giving the audio subsystem time to settle after permission changes - Extract shared capture-start logic into startAudioCaptureWithRetry to avoid duplication between hold and tap code paths Co-authored-by: Davy <thedavidweng@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
-10877(kAudioUnitErr_InvalidElement) crash that occurs when a user triggers voice input for the first time immediately after granting microphone permission.Root Cause
After a fresh microphone permission grant,
AVAudioEngine.inputNodemay temporarily report 0 channels / 0 sampleRate while the macOS audio subsystem reconfigures. The previous code proceeded unconditionally with this invalid format:AVAudioEngine.start()then fails with-10877because the Audio Unit has no valid element/connection on bus 0. The user sees this as "pressing the trigger key does nothing" withthrowing -10877flooding the Console log.Reproduction
throwing -10877entriesChanges
SPAudioCaptureManager.moutputFormatForBus:0— returnNOearly ifchannelCount == 0orsampleRate <= 0, with a descriptive log messageSPAppDelegate.mstartAudioCaptureWithRetryBehavior
-10877crash, no audioTesting
cargo test --no-default-features— 44+11+1 tests).mfiles verified for balanced braces/brackets/parenscargo fmt --check/cargo clippy— pass