fix(ios): move MLXArray copy off audio tap path#26
Merged
Conversation
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"}
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
audioBufferinAudioCaptureManager.snapshot()so the real-time audio tap no longer triggers copy-on-write duplication of the sample array underbufferLock.MLXArray(samples)construction outside the lock and off the audio thread's critical path.deferso repeatedsnapshot()calls keep accumulating audio (preserves prior semantics).Test plan
bun specs:podsnapshot()rapidly during recording — no audio dropouts, transcript remains accurate