fix: prevent sound effects from bleeding into transcription - #52
Merged
Conversation
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
Fixes sound effects (Pop/Bottle) being picked up by the microphone and transcribed as gibberish words like "Ding", "Pewds", "pulls", "pain", etc.
Root Cause
SoundManager played sounds in parallel with AudioEngine start — the mic captured the system sounds before they finished playing, causing them to be included in the transcription buffer.
Solution
SoundManager.playStartSoundAsync()await sound completion usingNSSoundDelegate+CheckedContinuationstartRecording()flow: play start sound → await completion → start mic tapSoundManagerconform to@unchecked Sendableand added thread-safe lockingFiles Changed
SoundManager.swift— async playback with delegate callback and proper synchronizationAppState.swift— sequential sound → mic orchestration instartRecording()VocaMacTests.swift— tests for async sound behavior (5 new test cases)Testing
All 41 tests pass, including 5 new SoundManager tests covering:
Technical Details
The fix uses Swift concurrency best practices:
async/awaitfor cleaner sequencingNSSoundDelegate.sound(_:didFinishPlaying:)callbackCheckedContinuationto bridge delegate to asyncNSLockfor thread-safe continuation access@unchecked SendableforSoundManagerwith manual synchronizationCloses #49