fix(vscode): accelerate macOS speech capture - #12814
Conversation
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (3 files)
Notes: re-reviewed at cd7d053 after the PR was reworked to native AVFoundation capture. Startup now awaits the mac and FFmpeg paths and returns booleans, and Fix these issues in Kilo Cloud Previous Review Summary (commit 3aa37f2)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 3aa37f2)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (3 files)
Notes: reviewed Reviewed by kimi-k3 · Input: 62.7K · Output: 15.5K · Cached: 400.4K Review guidance: REVIEW.md from base branch |
3aa37f2 to
cd7d053
Compare
| const error = Ref() | ||
| const url = $.NSURL.fileURLWithPath(args[0]) | ||
| const recorder = $.AVAudioRecorder.alloc.initWithURLSettingsError(url, settings, error) | ||
| if (!recorder || !recorder.prepareToRecord || !recorder.record) throw new Error("Could not start recording") |
There was a problem hiding this comment.
SUGGESTION: The NSError populated by initWithURLSettingsError is never read
When AVAudioRecorder initialization fails, the script throws a generic Could not start recording, discarding the NSError captured in the error Ref (error[0]). Native capture failures only surface through the console.warn fallback log, and on this brand-new platform-specific path failures will be heterogeneous (TCC denial, device busy, unsupported format keys) — including the underlying localizedDescription in the thrown message would make user bug reports much more actionable. Note osascript-thrown JS errors do reach summary() via stderr, so this only affects the explicit throw here.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
macOS voice input currently launches FFmpeg for every recording even though the platform already provides AVFoundation. FFmpeg process creation is inexpensive, but its AVFoundation capture path accounts for most of the delay before the UI can safely report that recording has started.
This change records 16 kHz mono PCM WAV audio through AVFoundation using the built-in macOS JavaScript bridge. Readiness is emitted only after
AVAudioRecorder.record()succeeds, so the UI does not become optimistic and the beginning of speech is not clipped. The microphone remains closed while idle. If native capture fails, Kilo falls back to the existing bundled FFmpeg path.KILO_FFMPEG_PATHandFFMPEG_PATHcontinue to force FFmpeg explicitly.The comparison uses 20 capture-only starts per implementation in the same isolated VS Code environment with microphone permission already granted. Each recording is stopped and cancelled before transcription, so the numbers measure trigger-to-recording readiness rather than network or model latency.
/usr/bin/osascript, AVFoundation, and Foundation already provided by the OS.Platform Scope And Risks
osascriptand AVFoundation components. TCC, device, format, or managed-device restrictions can reject the native path. A native startup failure can pay the existing five-second readiness timeout before fallback.The native script is static and receives the temporary output path as a separate argument. It does not interpolate user input into executable code. The output format remains the existing 16 kHz mono PCM WAV contract used by transcription.
The separate follow-up PR #12821 only improves macOS NSError diagnostics when native startup fails; it does not change capture behavior.