Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more
fix: separate continuous dictation segments
altic-dev9410f4ed7e2e
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex a625b4c8..7c9bf61b 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -2943,27 +2943,36 @@ final class ASRService: ObservableObject {let precedingTrimmed = precedingText.trimmingCharacters(in: .whitespacesAndNewlines)if precedingTrimmed.isEmpty {- // Empty field = sentence start: capitalize first alphabetic character.- if let first = result.first, first.isLetter, first.isLowercase {- result = first.uppercased() + result.dropFirst()- }+ result = self.replacingFirstLetter(in: result, transform: { $0.uppercased() })} else if let lastChar = precedingTrimmed.last, lastChar.isLetter || lastChar.isNumber {// Last char before cursor is alphanumeric (no terminal punctuation): lowercase the// first character so this segment flows inline with the existing text.- if let first = result.first, first.isUppercase {- result = first.lowercased() + result.dropFirst()- }+ result = self.replacingFirstLetter(in: result, transform: { $0.lowercased() })}// If preceding text ends with .!? (or any other punctuation), leave the model's// capitalization as-is (sentence start).- // Append a trailing space so the next dictation chains without a manual spacebar press.- if !result.hasSuffix(" ") {+ // Add a separator when continuing after existing inline text, then leave a trailing+ // space so the next dictation can chain without a manual spacebar press.+ if let lastPreceding = precedingText.last,+ !lastPreceding.isWhitespace,+ result.first?.isWhitespace != true+ {+ result = " " + result+ }++ if result.last?.isWhitespace != true {result += " "}return result}++ private static func replacingFirstLetter(in text: String, transform: (Character) -> String) -> String {+ guard let index = text.firstIndex(where: { $0.isLetter }) else { return text }+ let nextIndex = text.index(after: index)+ return String(text[..<index]) + transform(text[index]) + String(text[nextIndex...])+ }}// swiftlint:enable type_body_lengthdiff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swiftindex cf9b4ba0..cc54f186 100644--- a/Sources/Fluid/Services/TypingService.swift+++ b/Sources/Fluid/Services/TypingService.swift@@ -172,42 +172,8 @@ final class TypingService {/// Best-effort: returns the text immediately before the caret in the currently focused/// text field. Used by Continuous Dictation Mode to decide capitalization when chaining/// transcribed segments. Returns "" when the focused field/context is unavailable.- /// Low-resource: single AX round-trip with a range fallback; no polling, no timers.static func textBeforeCursorInFocusedField() -> String {- guard AXIsProcessTrusted() else { return "" }-- let systemWideElement = AXUIElementCreateSystemWide()- var focusedElementRef: CFTypeRef?- let result = AXUIElementCopyAttributeValue(- systemWideElement,- kAXFocusedUIElementAttribute as CFString,- &focusedElementRef- )- guard result == .success, let focusedElementRef else { return "" }- guard CFGetTypeID(focusedElementRef) == AXUIElementGetTypeID() else { return "" }- let element = unsafeBitCast(focusedElementRef, to: AXUIElement.self)-- var rangeRef: CFTypeRef?- let rangeResult = AXUIElementCopyAttributeValue(- element,- kAXSelectedTextRangeAttribute as CFString,- &rangeRef- )- guard rangeResult == .success, let rangeRef else { return "" }- guard CFGetTypeID(rangeRef) == AXValueGetTypeID() else { return "" }-- var range = CFRange()- guard AXValueGetValue(unsafeBitCast(rangeRef, to: AXValue.self), .cfRange, &range) else { return "" }- guard range.location != kCFNotFound, range.location >= 0 else { return "" }-- var valueRef: CFTypeRef?- let valueResult = AXUIElementCopyAttributeValue(element, kAXValueAttribute as CFString, &valueRef)- guard valueResult == .success, let fullText = valueRef as? String else { return "" }-- let nsText = fullText as NSString- let location = min(range.location, nsText.length)- guard location > 0 else { return "" }- return nsText.substring(with: NSRange(location: 0, length: location))+ TypingService().captureTextBeforeCursorInFocusedField()}@discardableResult@@ -1032,6 +998,32 @@ final class TypingService {)}+ private func captureTextBeforeCursorInFocusedField() -> String {+ guard let snapshot = self.captureFocusedTextSnapshot() else { return "" }++ let scriptRange = snapshot.appScriptSelectedRange ?? snapshot.selectedRange+ if let scriptValue = snapshot.appScriptValue,+ let scriptRange+ {+ return Self.prefix(in: scriptValue, before: scriptRange.location)+ }++ if let value = snapshot.value,+ let selectedRange = snapshot.selectedRange+ {+ return Self.prefix(in: value, before: selectedRange.location)+ }++ return ""+ }++ private static func prefix(in text: String, before location: Int) -> String {+ let nsText = text as NSString+ let safeLocation = max(0, min(location, nsText.length))+ guard safeLocation > 0 else { return "" }+ return nsText.substring(with: NSRange(location: 0, length: safeLocation))+ }+private struct AppScriptTextSnapshot {let value: String?let selectedRange: CFRange?