Skip to content

Add 150ms tail buffer after Fn release#4

Open
croshank wants to merge 1 commit intosmallest-inc:mainfrom
croshank:fn-release-tail-buffer
Open

Add 150ms tail buffer after Fn release#4
croshank wants to merge 1 commit intosmallest-inc:mainfrom
croshank:fn-release-tail-buffer

Conversation

@croshank
Copy link
Copy Markdown

When you release the Fn key, audio capture stops immediately. If you're still finishing a word as you let go, the tail end gets clipped and the STT misses it.

This adds a 150ms delay between key-up and stopping the audio capture, giving the mic time to pick up the rest of the utterance before the stream is finalized.

One-line change in AgentViewModel.stopListening().

When the user releases Fn, audio capture now continues for 150ms
before stopping. This prevents the final word from being cut off
mid-utterance, which happens because key-up fires before the
speaker's articulatory gesture is complete.
@entelligence-ai-pr-reviews
Copy link
Copy Markdown

entelligence-ai-pr-reviews bot commented Mar 30, 2026

EntelligenceAI PR Summary

Fixes audio clipping of the last spoken word in AgentViewModel.swift by deferring recording pipeline teardown after key release.

  • Added a 150ms Task.sleep delay after key release event
  • Delay occurs before audio.onChunk is set to nil
  • Ensures the final audio chunk is fully captured before audio capture is stopped

Confidence Score: 5/5 - Safe to Merge

Safe to merge — this PR introduces a focused 150ms tail buffer in AgentViewModel.swift to prevent audio clipping of the last spoken word by deferring the teardown of audio.onChunk after the Fn key release event. The change is minimal, well-scoped, and directly addresses the described bug without introducing new complexity or side effects. No issues were identified in the review, and the approach of using Task.sleep before nullifying audio.onChunk is a straightforward and appropriate fix for this class of race condition.

Key Findings:

  • The 150ms Task.sleep delay in AgentViewModel.swift is placed correctly before audio.onChunk is set to nil, ensuring in-flight audio chunks from the final utterance are fully captured before the pipeline is torn down.
  • The change is surgically minimal — it touches only the key-release handling path and does not affect recording start, chunk processing logic, or any other state transitions in the view model.
  • No null-safety, concurrency, or logic issues were flagged; the async/await pattern used is idiomatic Swift and consistent with the surrounding codebase context.
  • The 150ms value is a reasonable heuristic for audio buffer latency at typical sample rates, though it could optionally be made a named constant for clarity — this is a minor style consideration with no runtime impact.
Files requiring special attention
  • AgentViewModel.swift

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