Phases 2-6: detection, visual timeline, backend hand-off, voiceprints

Phase 2 (call detection): CallDetector using CoreAudio per-process mic
attribution (anarlog technique) — robust start+stop for Zoom/Teams/Signal/Meet,
ignoring our own recording; auto-record toggle. Built; pending live multi-app
confirmation by the user.

Phase 3 (visual timeline foundation): AppAdapter protocol + SpeakerObservation,
TimelineBuilder (hysteresis/overlap/self-merge/aliases), VisualTimeline (schema
1.1), TextRecognizer (Vision OCR), FrameSampler + GridCallAnalyzer (name OCR +
saturated-highlight active-speaker attribution), SignalAdapter, VisualObserver
(window capture; frames released, never saved; minimized->visual_gap, idle != gap).
Synthetic-frame tested; adapter geometry pending real Signal fixtures + live
VisualObserver validation.

Phase 5 (backend hand-off): SparkControlClient (multipart label-merge, sequential,
TLS-skip, 503 Retry-After/413), SessionPackager (chunk plan + WAV slice + timeline
slice/rebase), TranscriptAssembler + SpeakersFile, TranscriptPipeline. Validated
END-TO-END against the live backend (chunk -> label-merge -> speakers.json).

Phase 6 (voiceprints): VoiceprintStore (known_voiceprints, persist named
fingerprints, skip Unknown). Wired: 'Send to backend' button + transcript status,
auto-send toggle (default off) + self-name setting.

All adversarial-review findings fixed. App + XCTest suite build; tests pass.
This commit is contained in:
Grant Gilliam
2026-06-06 00:15:49 -05:00
parent fd7e1a5907
commit 863136aeec
27 changed files with 2108 additions and 22 deletions
+29 -16
View File
@@ -156,31 +156,44 @@ final class AudioRecorder: NSObject, SCStreamDelegate, SCStreamOutput {
// MARK: - Ingest (ioQueue only)
/// Write audio CONTINUOUSLY; re-anchor to the timestamp only when drift is a
/// real gap (> ~100 ms), not per-buffer timestamp jitter. Correcting every
/// buffer injects/strips a few samples each time audible rhythmic glitching.
/// The shared t0 still bounds mic/system skew to the tolerance, well within
/// what the backend merge needs.
private static let driftTolerance: Int64 = 1600 // 100 ms @ 16 kHz
private func ingestMic(_ buffer: AVAudioPCMBuffer, startHost: Double) {
guard !tornDown, let writer = micWriter, let vad else { return }
let expected = max(0, Int64(((startHost - t0Host) * 16_000).rounded()))
if expected > writer.framesWritten {
let padded = writer.padSilence(expected - writer.framesWritten)
let drift = max(0, Int64(((startHost - t0Host) * 16_000).rounded())) - writer.framesWritten
var chunk: AVAudioPCMBuffer? = buffer
if drift > Self.driftTolerance { // real gap pad to realign
let padded = writer.padSilence(drift)
if padded > 0 { vad.feedSilence(padded) }
} else if drift < -Self.driftTolerance { // far ahead trim overlap
let trim = Int(-drift)
if trim >= Int(buffer.frameLength) { return }
chunk = Self.trimFront(buffer, by: trim)
}
let startIdx = max(0, Int(writer.framesWritten - expected))
if startIdx >= Int(buffer.frameLength) { return }
guard let chunk = Self.trimFront(buffer, by: startIdx) else { return }
updateLevel(chunk, isMic: true)
if writer.write(chunk) > 0 { vad.feed(chunk) }
guard let out = chunk else { return }
updateLevel(out, isMic: true)
if writer.write(out) > 0 { vad.feed(out) }
}
private func ingestSystem(_ buffer: AVAudioPCMBuffer, startHost: Double) {
guard !tornDown, let writer = systemWriter else { return }
let expected = max(0, Int64(((startHost - t0Host) * 16_000).rounded()))
if expected > writer.framesWritten {
writer.padSilence(expected - writer.framesWritten)
let drift = max(0, Int64(((startHost - t0Host) * 16_000).rounded())) - writer.framesWritten
var chunk: AVAudioPCMBuffer? = buffer
if drift > Self.driftTolerance {
writer.padSilence(drift)
} else if drift < -Self.driftTolerance {
let trim = Int(-drift)
if trim >= Int(buffer.frameLength) { return }
chunk = Self.trimFront(buffer, by: trim)
}
let startIdx = max(0, Int(writer.framesWritten - expected))
if startIdx >= Int(buffer.frameLength) { return }
guard let chunk = Self.trimFront(buffer, by: startIdx) else { return }
updateLevel(chunk, isMic: false)
writer.write(chunk)
guard let out = chunk else { return }
updateLevel(out, isMic: false)
writer.write(out)
}
// MARK: - Mic (AVAudioEngine)