Skip to content

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

prallelize snapshot and transcription

grohith3274cb6683f3758
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index 5912482a..853dfefe 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -1634,7 +1634,8 @@ struct ContentView: View {
private func deliverSpokenSend(
_ outputPlan: DictationLiteralOutputPlan,
targetPID: pid_t?,
- textReadyAt: TimeInterval
+ textReadyAt: TimeInterval,
+ preserveTranscriptOnClipboard: Bool
) async -> TypingService.DeliveryOutcome {
let sendsExistingDraft = outputPlan.plainText.isEmpty
let outcome = await self.asr.typeOutputPlanToActiveFieldAndWait(
@@ -1642,7 +1643,8 @@ struct ContentView: View {
preferredTargetPID: targetPID,
textReadyAt: textReadyAt,
postInsertionKey: self.settings.spokenSendKey,
- requiredFocusTarget: self.recordingFocusTarget
+ requiredFocusTarget: self.recordingFocusTarget,
+ preserveTranscriptOnClipboard: preserveTranscriptOnClipboard
)
if outcome.didDispatchAction {
NotchContentState.shared.setSpokenSendIndicatorState(.sent)
@@ -2461,7 +2463,8 @@ struct ContentView: View {
let deliveryOutcome = await self.deliverSpokenSend(
finalOutputPlan,
targetPID: typingTarget.pid,
- textReadyAt: finalTextReadyAt
+ textReadyAt: finalTextReadyAt,
+ preserveTranscriptOnClipboard: shouldCopyToClipboard
)
didTypeExternally = deliveryOutcome.didInsert
deliveryResult = deliveryOutcome.didInsert || deliveryOutcome.didDispatchAction
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index 66120e5c..0ed4090e 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -79,7 +79,9 @@ final class SettingsStore: ObservableObject {
case llama
case mlx
- var id: String { self.rawValue }
+ var id: String {
+ self.rawValue
+ }
/// Default backend when no preference is stored.
/// Apple Silicon → MLX (fastest Fluid-1 path). Intel → llama.cpp.
@@ -204,7 +206,9 @@ final class SettingsStore: ObservableObject {
let uid: String
var name: String
- var id: String { self.uid }
+ var id: String {
+ self.uid
+ }
}
enum DictationPromptSelection: Equatable {
@@ -1821,7 +1825,9 @@ final class SettingsStore: ObservableObject {
/// Direct Core Audio is the required capture backend. Legacy persisted
/// preferences are intentionally ignored because AVAudioEngine can block or
/// crash while audio devices are changing.
- var experimentalDirectAudioCaptureEnabled: Bool { true }
+ var experimentalDirectAudioCaptureEnabled: Bool {
+ true
+ }
var copyTranscriptionToClipboard: Bool {
get { self.defaults.bool(forKey: Keys.copyTranscriptionToClipboard) }
@@ -4092,7 +4098,9 @@ final class SettingsStore: ObservableObject {
case tab
case space
- var id: Self { self }
+ var id: Self {
+ self
+ }
var title: String {
switch self {
@@ -4127,7 +4135,9 @@ final class SettingsStore: ObservableObject {
var aliases: [String]
var isEnabled: Bool
- var id: SpokenFormattingAction { self.action }
+ var id: SpokenFormattingAction {
+ self.action
+ }
init(action: SpokenFormattingAction, aliases: [String], isEnabled: Bool = true) {
self.action = action
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swift
index cf9a9785..1c85d964 100644
--- a/Sources/Fluid/Services/ASRService.swift
+++ b/Sources/Fluid/Services/ASRService.swift
@@ -3953,10 +3953,14 @@ final class ASRService: ObservableObject {
)
let priorityUIDs = SettingsStore.shared.microphonePriority.map(\.uid)
let livenessRequiresRecovery =
- (self.isRunning &&
- resolvedInput?.uid != microphonePreferenceCoordinator.confirmedActiveInputUID) ||
- (self.hasPreparedAudioCapture &&
- resolvedInput?.id != self.directAudioLifecycleController.snapshot.deviceID)
+ (
+ self.isRunning &&
+ resolvedInput?.uid != microphonePreferenceCoordinator.confirmedActiveInputUID
+ ) ||
+ (
+ self.hasPreparedAudioCapture &&
+ resolvedInput?.id != self.directAudioLifecycleController.snapshot.deviceID
+ )
let shouldReconcileInputSelection = AudioCaptureIdlePolicy.shouldReconcileInputSelection(
priorityInputUIDs: priorityUIDs,
migrationPending: migrationPending,
@@ -4898,7 +4902,8 @@ final class ASRService: ObservableObject {
textReadyAt: TimeInterval? = nil,
tracksDictionaryCorrections: Bool = false,
postInsertionKey: SettingsStore.SpokenSendKey? = nil,
- requiredFocusTarget: TypingService.CapturedFocusTarget? = nil
+ requiredFocusTarget: TypingService.CapturedFocusTarget? = nil,
+ preserveTranscriptOnClipboard: Bool = false
) async -> TypingService.DeliveryOutcome {
let requestedAt = ProcessInfo.processInfo.systemUptime
let textReadyAge = textReadyAt.map { Int(((requestedAt - $0) * 1000).rounded()) }
@@ -4915,7 +4920,8 @@ final class ASRService: ObservableObject {
textReadyAt: textReadyAt,
tracksDictionaryCorrections: tracksDictionaryCorrections,
postInsertionKey: postInsertionKey,
- requiredFocusTarget: requiredFocusTarget
+ requiredFocusTarget: requiredFocusTarget,
+ preserveTranscriptOnClipboard: preserveTranscriptOnClipboard
) { outcome in
continuation.resume(returning: outcome)
}
diff --git a/Sources/Fluid/Services/PasteDeliveryCoordinator.swift b/Sources/Fluid/Services/PasteDeliveryCoordinator.swift
index 86b96d10..7880106d 100644
--- a/Sources/Fluid/Services/PasteDeliveryCoordinator.swift
+++ b/Sources/Fluid/Services/PasteDeliveryCoordinator.swift
@@ -80,6 +80,7 @@ final class SystemPasteboardManager: PasteboardManaging {
}
func captureSnapshot() -> PasteboardSnapshot? {
+ let startedAt = ProcessInfo.processInfo.systemUptime
for attempt in 1...2 {
let startingChangeCount = self.pasteboard.changeCount
guard let sourceItems = self.pasteboard.pasteboardItems else {
@@ -102,6 +103,7 @@ final class SystemPasteboardManager: PasteboardManaging {
}
var items: [PasteboardSnapshot.Item] = []
var totalBytes = 0
+ var totalPortableImageBytes = 0
var totalRepresentations = 0
var failure: (reason: String, itemIndex: Int, type: NSPasteboard.PasteboardType?)?
@@ -124,10 +126,12 @@ final class SystemPasteboardManager: PasteboardManaging {
totalRepresentations += 1
}
let item = PasteboardSnapshot.Item(representations: representations)
+ let portableImage = Self.portableImageRepresentation(for: item)
+ totalPortableImageBytes += portableImage?.data.count ?? 0
items.append(
.init(
representations: representations,
- portableImage: Self.portableImageRepresentation(for: item)
+ portableImage: portableImage
)
)
}
@@ -154,7 +158,9 @@ final class SystemPasteboardManager: PasteboardManaging {
}
self.log(
- "clipboard_snapshot_complete items=\(items.count) representations=\(totalRepresentations) bytes=\(totalBytes) firstItem=\(Self.representationSummary(items.first))"
+ "clipboard_snapshot_complete items=\(items.count) representations=\(totalRepresentations) " +
+ "bytes=\(totalBytes) portableImageBytes=\(totalPortableImageBytes) " +
+ "elapsedMs=\(Self.elapsedMs(since: startedAt)) firstItem=\(Self.representationSummary(items.first))"
)
return PasteboardSnapshot(items: items)
}
@@ -309,11 +315,17 @@ final class SystemPasteboardManager: PasteboardManaging {
if !sourceTypes.isDisjoint(with: Self.fileSemanticTypes) {
guard Self.fileItemContainsImage(item) else { return nil }
+ // Preserve an image file's encoded bytes directly. Decoding and re-encoding it
+ // here would put work proportional to its pixel count on the paste critical path.
if let fileURL = Self.fileURL(in: item),
- let image = NSImage(contentsOf: fileURL),
- let pngData = Self.pngData(from: image)
+ let fileType = UTType(filenameExtension: fileURL.pathExtension),
+ fileType.conforms(to: .image),
+ let imageData = try? Data(contentsOf: fileURL, options: .mappedIfSafe)
{
- return .init(type: .png, data: pngData)
+ return .init(
+ type: NSPasteboard.PasteboardType(fileType.identifier),
+ data: imageData
+ )
}
}
@@ -329,8 +341,8 @@ final class SystemPasteboardManager: PasteboardManaging {
}
private static func fileItemContainsImage(_ item: PasteboardSnapshot.Item) -> Bool {
- if let fileURL = Self.fileURL(in: item),
- Self.isImageFilename(fileURL.lastPathComponent)
+ if let fileURL = fileURL(in: item),
+ isImageFilename(fileURL.lastPathComponent)
{
return true
}
@@ -430,6 +442,10 @@ final class SystemPasteboardManager: PasteboardManaging {
private func log(_ message: String) {
DebugLogger.shared.benchmark("TYPING_BENCH", message: message, source: "TypingBenchmark")
}
+
+ private static func elapsedMs(since start: TimeInterval) -> Int {
+ Int(((ProcessInfo.processInfo.systemUptime - start) * 1000).rounded())
+ }
}
@MainActor
@@ -491,8 +507,6 @@ enum KeyboardLayoutKeyCodeResolver {
@MainActor
final class SystemPasteCommandPoster: PasteCommandPosting {
- nonisolated static let clipboardSettleDelayNanoseconds: UInt64 = 50_000_000
-
func postGlobalPasteCommand() async -> Bool {
guard AXIsProcessTrusted() else { return false }
@@ -513,8 +527,8 @@ final class SystemPasteCommandPoster: PasteCommandPosting {
vDown.flags = .maskCommand
vUp.flags = .maskCommand
- // Match Muesli's publication delay and two-event Command+V sequence.
- try? await Task.sleep(nanoseconds: Self.clipboardSettleDelayNanoseconds)
+ // The coordinator verifies pasteboard ownership before reaching this point,
+ // so the temporary item is ready to consume without an additional delay.
vDown.post(tap: .cghidEventTap)
vUp.post(tap: .cghidEventTap)
return true
diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swift
index a4a8a49f..01262a22 100644
--- a/Sources/Fluid/Services/TypingService.swift
+++ b/Sources/Fluid/Services/TypingService.swift
@@ -73,8 +73,8 @@ final class TypingService {
return !isSecureTextField && exactFocusIsActive
}
- // Logging toggle (off by default). Enable by setting env FLUID_TYPING_LOGS=1
- // or UserDefaults bool for key "enableTypingLogs".
+ /// Logging toggle (off by default). Enable by setting env FLUID_TYPING_LOGS=1
+ /// or UserDefaults bool for key "enableTypingLogs".
private nonisolated static var isLoggingEnabled: Bool {
if let env = ProcessInfo.processInfo.environment["FLUID_TYPING_LOGS"], env == "1" { return true }
return UserDefaults.standard.bool(forKey: "enableTypingLogs")
@@ -498,6 +498,7 @@ final class TypingService {
tracksDictionaryCorrections: Bool = false,
postInsertionKey: SettingsStore.SpokenSendKey? = nil,
requiredFocusTarget: CapturedFocusTarget? = nil,
+ preserveTranscriptOnClipboard: Bool = false,
completion: ((DeliveryOutcome) -> Void)? = nil
) {
Task { @MainActor in
@@ -527,7 +528,8 @@ final class TypingService {
plan,
preferredTargetPID: preferredTargetPID,
textReadyAt: textReadyAt,
- tracksDictionaryCorrections: tracksDictionaryCorrections
+ tracksDictionaryCorrections: tracksDictionaryCorrections,
+ preserveTranscriptOnClipboard: preserveTranscriptOnClipboard
)
guard result.wasDispatched else {
completion?(.insertionFailed)
@@ -1200,7 +1202,7 @@ final class TypingService {
return true
}
- // Why is it working now? And why is it not working now?
+ /// Why is it working now? And why is it not working now?
private nonisolated func setTextViaValue(_ element: AXUIElement, _ text: String) -> Bool {
let cfText = text as CFString
let result = AXUIElementSetAttributeValue(element, kAXValueAttribute as CFString, cfText)
@@ -1250,5 +1252,4 @@ final class TypingService {
return false
}
}
-
}
diff --git a/Sources/Fluid/Views/NotchContentViews.swift b/Sources/Fluid/Views/NotchContentViews.swift
index e5e534ce..a2c28101 100644
--- a/Sources/Fluid/Views/NotchContentViews.swift
+++ b/Sources/Fluid/Views/NotchContentViews.swift
@@ -774,7 +774,6 @@ struct NotchExpandedView: View {
)
}
- @ViewBuilder
private func promptMenuRow(
_ title: String,
rowID: String,
@@ -1251,7 +1250,6 @@ struct NotchWaveformView: View {
}
}
- @ViewBuilder
private func barsView(using height: @escaping (Int) -> CGFloat) -> some View {
HStack(spacing: self.barSpacing) {
ForEach(0..<self.barCount, id: \.self) { index in
@@ -1981,7 +1979,6 @@ struct CompactNotchWaveformView: View {
}
}
- @ViewBuilder
private func barsView(using height: @escaping (Int) -> CGFloat) -> some View {
HStack(spacing: self.barSpacing) {
ForEach(0..<self.barCount, id: \.self) { index in
diff --git a/Sources/Fluid/Views/RewriteModeView.swift b/Sources/Fluid/Views/RewriteModeView.swift
index eaf92246..1f6a5682 100644
--- a/Sources/Fluid/Views/RewriteModeView.swift
+++ b/Sources/Fluid/Views/RewriteModeView.swift
@@ -3,7 +3,10 @@ import SwiftUI
struct RewriteModeView: View {
@ObservedObject var service: RewriteModeService
@EnvironmentObject var appServices: AppServices
- private var asr: ASRService { self.appServices.asr }
+ private var asr: ASRService {
+ self.appServices.asr
+ }
+
@ObservedObject var settings = SettingsStore.shared
@EnvironmentObject var menuBarManager: MenuBarManager
@Environment(\.theme) private var theme
@@ -15,7 +18,7 @@ struct RewriteModeView: View {
@State private var isHoveringHowTo: Bool = false
@State private var isThinkingExpanded: Bool = false
- // Local state for available models (derived from shared AI Settings pool)
+ /// Local state for available models (derived from shared AI Settings pool)
@State private var availableModels: [String] = []
var body: some View {
diff --git a/Tests/FluidDictationIntegrationTests/PasteDeliveryCoordinatorTests.swift b/Tests/FluidDictationIntegrationTests/PasteDeliveryCoordinatorTests.swift
index 2ffcefb4..53479c86 100644
--- a/Tests/FluidDictationIntegrationTests/PasteDeliveryCoordinatorTests.swift
+++ b/Tests/FluidDictationIntegrationTests/PasteDeliveryCoordinatorTests.swift
@@ -225,8 +225,7 @@ final class PasteDeliveryCoordinatorTests: XCTestCase {
XCTAssertEqual(pasteboard.restoreCount, 1)
}
- func testPasteTimingMatchesMuesli() {
- XCTAssertEqual(SystemPasteCommandPoster.clipboardSettleDelayNanoseconds, 50_000_000)
+ func testClipboardRestorationUsesHalfSecondDelay() {
XCTAssertEqual(PasteDeliveryCoordinator.defaultSettlementDelayNanoseconds, 500_000_000)
}
diff --git a/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift b/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift
index 8541cd86..36b479fa 100644
--- a/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift
+++ b/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift
@@ -284,6 +284,7 @@ final class TypingServiceTransientPasteboardTests: XCTestCase {
XCTAssertEqual(restoredItem.string(forType: .fileURL), imageURL.absoluteString)
XCTAssertEqual(restoredItem.data(forType: icnsType), iconData)
XCTAssertNotEqual(restoredItem.data(forType: .png), iconData)
+ XCTAssertEqual(restoredItem.data(forType: .png), sourceImageData)
let restoredPNG = try XCTUnwrap(restoredItem.data(forType: .png))
let restoredBitmap = try XCTUnwrap(NSBitmapImageRep(data: restoredPNG))