Skip to content

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.

Flow dictation: a sentence said once is pasted once

Claude6c3b8a85413c
diff --git a/NotchBuddy/Sources/App/DictationTranscript.swift b/NotchBuddy/Sources/App/DictationTranscript.swift
index cc85469d..1d42dc15 100644
--- a/NotchBuddy/Sources/App/DictationTranscript.swift
+++ b/NotchBuddy/Sources/App/DictationTranscript.swift
@@ -45,12 +45,17 @@ struct DictationTranscript: Equatable {
current = formatted
return
}
- // Earlier words the new result left out, that no new word covers: put them back.
+ // Earlier words the new result left out, that no new word covers: put them back. Only words
+ // that had a time of their own (partial results often come without), and never words the new
+ // text already says (times can shift between results).
let kept = pieces.filter { old in
- old.end <= last.start + Self.tolerance
+ old.end > old.start
+ && old.end <= last.start + Self.tolerance
&& !new.contains { Self.close(old, $0) }
}
- if kept.isEmpty {
+ let alreadySaid = !kept.isEmpty
+ && Self.normalized(formatted).contains(Self.normalized(kept.map(\.text).joined(separator: " ")))
+ if kept.isEmpty || alreadySaid {
pieces = new
current = formatted
} else {
@@ -72,6 +77,12 @@ struct DictationTranscript: Equatable {
return p[0].lowercased() != n[0].lowercased()
}
+ /// Lowercase letters and digits, single spaces: "Salut, Coucou !" → "salut coucou".
+ static func normalized(_ s: String) -> String {
+ let kept = s.lowercased().map { $0.isLetter || $0.isNumber ? $0 : " " }
+ return String(kept).split(whereSeparator: \.isWhitespace).joined(separator: " ")
+ }
+
private static func close(_ a: Piece, _ b: Piece) -> Bool {
a.start < b.end + tolerance && b.start < a.end + tolerance
}
diff --git a/tests/FlowKeyLogicTests.swift b/tests/FlowKeyLogicTests.swift
index 746af5e9..65b54465 100644
--- a/tests/FlowKeyLogicTests.swift
+++ b/tests/FlowKeyLogicTests.swift
@@ -133,6 +133,20 @@ enum FlowKeyLogicTests {
check("untimed growth", u.text == "hello there my friend how are you")
u.absorb("great")
check("untimed fresh start", u.text == "hello there my friend how are you great")
+ // Partial results without times, then a final result with times: nothing doubled.
+ var f = DictationTranscript()
+ f.absorb("Salut coucou", pieces: [P(start: 0, end: 0, text: "Salut"), P(start: 0, end: 0, text: "coucou")])
+ f.absorb("Salut coucou comment tu vas", pieces: ["Salut", "coucou", "comment", "tu", "vas"].map { P(start: 0, end: 0, text: $0) })
+ f.absorb("Salut coucou comment tu vas", pieces: words([(0.6, "Salut"), (1.0, "coucou"), (1.5, "comment"), (1.9, "tu"), (2.1, "vas")]))
+ check("untimed partials then a timed final: said once", f.text == "Salut coucou comment tu vas")
+
+ // Times that move a lot between results, same words: said once.
+ var g = DictationTranscript()
+ g.absorb("Salut coucou comment tu vas", pieces: words([(0.0, "Salut"), (0.4, "coucou"), (0.8, "comment"), (1.1, "tu"), (1.3, "vas")]))
+ g.absorb("Salut, coucou, comment tu vas ?", pieces: words([(2.0, "Salut,"), (2.4, "coucou,"), (2.8, "comment"), (3.1, "tu"), (3.3, "vas ?")]))
+ check("same words at other times: said once", g.text == "Salut, coucou, comment tu vas ?")
+ check("normalized", DictationTranscript.normalized("Salut, Coucou !") == "salut coucou")
+
check("a short correction is not a fresh start", !DictationTranscript.isRestart(previous: "one two three four", new: "one two"))
check("too little text to call it a fresh start", !DictationTranscript.isRestart(previous: "one two", new: "three"))
}