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
Add latency metrics for chunk processing and post-processing
grohith327639e015872a5
diff --git a/Sources/Fluid/Analytics/AnalyticsEvent.swift b/Sources/Fluid/Analytics/AnalyticsEvent.swiftindex c284b331..e02767b2 100644--- a/Sources/Fluid/Analytics/AnalyticsEvent.swift+++ b/Sources/Fluid/Analytics/AnalyticsEvent.swift@@ -11,6 +11,8 @@ enum AnalyticsEvent: String {// Dictationcase transcriptionCompleted = "transcription_completed"+ case transcriptionChunkProcessed = "transcription_chunk_processed"+ case dictationPostProcessingCompleted = "dictation_post_processing_completed"case outputDelivered = "output_delivered"case postTranscriptionEdit = "post_transcription_edit"diff --git a/Sources/Fluid/Analytics/AnalyticsService.swift b/Sources/Fluid/Analytics/AnalyticsService.swiftindex 40ea39b2..6ae2242c 100644--- a/Sources/Fluid/Analytics/AnalyticsService.swift+++ b/Sources/Fluid/Analytics/AnalyticsService.swift@@ -1,3 +1,4 @@+import Darwinimport Foundation/// Lightweight analytics pipeline:@@ -8,6 +9,7 @@ final class AnalyticsService {static let shared = AnalyticsService()private let core = AnalyticsCore()+ private static let hardwarePropertiesSnapshot = AnalyticsService.buildHardwareProperties()private init() {}@@ -72,7 +74,7 @@ final class AnalyticsService {let settings = SettingsStore.shared- return [+ var properties: [String: Any] = ["app_version": version,"app_build": build,"os_version": osVersion,@@ -85,6 +87,76 @@ final class AnalyticsService {"press_and_hold_mode": settings.pressAndHoldMode,"copy_to_clipboard_enabled": settings.copyTranscriptionToClipboard,]++ for (key, value) in Self.hardwarePropertiesSnapshot {+ properties[key] = value+ }++ return properties+ }++ private static func buildHardwareProperties() -> [String: Any] {+ let architectureFamily = CPUArchitecture.isAppleSilicon ? "apple_silicon" : "intel"+ let cpuBrand = self.sysctlString("machdep.cpu.brand_string") ?? "unknown"+ let hardwareModel = self.sysctlString("hw.model") ?? "unknown"+ let chipFamily = self.normalizedChipFamily(cpuBrand: cpuBrand, architectureFamily: architectureFamily)++ return [+ "hardware_arch_family": architectureFamily,+ "hardware_chip_family": chipFamily,+ "hardware_model": hardwareModel,+ ]+ }++ private static func normalizedChipFamily(cpuBrand: String, architectureFamily: String) -> String {+ let normalizedBrand = cpuBrand.lowercased()+ let tokenized = normalizedBrand+ .split(whereSeparator: { $0.isWhitespace })+ .map { token in+ String(token.unicodeScalars.filter { CharacterSet.alphanumerics.contains($0) })+ }+ .filter { !$0.isEmpty }++ if architectureFamily == "apple_silicon" {+ if let familyTokenIndex = tokenized.firstIndex(where: { self.isAppleMSeriesToken($0) }) {+ let family = tokenized[familyTokenIndex]+ let tiers = Set(["pro", "max", "ultra"])+ if familyTokenIndex + 1 < tokenized.count {+ let tier = tokenized[familyTokenIndex + 1]+ if tiers.contains(tier) {+ return "\(family)_\(tier)"+ }+ }+ return family+ }+ return "apple_silicon_other"+ }++ if let intelTier = ["i9", "i7", "i5", "i3"].first(where: { tier in+ tokenized.contains(where: { $0.hasPrefix(tier) })+ }) {+ return "intel_\(intelTier)"+ }+ if tokenized.contains(where: { $0.contains("xeon") }) {+ return "intel_xeon"+ }+ return "intel_other"+ }++ private static func isAppleMSeriesToken(_ token: String) -> Bool {+ guard token.hasPrefix("m"), token.count > 1 else { return false }+ return token.dropFirst().allSatisfy(\.isNumber)+ }++ private static func sysctlString(_ name: String) -> String? {+ var size: size_t = 0+ guard sysctlbyname(name, nil, &size, nil, 0) == 0, size > 0 else { return nil }++ var buffer = [CChar](repeating: 0, count: size)+ guard sysctlbyname(name, &buffer, &size, nil, 0) == 0 else { return nil }++ let value = String(cString: buffer).trimmingCharacters(in: .whitespacesAndNewlines)+ return value.isEmpty ? nil : value}}diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex ce60630c..cad664ba 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -689,6 +689,14 @@ struct ContentView: View {return (provider: providerOut, model: modelOut)}+ private func currentTranscriptionModelInfo() -> (provider: String, model: String) {+ let selectedModel = SettingsStore.shared.selectedSpeechModel+ return (+ provider: selectedModel.provider.rawValue.lowercased(),+ model: selectedModel.rawValue+ )+ }+// MARK: - Mode Transition Handler/// Centralized handler for sidebar mode transitions to ensure proper cleanup and state management@@ -1714,9 +1722,13 @@ struct ContentView: View {// Check if we should use AI processinglet shouldUseAI = DictationAIPostProcessingGate.isConfigured()+ let transcriptionModelInfo = self.currentTranscriptionModelInfo()if shouldUseAI {DebugLogger.shared.debug("Routing transcription through AI post-processing", source: "ContentView")+ let postProcessingModelInfo = self.currentDictationAIModelInfo()+ let postProcessingInputChars = transcribedText.count+ let postProcessingStart = Date()// Update overlay text to show we're now refining (processing already true)NotchOverlayManager.shared.updateTranscriptionText("Refining...")@@ -1725,6 +1737,18 @@ struct ContentView: View {await Task.yield()finalText = await self.processTextWithAI(transcribedText)+ let postProcessingLatencyMs = Int((Date().timeIntervalSince(postProcessingStart) * 1000).rounded())+ AnalyticsService.shared.capture(+ .dictationPostProcessingCompleted,+ properties: [+ "latency_ms": postProcessingLatencyMs,+ "input_chars": postProcessingInputChars,+ "post_processing_provider": postProcessingModelInfo.provider ?? "unknown",+ "post_processing_model": postProcessingModelInfo.model ?? "unknown",+ "transcription_provider": transcriptionModelInfo.provider,+ "transcription_model": transcriptionModelInfo.model,+ ]+ )// Clear transient status text before leaving processing state to avoid// a brief non-shimmer "Refining..." preview flash.@@ -1752,6 +1776,8 @@ struct ContentView: View {"words_bucket": AnalyticsBuckets.bucketWords(AnalyticsBuckets.wordCount(in: finalText)),"ai_used": shouldUseAI,"ai_changed_text": transcribedText != finalText,+ "transcription_provider": transcriptionModelInfo.provider,+ "transcription_model": transcriptionModelInfo.model,])diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex c516a7ee..27f1ff19 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -259,6 +259,58 @@ final class ASRService: ObservableObject {self.transcriptionProvider}+ private func currentTranscriptionAnalyticsDimensions() -> (provider: String, model: String) {+ let selectedModel = SettingsStore.shared.selectedSpeechModel+ return (+ provider: selectedModel.provider.rawValue.lowercased(),+ model: selectedModel.rawValue+ )+ }++ private func streamingChunkErrorCategory(for error: Error) -> String {+ if error is CancellationError {+ return "cancelled"+ }++ let nsError = error as NSError+ switch nsError.domain {+ case AVFoundationErrorDomain:+ return "avfoundation"+ case NSOSStatusErrorDomain:+ return "osstatus"+ case NSCocoaErrorDomain:+ return "cocoa"+ default:+ return "other"+ }+ }++ private func captureStreamingChunkAnalytics(+ success: Bool,+ chunkSampleCount: Int,+ latencyMs: Int,+ error: Error? = nil+ ) {+ let dims = self.currentTranscriptionAnalyticsDimensions()+ var properties: [String: Any] = [+ "success": success,+ "latency_ms": latencyMs,+ "chunk_samples": chunkSampleCount,+ "chunk_audio_seconds": Double(chunkSampleCount) / 16_000.0,+ "transcription_provider": dims.provider,+ "transcription_model": dims.model,+ ]++ if let error {+ properties["error_category"] = self.streamingChunkErrorCategory(for: error)+ }++ AnalyticsService.shared.capture(+ .transcriptionChunkProcessed,+ properties: properties+ )+ }+/// Gets a provider for a specific model (without changing the active selection)/// Used for downloading models without switching the active model.private func getProvider(for model: SettingsStore.SpeechModel) -> TranscriptionProvider {@@ -2350,6 +2402,12 @@ final class ASRService: ObservableObject {}let duration = Date().timeIntervalSince(startTime)+ let latencyMs = Int((duration * 1000).rounded())+ self.captureStreamingChunkAnalytics(+ success: true,+ chunkSampleCount: chunk.count,+ latencyMs: latencyMs+ )DebugLogger.shared.debug("Streaming chunk transcription finished in \(String(format: "%.2f", duration))s",source: "ASRService"@@ -2386,6 +2444,14 @@ final class ASRService: ObservableObject {self.skipNextChunk = true}} catch {+ let duration = Date().timeIntervalSince(startTime)+ let latencyMs = Int((duration * 1000).rounded())+ self.captureStreamingChunkAnalytics(+ success: false,+ chunkSampleCount: chunk.count,+ latencyMs: latencyMs,+ error: error+ )DebugLogger.shared.error("❌ Streaming failed: \(error)", source: "ASRService")self.skipNextChunk = true}diff --git a/Sources/Fluid/UI/AnalyticsPrivacyView.swift b/Sources/Fluid/UI/AnalyticsPrivacyView.swiftindex 5bfc930e..0221ae72 100644--- a/Sources/Fluid/UI/AnalyticsPrivacyView.swift+++ b/Sources/Fluid/UI/AnalyticsPrivacyView.swift@@ -30,9 +30,10 @@ struct AnalyticsPrivacyView: View {ScrollView {VStack(alignment: .leading, spacing: 14) {self.sectionTitle("We collect")- self.bullet("Basic app/device info (app version, macOS version, etc.)")+ self.bullet("Basic app/device info (app version, macOS version, CPU family/chip class, etc.)")self.bullet("Which features were used (for example: dictation, Command Mode etc.)")- self.bullet("Approximate ranges only (not exact values), such as duration or word count.")+ self.bullet("Performance metrics such as transcription chunk latency and AI post-processing latency (milliseconds).")+ self.bullet("Model/provider metadata and post-processing input length (character count only, not text content).")self.bullet("Whether something worked and high-level error info.")self.sectionTitle("We do NOT collect")