Skip to content

fix: prevent sound effects from bleeding into transcription - #52

Merged
jatinkrmalik merged 1 commit into
mainfrom
fix/sound-bleed
Mar 10, 2026
Merged

fix: prevent sound effects from bleeding into transcription#52
jatinkrmalik merged 1 commit into
mainfrom
fix/sound-bleed

Conversation

@jatinkrmalik

Copy link
Copy Markdown
Member

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

  • Made SoundManager.playStartSoundAsync() await sound completion using NSSoundDelegate + CheckedContinuation
  • Reordered startRecording() flow: play start sound → await completion → start mic tap
  • Stop flow already correct: stop mic tap → play stop sound (fire-and-forget, mic is already off)
  • Added 1-second timeout to prevent stuck sounds from blocking recording
  • Made SoundManager conform to @unchecked Sendable and added thread-safe locking

Files Changed

  • SoundManager.swift — async playback with delegate callback and proper synchronization
  • AppState.swift — sequential sound → mic orchestration in startRecording()
  • VocaMacTests.swift — tests for async sound behavior (5 new test cases)

Testing

All 41 tests pass, including 5 new SoundManager tests covering:

  • Synchronous sound playback (fire-and-forget)
  • Asynchronous sound playback with timeout
  • Volume control

Technical Details

The fix uses Swift concurrency best practices:

  • async/await for cleaner sequencing
  • NSSoundDelegate.sound(_:didFinishPlaying:) callback
  • CheckedContinuation to bridge delegate to async
  • NSLock for thread-safe continuation access
  • @unchecked Sendable for SoundManager with manual synchronization

Closes #49

@jatinkrmalik
jatinkrmalik merged commit 97c5b9f into main Mar 10, 2026
1 check passed
@jatinkrmalik
jatinkrmalik deleted the fix/sound-bleed branch August 22, 2026 05:32
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.

fix: Sound effects bleed into transcription — make audio capture sequential with sound playback

1 participant