Skip to content

fix(ios): move MLXArray copy off audio tap path#26

Merged
corasan merged 3 commits into
mainfrom
t3code/fix-audio-snapshot-lock-copy
Apr 23, 2026
Merged

fix(ios): move MLXArray copy off audio tap path#26
corasan merged 3 commits into
mainfrom
t3code/fix-audio-snapshot-lock-copy

Conversation

@corasan
Copy link
Copy Markdown
Owner

@corasan corasan commented Apr 23, 2026

Summary

  • Take exclusive ownership of audioBuffer in AudioCaptureManager.snapshot() so the real-time audio tap no longer triggers copy-on-write duplication of the sample array under bufferLock.
  • Move the MLXArray(samples) construction outside the lock and off the audio thread's critical path.
  • Merge samples back via defer so repeated snapshot() calls keep accumulating audio (preserves prior semantics).

Test plan

  • bun specs:pod
  • Run the example app on iOS and open the STT tab
  • Verify transcription quality across a long utterance
  • Call snapshot() rapidly during recording — no audio dropouts, transcript remains accurate
  • Stop/restart capture cycles behave cleanly

corasan added 3 commits April 23, 2026 13:51
Reading audioBuffer into a `let` only bumped the copy-on-write refcount,
so the next append from the real-time audio tap forced a full duplication
of the sample array under bufferLock. Take exclusive ownership of the
buffer, release the lock, then construct MLXArray off the audio path.
The defer block merges any samples appended during the copy back into
audioBuffer so cumulative capture semantics are preserved across calls.
- Use snapshotAndClear() so each transcribeBuffer call processes only new audio
- Append partial results in the example instead of overwriting, and merge with final text on stop
{"subject": "feat(stt): switch to Qwen3-ASR and gate silent audio chunks", "body": "- Add Qwen3-ASR 0.6B 4-bit model and swap HybridSTT to use it\n- Skip audio chunks below peak amplitude threshold to avoid ASR hallucinations on silence\n- Simplify example stop flow and surface transcribeBuffer errors"}
@corasan corasan merged commit 76a9f9f into main Apr 23, 2026
3 checks passed
@corasan corasan deleted the t3code/fix-audio-snapshot-lock-copy branch April 23, 2026 20:52
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