A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
voice: room to think — longer pauses, "euhhh" keeps the turn open, names in answers
Claude1730e47efd67
diff --git a/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift b/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swiftindex 4131c0a0..a93dca21 100644--- a/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift+++ b/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift@@ -6,13 +6,17 @@ import Foundation// Decides silence duration before ending a command turn.// Standalone compilable (used by test scripts via swiftc).enum TurnEndPolicy {- static let baseSilence: TimeInterval = 1.2- static let extendedSilence: TimeInterval = 2.2+ static let baseSilence: TimeInterval = 1.6+ static let extendedSilence: TimeInterval = 2.6+ /// Answers Coucou asked for in free text (who, subject, what the mail says, what to+ /// look up): room to think, a 2–3 s pause doesn't cut me off.+ static let answerSilence: TimeInterval = 3.2static let maxTurnTime: TimeInterval = 15.0/// Returns the silence timeout given the current *normalised* partial transcript./// Call with `IntentParser.normalise(rawTranscript)`.- static func silenceDelay(for transcript: String) -> TimeInterval {+ static func silenceDelay(for transcript: String, longAnswer: Bool = false) -> TimeInterval {+ if longAnswer { return answerSilence }guard !transcript.trimmingCharacters(in: .whitespaces).isEmpty else {return baseSilence}@@ -33,6 +37,9 @@ enum TurnEndPolicy {"et", "puis", "ensuite", "mais", "ou",// EN conjunctions"and", "then", "but", "or",+ // Thinking out loud ("euh…", "hmm", "genre")+ "euh", "heu", "hum", "hmm", "mmm", "bah", "ben", "bon", "genre", "enfin", "attends",+ "um", "uh", "uhm", "erm", "er", "like", "well", "wait",// FR articles / prepositions"de", "du", "le", "la", "les", "des", "un", "une","a", "au", "aux", "sur", "dans", "avec", "pour",diff --git a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swiftindex 0d6b9c89..bf60f8e5 100644--- a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift@@ -462,6 +462,16 @@ final class VoiceActionRunner {return false}+ /// The answer Coucou waits for is free text (who, subject, what the mail says, what to+ /// look up): the mic gives more time to pause and think before the turn ends.+ var expectsLongAnswer: Bool {+ switch pendingQuestion?.kind {+ case .mailStep(let field)?: return field != .attachment+ case .webQuery?: return true+ default: return false+ }+ }+/// True while Coucou waits for any answer of the voice email (who, subject, text, file).var isMailInProgress: Bool {if case .mailStep? = pendingQuestion?.kind { return true }@@ -548,7 +558,8 @@ final class VoiceActionRunner {private func answerMail(_ field: PendingVoiceQuestion.MailField, _ transcript: String,pending: PendingVoiceQuestion) async -> VoiceActionResult {guard var m = mail else { return fail("voice.unknown") }- let said = transcript.trimmingCharacters(in: .whitespacesAndNewlines)+ // "image image": the same answer said twice in one turn counts once.+ let said = VoiceQuery.collapseRepeat(transcript.trimmingCharacters(in: .whitespacesAndNewlines))if said.isEmpty {// Silence after "any attachment?" means none; anywhere else it cancels the mail.diff --git a/NotchBuddy/Sources/App/Voice/VoiceAudio.swift b/NotchBuddy/Sources/App/Voice/VoiceAudio.swiftindex 4777215a..fc7cfbcf 100644--- a/NotchBuddy/Sources/App/Voice/VoiceAudio.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceAudio.swift@@ -49,6 +49,10 @@ final class VoiceAudio: @unchecked Sendable {/// Read on main for stall detection — nonisolated for cross-thread access.nonisolated(unsafe) private(set) var lastBufferTime: Date = .distantPast+ /// Last time the mic heard a voice-like sound while a command was being listened to+ /// ("euhhh" included, which the recognizer doesn't write down). Read on main.+ nonisolated(unsafe) private(set) var lastVoicedTime: Date = .distantPast+/// When true, every audio buffer is delivered via `onBuffer` regardless of VAD.nonisolated(unsafe) var bypassVAD: Bool = false@@ -166,6 +170,7 @@ final class VoiceAudio: @unchecked Sendable {if bypassVAD {onBuffer?(deliverBuf, time)let power = buf.meanSquarePower // raw format for accuracy+ if power > vad.noisePower * 5 { lastVoicedTime = Date() }smoothedLevel = smoothedLevel * 0.6 + power * 0.4levelFrameCount += 1if levelFrameCount % 2 == 0 {@@ -176,6 +181,7 @@ final class VoiceAudio: @unchecked Sendable {}let power = buf.meanSquarePower // raw format for accuracy+ if power > vad.noisePower * 5 { lastVoicedTime = Date() }let event = vad.feed(power)switch event {diff --git a/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift b/NotchBuddy/Sources/App/Voice/VoiceDataSources.swiftindex 8a0ed490..c7daeccf 100644--- a/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift@@ -318,9 +318,16 @@ enum ContactLookup {return await Task.detached(priority: .userInitiated) { () -> String? inlet keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactNicknameKey,CNContactEmailAddressesKey] as [CNKeyDescriptor]- let pred = CNContact.predicateForContacts(matchingName: trimmed)- let found = (try? CNContactStore().unifiedContacts(matching: pred, keysToFetch: keys)) ?? []- return found.lazy.compactMap { $0.emailAddresses.first?.value as String? }.first+ // The whole name first, then its parts: "il s'appelle Enzo" must find Enzo.+ let store = CNContactStore()+ for candidate in VoiceQuery.contactCandidates(trimmed) {+ let pred = CNContact.predicateForContacts(matchingName: candidate)+ let found = (try? store.unifiedContacts(matching: pred, keysToFetch: keys)) ?? []+ if let email = found.lazy.compactMap({ $0.emailAddresses.first?.value as String? }).first {+ return email+ }+ }+ return nil}.value}}diff --git a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift b/NotchBuddy/Sources/App/Voice/VoiceEngine.swiftindex 4a11aeb7..c7f4cbf8 100644--- a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift@@ -55,6 +55,7 @@ final class VoiceEngine: ObservableObject {// Command session timersprivate var silenceWork: DispatchWorkItem?private var commandMaxWork: DispatchWorkItem?+ private var loggedDropWhileSpeaking = falseprivate var wakeWindowWork: DispatchWorkItem? // 20 s periodic restartprivate var lastWordCount = 0@@ -166,6 +167,7 @@ final class VoiceEngine: ObservableObject {commandTranscript = ""lastWordCount = 0directInitialTimeout = firstWordTimeout+ loggedDropWhileSpeaking = falseaudio.bypassVAD = trueduckMusic()appendAppLog("nb.log", "[Voice] direct listen start (firstWordTimeout: \(firstWordTimeout)s)")@@ -608,7 +610,14 @@ final class VoiceEngine: ObservableObject {private func commandUpdate(_ command: String) {// Semi-duplex: ignore updates while Coucou is speaking.- guard !VoiceSpeaker.shared.isBusy else { return }+ guard !VoiceSpeaker.shared.isBusy else {+ // Logged once per turn (no words): helps when an answer seems unheard.+ if !loggedDropWhileSpeaking {+ loggedDropWhileSpeaking = true+ appendAppLog("nb.log", "[Voice] words heard while Coucou was speaking: ignored")+ }+ return+ }// The recognizer often repeats the same partial: no update, no re-render.guard command != commandTranscript else { return }commandTranscript = command@@ -638,13 +647,28 @@ final class VoiceEngine: ObservableObject {if lastWordCount == 0 {timeout = directInitialTimeout} else {- timeout = TurnEndPolicy.silenceDelay(for: WakePhrase.normalise(commandTranscript))+ timeout = TurnEndPolicy.silenceDelay(for: WakePhrase.normalise(commandTranscript),+ longAnswer: VoiceActionRunner.shared.expectsLongAnswer)}+ scheduleSilenceCheck(after: timeout)+ }++ /// The turn ends after the silence delay, unless I'm still making sound (an "euhhh"+ /// while thinking gives no words but is not silence): then it waits a bit more. The+ /// command's max duration still applies.+ private func scheduleSilenceCheck(after delay: TimeInterval) {let item = DispatchWorkItem { [weak self] in- Task { @MainActor in self?.endCommand(postFinished: true) }+ Task { @MainActor in+ guard let self, self.isListeningForCommand else { return }+ if let a = self.audio, Date().timeIntervalSince(a.lastVoicedTime) < 0.5 {+ self.scheduleSilenceCheck(after: 0.5)+ } else {+ self.endCommand(postFinished: true)+ }+ }}silenceWork = item- DispatchQueue.main.asyncAfter(deadline: .now() + timeout, execute: item)+ DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: item)}/// Idempotent: if not in command mode, only cancels timers.diff --git a/NotchBuddy/Sources/App/Voice/VoiceQuery.swift b/NotchBuddy/Sources/App/Voice/VoiceQuery.swiftindex be3d2639..72a7c168 100644--- a/NotchBuddy/Sources/App/Voice/VoiceQuery.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceQuery.swift@@ -226,11 +226,45 @@ enum VoiceQuery {/// "c'est Tana", "à tana arobase gmail point com", "send it to Paul" → "Tana" / "[email protected]" / "Paul".static func recipientAnswer(_ raw: String) -> String {var t = stripLead(raw, ["envoie le à", "envoie-le à", "envoie la à", "envoie-la à", "send it to", "it's for",+ "il s'appelle", "elle s'appelle", "ils s'appellent", "elles s'appellent", "s'appelle",+ "son nom c'est", "son nom est", "son prénom c'est", "son prénom est", "son mail c'est",+ "son adresse c'est", "son adresse mail c'est", "son email c'est", "mon ami", "mon amie",+ "mon pote", "ma pote", "mon frère", "ma sœur", "ma soeur",+ "his name is", "her name is", "their name is", "the name is", "name is",+ "his email is", "her email is", "it's called", "called","c'est pour", "c'est", "c est", "it's", "its", "to", "à", "a", "pour", "for", "the", "le", "la"])t = t.trimmingCharacters(in: CharacterSet(charactersIn: " .,;:!?"))return spokenEmail(t) ?? t}+ /// "image image" → "image", "Paul Dupont Paul Dupont" → "Paul Dupont": an answer said+ /// twice in the same turn (the first time looked unheard) counts once.+ static func collapseRepeat(_ raw: String) -> String {+ let words = raw.split(separator: " ").map(String.init)+ guard words.count >= 2, words.count % 2 == 0 else { return raw }+ let half = words.count / 2+ let a = IntentParser.normalise(words[..<half].joined(separator: " "))+ let b = IntentParser.normalise(words[half...].joined(separator: " "))+ return a == b && !a.isEmpty ? words[..<half].joined(separator: " ") : raw+ }++ /// Names to try in the contacts for a spoken recipient: the whole of it, then its+ /// capitalised words, then each word ("le pote Enzo" → "Enzo").+ static func contactCandidates(_ raw: String) -> [String] {+ let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines.union(.punctuationCharacters))+ guard !trimmed.isEmpty else { return [] }+ let words = trimmed.split(separator: " ").map(String.init)+ let stop: Set<String> = ["le", "la", "les", "l", "de", "du", "des", "mon", "ma", "mes", "ami", "amie", "pote",+ "c", "est", "il", "elle", "s", "appelle", "the", "my", "friend", "is", "name", "his",+ "her", "a", "à", "et", "and"]+ var out = [trimmed]+ let caps = words.filter { $0.first?.isUppercase == true && !stop.contains(IntentParser.normalise($0)) }+ if !caps.isEmpty { out.append(caps.joined(separator: " ")) }+ for w in words.reversed() where w.count >= 2 && !stop.contains(IntentParser.normalise(w)) { out.append(w) }+ var seen = Set<String>()+ return out.filter { seen.insert($0.lowercased()).inserted }+ }+/// "l'objet c'est Voilà votre image" → "Voilà votre image"; "pas d'objet" / "no subject" → "".static func subjectAnswer(_ raw: String) -> String {let n = IntentParser.normalise(raw)diff --git a/tests/TurnEndPolicyTests.swift b/tests/TurnEndPolicyTests.swiftindex 0b8cea33..23e84752 100644--- a/tests/TurnEndPolicyTests.swift+++ b/tests/TurnEndPolicyTests.swift@@ -32,8 +32,12 @@ enum TurnEndPolicyTests {"complete command → baseSilence")// Constants- precondition(TurnEndPolicy.baseSilence == 1.2, "baseSilence == 1.2")- precondition(TurnEndPolicy.extendedSilence == 2.2, "extendedSilence == 2.2")+ precondition(TurnEndPolicy.baseSilence == 1.6, "baseSilence == 1.6")+ precondition(TurnEndPolicy.extendedSilence == 2.6, "extendedSilence == 2.6")+ precondition(TurnEndPolicy.silenceDelay(for: "l objet c est", longAnswer: true) == TurnEndPolicy.answerSilence,+ "free-text answer → answerSilence")+ precondition(TurnEndPolicy.silenceDelay(for: "mets euh") == TurnEndPolicy.extendedSilence,+ "ends with 'euh' → extendedSilence")precondition(TurnEndPolicy.maxTurnTime == 15.0, "maxTurnTime == 15.0")print("TurnEndPolicyTests: all cases passed")diff --git a/tests/VoiceQueryTests.swift b/tests/VoiceQueryTests.swiftindex 391a1f11..cfdcd3da 100644--- a/tests/VoiceQueryTests.swift+++ b/tests/VoiceQueryTests.swift@@ -107,6 +107,15 @@ struct VoiceQueryTests {check("open Safari", VoiceQuery.appToOpen("open Safari"), "Safari")check("parse open app", IntentParser.parse("ouvre Figma", pills: pills), .openApp(name: "Figma"))+ // Guided mail: names and repeats+ check("recipient il s'appelle", VoiceQuery.recipientAnswer("Il s'appelle Enzo"), "Enzo")+ check("recipient son nom c'est", VoiceQuery.recipientAnswer("son nom c'est Enzo Martin"), "Enzo Martin")+ check("recipient his name is", VoiceQuery.recipientAnswer("his name is Paul"), "Paul")+ check("contact candidates", VoiceQuery.contactCandidates("mon pote Enzo"), ["mon pote Enzo", "Enzo"])+ check("collapse repeat", VoiceQuery.collapseRepeat("image image"), "image")+ check("collapse repeat two words", VoiceQuery.collapseRepeat("Voilà l'image voilà l'image"), "Voilà l'image")+ check("no collapse", VoiceQuery.collapseRepeat("bonjour Enzo"), "bonjour Enzo")+// Web searchcheck("web fr lead", VoiceQuery.webQuery(of: "cherche sur internet qui a gagné l'Euro"), "qui a gagné l'Euro")check("web fr tail", VoiceQuery.webQuery(of: "Cherche les horaires du Louvre sur internet"), "les horaires du Louvre")