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
feat: Add meeting file transcription and enhance audio services
altic-dev92b0dae2bb44
diff --git a/.gitignore b/.gitignoreindex 13bc4ea4..ca36086d 100644--- a/.gitignore+++ b/.gitignore@@ -182,3 +182,4 @@ SettingsStore.xcuserstate**/.vscode/+.mcp_temp/diff --git a/Fluid.entitlements b/Fluid.entitlementsindex 2115f611..c4e44c97 100644--- a/Fluid.entitlements+++ b/Fluid.entitlements@@ -4,8 +4,6 @@<dict><key>com.apple.security.automation.apple-events</key><true/>- <key>com.apple.security.get-task-allow</key>- <true/><key>com.apple.security.temporary-exception.apple-events</key><array><string>com.apple.systemevents</string>diff --git a/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolvedindex a81b172b..37abfa7c 100644--- a/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved+++ b/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved@@ -1,5 +1,5 @@{- "originHash" : "5fb64993316baee53fa040ae9eed2205d41e7618ec2ebd2fea554527d0b01783",+ "originHash" : "0e9edc93872d7a92fcff2d2765dc22155b0d0f13274eb53dcac8ebcf9819b368","pins" : [{"identity" : "appupdater",@@ -10,6 +10,15 @@"version" : "1.1.1"}},+ {+ "identity" : "eventsource",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/mattt/eventsource.git",+ "state" : {+ "revision" : "a2965424a4babeb0c8e4b5ec9708c3939bc52449",+ "version" : "1.2.0"+ }+ },{"identity" : "fluidaudio","kind" : "remoteSourceControl",@@ -46,6 +55,33 @@"version" : "6.22.1"}},+ {+ "identity" : "swift-log",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/apple/swift-log.git",+ "state" : {+ "revision" : "ce592ae52f982c847a4efc0dd881cc9eb32d29f2",+ "version" : "1.6.4"+ }+ },+ {+ "identity" : "swift-sdk",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/modelcontextprotocol/swift-sdk.git",+ "state" : {+ "revision" : "c0407a0b52677cb395d824cac2879b963075ba8c",+ "version" : "0.10.2"+ }+ },+ {+ "identity" : "swift-system",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/apple/swift-system.git",+ "state" : {+ "revision" : "395a77f0aa927f0ff73941d7ac35f2b46d47c9db",+ "version" : "1.6.3"+ }+ },{"identity" : "version","kind" : "remoteSourceControl",diff --git a/Info.plist b/Info.plistindex d1eb680c..2140cb6a 100644--- a/Info.plist+++ b/Info.plist@@ -3,15 +3,15 @@<plist version="1.0"><dict><key>CFBundleDisplayName</key>- <string>FluidVoice</string>+ <string>$(PRODUCT_NAME)</string><key>CFBundleName</key>- <string>FluidVoice</string>+ <string>$(PRODUCT_NAME)</string><key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string><key>CFBundleVersion</key><string>1</string><key>CFBundleShortVersionString</key>- <string>1.3.2</string>+ <string>1.3.3</string><key>LSMinimumSystemVersion</key><string>$(MACOSX_DEPLOYMENT_TARGET)</string><key>LSApplicationCategoryType</key>diff --git a/Package.resolved b/Package.resolvedindex 41db22f0..c0a4402b 100644--- a/Package.resolved+++ b/Package.resolved@@ -14,8 +14,8 @@"kind" : "remoteSourceControl","location" : "https://github.com/FluidInference/FluidAudio","state" : {- "revision" : "a5eeed9a0d5699c765670b5f56704739beb32a76",- "version" : "0.5.2"+ "revision" : "06ab3d5cac39f661619d5d22e1113807e439cd50",+ "version" : "0.7.4"}},{diff --git a/Package.swift b/Package.swiftindex 8ce20ca7..0fef9f52 100644--- a/Package.swift+++ b/Package.swift@@ -6,11 +6,11 @@ import PackageDescriptionlet package = Package(name: "FluidVoice",platforms: [- .macOS(.v13)+ .macOS(.v14)],dependencies: [.package(url: "https://github.com/mxcl/AppUpdater.git", from: "1.0.0"),- .package(url: "https://github.com/FluidInference/FluidAudio", from: "0.5.0"),+ .package(url: "https://github.com/FluidInference/FluidAudio", from: "0.7.4"),.package(url: "https://github.com/mxcl/PromiseKit", from: "6.0.0")],targets: [diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex 1005d130..d57b7b74 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -104,6 +104,7 @@ struct ContentView: View {@State private var enableAIProcessing: Bool = false@State private var enableDebugLogs: Bool = SettingsStore.shared.enableDebugLogs@State private var pressAndHoldModeEnabled: Bool = SettingsStore.shared.pressAndHoldMode+ @State private var enableStreamingPreview: Bool = SettingsStore.shared.enableStreamingPreview// Preferences Tab State@State private var launchAtStartup: Bool = SettingsStore.shared.launchAtStartup@@ -383,16 +384,24 @@ struct ContentView: View {hosting.wantsLayer = truehosting.layer?.cornerRadius = 20hosting.layer?.masksToBounds = true- self.overlay?.show(with: hosting)+ self.overlay?.show(with: hosting, showPreview: self.enableStreamingPreview)}} else {overlayVisible = falseDispatchQueue.main.asyncAfter(deadline: .now() + delay) {guard !self.overlayVisible else { return }self.overlay?.hide()+ // Clear transcription text when hiding overlay+ self.overlay?.updateTranscriptionText("")}}}+ .onChange(of: asr.partialTranscription) { newText in+ // Update overlay with streaming transcription preview (if enabled)+ if enableStreamingPreview {+ overlay?.updateTranscriptionText(newText)+ }+ }}private func resetPendingShortcutState()@@ -601,7 +610,12 @@ struct ContentView: View {step: 3,title: "Set Up AI Enhancement (Optional)",description: "Configure API keys for AI-powered text enhancement",- status: (providerAPIKeys[currentProvider]?.isEmpty == false && availableModels.contains(selectedModel)) ? .completed : .pending,+ status: {+ let hasApiKey = providerAPIKeys[currentProvider]?.isEmpty == false+ let isLocal = isLocalEndpoint(openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines))+ let hasModel = availableModels.contains(selectedModel)+ return ((isLocal || hasApiKey) && hasModel) ? .completed : .pending+ }(),action: {selectedSidebarItem = .aiProcessing}@@ -1630,6 +1644,33 @@ struct ContentView: View {SettingsStore.shared.pressAndHoldMode = newValuehotkeyManager?.enablePressAndHoldMode(newValue)}++ VStack(alignment: .leading, spacing: 12) {+ Toggle("Show Live Preview", isOn: $enableStreamingPreview)+ .toggleStyle(GlassToggleStyle())+ Text("Display transcription text in real-time in the overlay as you speak. When disabled, only the animation is shown.")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ .padding(.horizontal, 12)+ .padding(.vertical, 10)+ .background(+ RoundedRectangle(cornerRadius: 8)+ .fill(.ultraThinMaterial.opacity(0.5))+ .overlay(+ RoundedRectangle(cornerRadius: 8)+ .stroke(.white.opacity(0.08), lineWidth: 1)+ )+ )+ .onChange(of: enableStreamingPreview) { newValue in+ SettingsStore.shared.enableStreamingPreview = newValue+ // Dynamically resize overlay based on preview state+ overlay?.setPreviewEnabled(newValue)+ // Clear overlay text if disabled+ if !newValue {+ overlay?.updateTranscriptionText("")+ }+ }}} else {VStack(alignment: .leading, spacing: 16) {@@ -1819,7 +1860,10 @@ struct ContentView: View {Spacer()- if enableAIProcessing && (providerAPIKeys[currentProvider] ?? "").trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty {+ // Only show API key warning for non-local endpoints+ if enableAIProcessing &&+ !isLocalEndpoint(openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines)) &&+ (providerAPIKeys[currentProvider] ?? "").trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty {HStack {Image(systemName: "exclamationmark.triangle.fill").foregroundStyle(.orange)@@ -1927,14 +1971,18 @@ struct ContentView: View {// Status indicatorsHStack(spacing: 16) {- // API Key status+ // API Key status (or local endpoint indicator)HStack(spacing: 4) {- Image(systemName: (providerAPIKeys[currentProvider] ?? "").isEmpty ? "xmark.circle.fill" : "checkmark.circle.fill")- .foregroundStyle((providerAPIKeys[currentProvider] ?? "").isEmpty ? .red : .green)+ let hasApiKey = !(providerAPIKeys[currentProvider] ?? "").isEmpty+ let isLocal = isLocalEndpoint(openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines))+ let isConfigured = hasApiKey || isLocal++ Image(systemName: isConfigured ? "checkmark.circle.fill" : "xmark.circle.fill")+ .foregroundStyle(isConfigured ? .green : .red).font(.caption)- Text("API Key")+ Text(isLocal ? "Local" : "API Key").font(.caption)- .foregroundStyle((providerAPIKeys[currentProvider] ?? "").isEmpty ? .red : .green)+ .foregroundStyle(isConfigured ? .green : .red)}// Connection status@@ -2027,6 +2075,8 @@ struct ContentView: View {}}+ Spacer()+Button("+ Add Provider") {showingSaveProvider = truenewProviderName = ""@@ -2038,6 +2088,42 @@ struct ContentView: View {.buttonHoverEffect()}+ // Delete button for custom providers - positioned near model catalogs+ HStack(spacing: 8) {+ // Delete button for custom providers+ if !selectedProviderID.isEmpty && selectedProviderID != "openai" && selectedProviderID != "groq" {+ Button(action: {+ // Remove the provider+ savedProviders.removeAll { $0.id == selectedProviderID }+ saveSavedProviders()++ // Remove associated data+ let key = providerKey(for: selectedProviderID)+ availableModelsByProvider.removeValue(forKey: key)+ selectedModelByProvider.removeValue(forKey: key)+ providerAPIKeys.removeValue(forKey: key)+ saveProviderAPIKeys()+ SettingsStore.shared.availableModelsByProvider = availableModelsByProvider+ SettingsStore.shared.selectedModelByProvider = selectedModelByProvider++ // Switch to OpenAI if we just deleted the current provider+ selectedProviderID = "openai"+ openAIBaseURL = "https://api.openai.com/v1"+ updateCurrentProvider()+ availableModels = defaultModels(for: "openai")+ selectedModel = availableModels.first ?? selectedModel+ }) {+ Image(systemName: "trash")+ .foregroundStyle(.red)+ .font(.caption)+ }+ .buttonStyle(.plain)+ .help("Delete this provider")+ }++ Spacer()+ }+// Provider model catalogs quick linksHStack(spacing: 6) {Image(systemName: "link")@@ -2110,7 +2196,9 @@ struct ContentView: View {.clipShape(RoundedRectangle(cornerRadius: 6))}.buttonStyle(.plain)- .disabled(isTestingConnection || (providerAPIKeys[currentProvider] ?? "").isEmpty)+ .disabled(isTestingConnection ||+ (!isLocalEndpoint(openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines)) &&+ (providerAPIKeys[currentProvider] ?? "").isEmpty)).buttonHoverEffect()Text("(\(currentProvider.capitalized))")@@ -2123,7 +2211,7 @@ struct ContentView: View {Text("Enter \(currentProvider.capitalized) API Key").font(.headline)- SecureField("API Key", text: $newProviderApiKey)+ SecureField("API Key (optional for local endpoints)", text: $newProviderApiKey).textFieldStyle(.roundedBorder).frame(width: 300)@@ -2144,7 +2232,9 @@ struct ContentView: View {showAPIKeyEditor = false}.buttonStyle(.borderedProminent)- .disabled(newProviderApiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)+ // Allow empty API key for local endpoints+ .disabled(!isLocalEndpoint(openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines)) &&+ newProviderApiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)}}.padding()@@ -2154,7 +2244,9 @@ struct ContentView: View {// Connection Status DisplayHStack(spacing: 8) {// Real-time validation indicator- if (providerAPIKeys[currentProvider] ?? "").isEmpty {+ // Only show API key warning for non-local endpoints+ if (providerAPIKeys[currentProvider] ?? "").isEmpty &&+ !isLocalEndpoint(openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines)) {Image(systemName: "exclamationmark.triangle.fill").foregroundStyle(.orange).font(.caption)@@ -2228,7 +2320,7 @@ struct ContentView: View {}HStack(spacing: 8) {- SecureField("API Key", text: $newProviderApiKey)+ SecureField("API Key (optional for local)", text: $newProviderApiKey).textFieldStyle(.roundedBorder).frame(width: 300)TextField("Available models (comma-separated)", text: $newProviderModels)@@ -2286,9 +2378,16 @@ struct ContentView: View {}.buttonStyle(GlassButtonStyle()).buttonHoverEffect()- .disabled(newProviderName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ||- newProviderBaseURL.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ||- newProviderApiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)+ .disabled({+ let nameEmpty = newProviderName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ let urlEmpty = newProviderBaseURL.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ let apiKeyEmpty = newProviderApiKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ let isLocal = isLocalEndpoint(newProviderBaseURL.trimmingCharacters(in: .whitespacesAndNewlines))++ // Name and URL are always required+ // API key is only required for non-local endpoints+ return nameEmpty || urlEmpty || (!isLocal && apiKeyEmpty)+ }())Button("Cancel") {showingSaveProvider = false@@ -2546,38 +2645,7 @@ struct ContentView: View {// MARK: - Meeting Transcription (Coming Soon)private var meetingToolsView: some View{- VStack(alignment: .leading, spacing: 16) {- HStack(spacing: 8) {- Image(systemName: "person.2.wave.2.fill")- .font(.title2)- Text("Meeting Tools")- .font(.title3)- .fontWeight(.semibold)- }-- Text("Upload recordings and transcribe multi-speaker meetings. This is a playground where you can test transcription features.")- .foregroundStyle(.secondary)-- RoundedRectangle(cornerRadius: 12)- .fill(.ultraThinMaterial)- .overlay(- VStack(spacing: 12) {- Image(systemName: "clock.badge.exclamationmark")- .font(.system(size: 28, weight: .semibold))- .foregroundStyle(.orange)- Text("Coming Soon")- .font(.headline)- Text("This feature is in active development. A testing playground for transcription capabilities.")- .font(.subheadline)- .foregroundStyle(.secondary)- }- .padding(24)- )- .frame(maxWidth: .infinity, minHeight: 180)-- Spacer()- }- .padding(20)+ MeetingTranscriptionView()}// MARK: - Feedback View@@ -2817,7 +2885,9 @@ struct ContentView: View {}}- private func saveProviderAPIKeys() { SettingsStore.shared.providerAPIKeys = providerAPIKeys }+ private func saveProviderAPIKeys() {+ SettingsStore.shared.providerAPIKeys = providerAPIKeys+ }private func updateCurrentProvider() {// Map baseURL to canonical key for built-ins; else keep existing@@ -2828,7 +2898,9 @@ struct ContentView: View {currentProvider = providerKey(for: selectedProviderID)}- private func saveSavedProviders() { SettingsStore.shared.savedProviders = savedProviders }+ private func saveSavedProviders() {+ SettingsStore.shared.savedProviders = savedProviders+ }// MARK: - App Detection and Context-Aware Promptsprivate func getCurrentAppInfo() -> (name: String, bundleId: String, windowTitle: String) {@@ -2992,17 +3064,73 @@ struct ContentView: View {}return base + "\n\n" + addendum + "\n\n" + context}++ // MARK: - Local Endpoint Detection+ private func isLocalEndpoint(_ urlString: String) -> Bool {+ guard let url = URL(string: urlString),+ let host = url.host else { return false }++ let hostLower = host.lowercased()++ // Check for localhost variations+ if hostLower == "localhost" || hostLower == "127.0.0.1" {+ return true+ }++ // Check for private IP ranges+ // 127.x.x.x+ if hostLower.hasPrefix("127.") {+ return true+ }+ // 10.x.x.x+ if hostLower.hasPrefix("10.") {+ return true+ }+ // 192.168.x.x+ if hostLower.hasPrefix("192.168.") {+ return true+ }+ // 172.16.x.x - 172.31.x.x+ if hostLower.hasPrefix("172.") {+ let components = hostLower.split(separator: ".")+ if components.count >= 2,+ let secondOctet = Int(components[1]),+ secondOctet >= 16 && secondOctet <= 31 {+ return true+ }+ }++ return false+ }// MARK: - Modular AI Processingprivate func processTextWithAI(_ inputText: String) async -> String {let endpoint = openAIBaseURL.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty ? "https://api.openai.com/v1" : openAIBaseURL.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)- guard let url = URL(string: endpoint + "/chat/completions") else {++ // Build the full URL - only append /chat/completions if not already present+ let fullEndpoint: String+ if endpoint.contains("/chat/completions") ||+ endpoint.contains("/api/chat") ||+ endpoint.contains("/api/generate") {+ // URL already has a complete path, use as-is+ fullEndpoint = endpoint+ } else {+ // Append /chat/completions for OpenAI-compatible endpoints+ fullEndpoint = endpoint + "/chat/completions"+ }++ guard let url = URL(string: fullEndpoint) else {return "Error: Invalid Base URL"}+ let isLocal = isLocalEndpoint(endpoint)let apiKey = providerAPIKeys[currentProvider] ?? ""- guard !apiKey.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty else {- return "Error: API Key not set for \(currentProvider)"++ // Skip API key validation for local endpoints+ if !isLocal {+ guard !apiKey.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty else {+ return "Error: API Key not set for \(currentProvider)"+ }}struct ChatMessage: Codable { let role: String; let content: String }@@ -3032,11 +3160,28 @@ struct ContentView: View {var request = URLRequest(url: url)request.httpMethod = "POST"request.addValue("application/json", forHTTPHeaderField: "Content-Type")- request.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")++ // Only add Authorization header for non-local endpoints+ if !isLocal {+ request.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")+ }+request.httpBody = jsonDatado {let (data, response) = try await URLSession.shared.data(for: request)++ // Debug: Print raw response+ print("=== OLLAMA RESPONSE DEBUG (ContentView) ===")+ print("Response URL: \(request.url?.absoluteString ?? "unknown")")+ if let http = response as? HTTPURLResponse {+ print("HTTP Status: \(http.statusCode)")+ }+ if let responseText = String(data: data, encoding: .utf8) {+ print("Raw Response: \(responseText)")+ }+ print("==========================================")+if let http = response as? HTTPURLResponse, http.statusCode >= 400 {let errText = String(data: data, encoding: .utf8) ?? "Unknown error"return "Error: HTTP \(http.statusCode): \(errText)"@@ -3044,6 +3189,12 @@ struct ContentView: View {let decoded = try JSONDecoder().decode(ChatResponse.self, from: data)return decoded.choices.first?.message.content ?? "<no content>"} catch {+ print("=== OLLAMA DECODE ERROR (ContentView) ===")+ print("Error: \(error)")+ if let decodingError = error as? DecodingError {+ print("Decoding Error Details: \(decodingError)")+ }+ print("========================================")return "Error: \(error.localizedDescription)"}}@@ -3062,7 +3213,13 @@ struct ContentView: View {let finalText: String- if enableAIProcessing && !(providerAPIKeys[currentProvider] ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {+ // Check if we should use AI processing+ let apiKey = (providerAPIKeys[currentProvider] ?? "").trimmingCharacters(in: .whitespacesAndNewlines)+ let baseURL = openAIBaseURL.trimmingCharacters(in: .whitespacesAndNewlines)+ let isLocal = isLocalEndpoint(baseURL)+ let shouldUseAI = enableAIProcessing && (isLocal || !apiKey.isEmpty)++ if shouldUseAI {DebugLogger.shared.debug("Routing transcription through AI post-processing", source: "ContentView")finalText = await processTextWithAI(transcribedText)} else {@@ -3122,25 +3279,42 @@ struct ContentView: View {let apiKey = providerAPIKeys[currentProvider] ?? ""let baseURL = openAIBaseURL.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)+ let isLocal = isLocalEndpoint(baseURL)// Debug logging- DebugLogger.shared.info("API connection test started (provider: \(currentProvider), baseURL: \(baseURL))", source: "ContentView")+ DebugLogger.shared.info("API connection test started (provider: \(currentProvider), baseURL: \(baseURL), isLocal: \(isLocal))", source: "ContentView")DebugLogger.shared.debug("API key supplied: \(!apiKey.isEmpty), length: \(apiKey.count)", source: "ContentView")- if !apiKey.hasPrefix("sk-") {- DebugLogger.shared.warning("PROBLEM: API key doesn't start with 'sk-' - this is likely the cause of the 401 error!", source: "ContentView")- }- if apiKey.count < 20 || apiKey.count > 200 {- DebugLogger.shared.warning("PROBLEM: API key length is unusual - should be 20-200 characters!", source: "ContentView")+ // Only validate API key for non-local endpoints+ if !isLocal {+ if !apiKey.hasPrefix("sk-") {+ DebugLogger.shared.warning("PROBLEM: API key doesn't start with 'sk-' - this is likely the cause of the 401 error!", source: "ContentView")+ }+ if apiKey.count < 20 || apiKey.count > 200 {+ DebugLogger.shared.warning("PROBLEM: API key length is unusual - should be 20-200 characters!", source: "ContentView")+ }}- guard !apiKey.isEmpty && !baseURL.isEmpty else {- DebugLogger.shared.error("Missing required fields - API key or base URL is empty", source: "ContentView")- await MainActor.run {- connectionStatus = .failed- connectionErrorMessage = "API key and base URL are required"+ // For local endpoints, only baseURL is required+ if isLocal {+ guard !baseURL.isEmpty else {+ DebugLogger.shared.error("Missing required field - base URL is empty", source: "ContentView")+ await MainActor.run {+ connectionStatus = .failed+ connectionErrorMessage = "Base URL is required"+ }+ return+ }+ } else {+ // For remote endpoints, both API key and baseURL are required+ guard !apiKey.isEmpty && !baseURL.isEmpty else {+ DebugLogger.shared.error("Missing required fields - API key or base URL is empty", source: "ContentView")+ await MainActor.run {+ connectionStatus = .failed+ connectionErrorMessage = "API key and base URL are required"+ }+ return}- return}await MainActor.run {@@ -3151,7 +3325,19 @@ struct ContentView: View {do {let endpoint = baseURL.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)- let fullURL = endpoint + "/chat/completions"++ // Build the full URL - only append /chat/completions if not already present+ let fullURL: String+ if endpoint.contains("/chat/completions") ||+ endpoint.contains("/api/chat") ||+ endpoint.contains("/api/generate") {+ // URL already has a complete path, use as-is+ fullURL = endpoint+ } else {+ // Append /chat/completions for OpenAI-compatible endpoints+ fullURL = endpoint + "/chat/completions"+ }+DebugLogger.shared.debug("Full endpoint URL: \(fullURL)", source: "ContentView")guard let url = URL(string: fullURL) else {@@ -3198,7 +3384,12 @@ struct ContentView: View {var request = URLRequest(url: url)request.httpMethod = "POST"request.setValue("application/json", forHTTPHeaderField: "Content-Type")- request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")++ // Only add Authorization header for non-local endpoints+ if !isLocal {+ request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")+ }+request.httpBody = jsonData// Log request details (mask API key for security)@@ -3207,8 +3398,12 @@ struct ContentView: View {print("[DEBUG] Method: \(request.httpMethod ?? "Unknown")")print("[DEBUG] URL: \(request.url?.absoluteString ?? "Unknown")")print("[DEBUG] Content-Type: \(request.value(forHTTPHeaderField: "Content-Type") ?? "Not set")")- print("[DEBUG] Authorization header: \(request.value(forHTTPHeaderField: "Authorization") != nil ? "Set (Bearer \(maskedKey))" : "NOT SET - This is likely the problem!")")- print("[DEBUG] Full Authorization header: \(request.value(forHTTPHeaderField: "Authorization") ?? "NOT SET")")+ if isLocal {+ print("[DEBUG] Authorization header: Skipped (local endpoint detected)")+ } else {+ print("[DEBUG] Authorization header: \(request.value(forHTTPHeaderField: "Authorization") != nil ? "Set (Bearer \(maskedKey))" : "NOT SET - This is likely the problem!")")+ print("[DEBUG] Full Authorization header: \(request.value(forHTTPHeaderField: "Authorization") ?? "NOT SET")")+ }print("[DEBUG] Body size: \(jsonData.count) bytes")if let bodyString = String(data: jsonData, encoding: .utf8) {print("[DEBUG] Request body: \(bodyString)")@@ -3355,25 +3550,18 @@ struct ContentView: View {isSendingFeedback = true}- do {- let feedbackData = createFeedbackData()- let success = await submitFeedback(data: feedbackData)-- await MainActor.run {- isSendingFeedback = false- if success {- // Show confirmation and clear form- showFeedbackConfirmation = true- feedbackText = ""- feedbackEmail = ""- includeDebugLogs = false- }- }- } catch {- await MainActor.run {- isSendingFeedback = false+ let feedbackData = createFeedbackData()+ let success = await submitFeedback(data: feedbackData)++ await MainActor.run {+ isSendingFeedback = false+ if success {+ // Show confirmation and clear form+ showFeedbackConfirmation = true+ feedbackText = ""+ feedbackEmail = ""+ includeDebugLogs = false}- DebugLogger.shared.error("Failed to send feedback: \(error.localizedDescription)", source: "ContentView")}}diff --git a/Sources/Fluid/Networking/AIProvider.swift b/Sources/Fluid/Networking/AIProvider.swiftindex 5e72e041..bcadc8f1 100644--- a/Sources/Fluid/Networking/AIProvider.swift+++ b/Sources/Fluid/Networking/AIProvider.swift@@ -12,11 +12,64 @@ final class OpenAICompatibleProvider: AIProviderstruct ChatChoiceMessage: Codable { let role: String; let content: String }struct ChatChoice: Codable { let index: Int?; let message: ChatChoiceMessage }struct ChatResponse: Codable { let choices: [ChatChoice] }++ // Helper function to detect if the endpoint is local+ private func isLocalEndpoint(_ urlString: String) -> Bool {+ guard let url = URL(string: urlString),+ let host = url.host else { return false }++ let hostLower = host.lowercased()++ // Check for localhost variations+ if hostLower == "localhost" || hostLower == "127.0.0.1" {+ return true+ }++ // Check for private IP ranges+ // 127.x.x.x+ if hostLower.hasPrefix("127.") {+ return true+ }+ // 10.x.x.x+ if hostLower.hasPrefix("10.") {+ return true+ }+ // 192.168.x.x+ if hostLower.hasPrefix("192.168.") {+ return true+ }+ // 172.16.x.x - 172.31.x.x+ if hostLower.hasPrefix("172.") {+ let components = hostLower.split(separator: ".")+ if components.count >= 2,+ let secondOctet = Int(components[1]),+ secondOctet >= 16 && secondOctet <= 31 {+ return true+ }+ }++ return false+ }func process(systemPrompt: String, userText: String, model: String, apiKey: String, baseURL: String) async -> String{let endpoint = baseURL.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? "https://api.openai.com/v1" : baseURL.trimmingCharacters(in: .whitespacesAndNewlines)- guard let url = URL(string: endpoint + "/chat/completions") else { return "Error: Invalid Base URL" }++ // Build the full URL - only append /chat/completions if not already present+ let fullEndpoint: String+ if endpoint.contains("/chat/completions") ||+ endpoint.contains("/api/chat") ||+ endpoint.contains("/api/generate") {+ // URL already has a complete path, use as-is+ fullEndpoint = endpoint+ } else {+ // Append /chat/completions for OpenAI-compatible endpoints+ fullEndpoint = endpoint + "/chat/completions"+ }++ guard let url = URL(string: fullEndpoint) else { return "Error: Invalid Base URL" }++ let isLocal = isLocalEndpoint(endpoint)let body = ChatRequest(model: model,@@ -32,12 +85,29 @@ final class OpenAICompatibleProvider: AIProvidervar request = URLRequest(url: url)request.httpMethod = "POST"request.addValue("application/json", forHTTPHeaderField: "Content-Type")- request.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")++ // Only add Authorization header for non-local endpoints+ if !isLocal {+ request.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")+ }+request.httpBody = jsonDatado{let (data, response) = try await URLSession.shared.data(for: request)++ // Debug: Print raw response+ print("=== OLLAMA RESPONSE DEBUG ===")+ print("Response URL: \(request.url?.absoluteString ?? "unknown")")+ if let http = response as? HTTPURLResponse {+ print("HTTP Status: \(http.statusCode)")+ }+ if let responseText = String(data: data, encoding: .utf8) {+ print("Raw Response: \(responseText)")+ }+ print("============================")+if let http = response as? HTTPURLResponse, http.statusCode >= 400{let errText = String(data: data, encoding: .utf8) ?? "Unknown error"@@ -48,6 +118,12 @@ final class OpenAICompatibleProvider: AIProvider}catch{+ print("=== OLLAMA DECODE ERROR ===")+ print("Error: \(error)")+ if let decodingError = error as? DecodingError {+ print("Decoding Error Details: \(decodingError)")+ }+ print("==========================")return "Error: \(error.localizedDescription)"}}diff --git a/Sources/Fluid/Networking/ModelDownloader.swift b/Sources/Fluid/Networking/ModelDownloader.swiftindex 109690fd..faacab8b 100644--- a/Sources/Fluid/Networking/ModelDownloader.swift+++ b/Sources/Fluid/Networking/ModelDownloader.swift@@ -302,25 +302,52 @@ extension HuggingFaceModelDownloaderfunc loadLocalAsrModels(from repoDirectory: URL) async throws -> AsrModels{let config = AsrModels.defaultConfiguration()+ let fm = FileManager.default- // Unified v3 model paths- let melEncUrl = repoDirectory.appendingPathComponent("MelEncoder.mlmodelc")+ // Try to load with new naming convention first (Preprocessor + Encoder)+ let preprocessorUrl = repoDirectory.appendingPathComponent("Preprocessor.mlmodelc")+ let encoderUrl = repoDirectory.appendingPathComponent("Encoder.mlmodelc")let decUrl = repoDirectory.appendingPathComponent("Decoder.mlmodelc")let jointUrl = repoDirectory.appendingPathComponent("JointDecision.mlmodelc")print("[ModelDL] Loading v3 models from: \(repoDirectory.path)")- print("[ModelDL] MelEncoder path: \(melEncUrl.path)")+ print("[ModelDL] Preprocessor path: \(preprocessorUrl.path)")+ print("[ModelDL] Encoder path: \(encoderUrl.path)")print("[ModelDL] Decoder path: \(decUrl.path)")print("[ModelDL] JointDecision path: \(jointUrl.path)")- // Check existence- let fm = FileManager.default- print("[ModelDL] MelEncoder exists: \(fm.fileExists(atPath: melEncUrl.path))")- print("[ModelDL] Decoder exists: \(fm.fileExists(atPath: decUrl.path))")- print("[ModelDL] JointDecision exists: \(fm.fileExists(atPath: jointUrl.path))")+ // Check if new structure exists+ let hasNewStructure = fm.fileExists(atPath: preprocessorUrl.path) && fm.fileExists(atPath: encoderUrl.path)++ let preprocessor: MLModel+ let encoder: MLModel++ if hasNewStructure {+ // Load with new structure (separate Preprocessor and Encoder)+ print("[ModelDL] Loading with new model structure (Preprocessor + Encoder)")+ preprocessor = try MLModel(contentsOf: preprocessorUrl, configuration: config)+ encoder = try MLModel(contentsOf: encoderUrl, configuration: config)+ } else {+ // Fallback: Try old structure (MelEncoder as both preprocessor and encoder)+ let melEncUrl = repoDirectory.appendingPathComponent("MelEncoder.mlmodelc")+ print("[ModelDL] New structure not found, trying legacy MelEncoder")+ print("[ModelDL] MelEncoder path: \(melEncUrl.path)")+ print("[ModelDL] MelEncoder exists: \(fm.fileExists(atPath: melEncUrl.path))")++ if fm.fileExists(atPath: melEncUrl.path) {+ let melEncoder = try MLModel(contentsOf: melEncUrl, configuration: config)+ // Use MelEncoder for both preprocessor and encoder+ preprocessor = melEncoder+ encoder = melEncoder+ print("[ModelDL] Using MelEncoder for both preprocessor and encoder (legacy mode)")+ } else {+ throw NSError(domain: "ModelDL", code: -1, userInfo: [+ NSLocalizedDescriptionKey: "Neither new model structure (Preprocessor + Encoder) nor legacy structure (MelEncoder) found"+ ])+ }+ }- // Load models with configuration- let melEncoder = try MLModel(contentsOf: melEncUrl, configuration: config)+ // Load decoder and joint (same for both structures)let decoder = try MLModel(contentsOf: decUrl, configuration: config)let joint = try MLModel(contentsOf: jointUrl, configuration: config)@@ -338,8 +365,12 @@ extension HuggingFaceModelDownloader}print("[ModelDL] Creating AsrModels (unified v3)")++ // Use the encoder as melEncoder (works with both old and new models)+ // When using new model structure (Preprocessor + Encoder), encoder is separate+ // When using old structure (MelEncoder), encoder IS the melEncoderreturn AsrModels(- melEncoder: melEncoder,+ melEncoder: encoder,decoder: decoder,joint: joint,configuration: config,diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex 894e063d..cf13e291 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -28,6 +28,7 @@ final class SettingsStorestatic let launchAtStartup = "LaunchAtStartup"static let showInDock = "ShowInDock"static let pressAndHoldMode = "PressAndHoldMode"+ static let enableStreamingPreview = "EnableStreamingPreview"}struct SavedProvider: Codable, Identifiable, Hashable@@ -133,6 +134,15 @@ final class SettingsStoreset { defaults.set(newValue, forKey: Keys.pressAndHoldMode) }}+ var enableStreamingPreview: Bool+ {+ get {+ let value = defaults.object(forKey: Keys.enableStreamingPreview)+ return value as? Bool ?? true // Default to true (enabled)+ }+ set { defaults.set(newValue, forKey: Keys.enableStreamingPreview) }+ }+var preferredInputDeviceUID: String?{get { defaults.string(forKey: Keys.preferredInputDeviceUID) }@@ -194,8 +204,6 @@ final class SettingsStore}}--// MARK: - Private Methodsprivate func updateLaunchAtStartup(_ enabled: Bool) {diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex a3c984b4..c4aa6da5 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -45,6 +45,7 @@ final class ASRService: ObservableObject{@Published var isRunning: Bool = false@Published var finalText: String = ""+ @Published var partialTranscription: String = ""@Published var micStatus: AVAuthorizationStatus = .notDetermined@Published var isAsrReady: Bool = false@Published var isDownloadingModel: Bool = false@@ -68,6 +69,14 @@ final class ASRService: ObservableObjectprivate var isRecordingWholeSession: Bool = falseprivate var recordedPCM: [Float] = []+ // Streaming transcription properties (timer-based, no VAD)+ private var streamingTimer: Timer?+ private var lastProcessedSampleCount: Int = 0+ private let chunkDurationSeconds: Double = 1.5 // Faster updates!+ private var isProcessingChunk: Bool = false+ private var skipNextChunk: Bool = false+ private var previousFullTranscription: String = ""+private var audioLevelSubject = PassthroughSubject<CGFloat, Never>()var audioLevelPublisher: AnyPublisher<CGFloat, Never> { audioLevelSubject.eraseToAnyPublisher() }private var lastAudioLevelSentAt: TimeInterval = 0@@ -133,6 +142,11 @@ final class ASRService: ObservableObjectfinalText.removeAll()recordedPCM.removeAll()+ partialTranscription.removeAll()+ previousFullTranscription.removeAll()+ lastProcessedSampleCount = 0+ isProcessingChunk = false+ skipNextChunk = falseisRecordingWholeSession = truedo@@ -141,6 +155,7 @@ final class ASRService: ObservableObjecttry startEngine()setupEngineTap()isRunning = true+ startStreamingTranscription()}catch{@@ -180,9 +195,14 @@ final class ASRService: ObservableObjectfunc stop() async -> String{guard isRunning else { return "" }+ stopStreamingTimer()removeEngineTap()engine.stop()isRunning = false++ isProcessingChunk = false+ skipNextChunk = false+ previousFullTranscription.removeAll()let pcm = recordedPCMrecordedPCM.removeAll()@@ -220,11 +240,17 @@ final class ASRService: ObservableObjectfunc stopWithoutTranscription(){guard isRunning else { return }+ stopStreamingTimer()removeEngineTap()engine.stop()isRunning = falserecordedPCM.removeAll()isRecordingWholeSession = false+ partialTranscription.removeAll()+ previousFullTranscription.removeAll()+ lastProcessedSampleCount = 0+ isProcessingChunk = false+ skipNextChunk = false}private func configureSession() throws@@ -531,8 +557,8 @@ final class ASRService: ObservableObject{DebugLogger.shared.debug("Initializing AsrManager with models...", source: "ASRService")try await manager.initialize(models: models)- DebugLogger.shared.debug("AsrManager initialized successfully", source: "ASRService")- }+ DebugLogger.shared.debug("AsrManager initialized successfully", source: "ASRService")+ }dup2(originalStderr, STDERR_FILENO)close(originalStderr)@@ -624,6 +650,112 @@ final class ASRService: ObservableObjecttry await ensureAsrReady()}+ // MARK: - Timer-based Streaming Transcription (No VAD)++ private func startStreamingTranscription() {+ stopStreamingTimer()+ guard isAsrReady else { return }++ DebugLogger.shared.debug("Starting streaming transcription timer (every \(chunkDurationSeconds)s)", source: "ASRService")++ Task { @MainActor in+ self.streamingTimer = Timer.scheduledTimer(withTimeInterval: self.chunkDurationSeconds, repeats: true) { [weak self] _ in+ guard let self = self else { return }+ Task { @MainActor in+ await self.processStreamingChunk()+ }+ }+ }+ }++ private func stopStreamingTimer() {+ streamingTimer?.invalidate()+ streamingTimer = nil+ }++ @MainActor+ private func processStreamingChunk() async {+ guard isRunning else { return }++ // Prevent concurrent transcription+ guard !isProcessingChunk else {+ DebugLogger.shared.debug("⚠️ Skipping chunk - previous transcription still in progress", source: "ASRService")+ skipNextChunk = true+ return+ }++ if skipNextChunk {+ DebugLogger.shared.debug("⚠️ Skipping chunk for ANE recovery", source: "ASRService")+ skipNextChunk = false+ return+ }++ guard isAsrReady, let manager = asrManager else { return }++ let currentSampleCount = recordedPCM.count+ let minSamples = 16000 // 1 second minimum+ guard currentSampleCount >= minSamples else { return }++ // Transcribe ALL audio from start (for full context)+ let chunk = Array(recordedPCM[0..<currentSampleCount])++ isProcessingChunk = true+ let startTime = Date()++ do {+ let result = try await manager.transcribe(chunk, source: .microphone)+ let duration = Date().timeIntervalSince(startTime)+ let newText = result.text.trimmingCharacters(in: .whitespacesAndNewlines)++ if !newText.isEmpty {+ // Smart diff: only show truly new words+ let updatedText = smartDiffUpdate(previous: previousFullTranscription, current: newText)+ partialTranscription = updatedText+ previousFullTranscription = newText++ DebugLogger.shared.debug("✅ Streaming: '\(updatedText)' (\(String(format: "%.2f", duration))s)", source: "ASRService")+ }++ if duration > chunkDurationSeconds * 0.8 {+ skipNextChunk = true+ }+ } catch {+ DebugLogger.shared.error("❌ Streaming failed: \(error)", source: "ASRService")+ skipNextChunk = true+ }++ isProcessingChunk = false+ }++ /// Smart diff to prevent text from jumping around+ private func smartDiffUpdate(previous: String, current: String) -> String {+ guard !previous.isEmpty else { return current }+ guard !current.isEmpty else { return previous }++ let prevWords = previous.split(separator: " ").map(String.init)+ let currWords = current.split(separator: " ").map(String.init)++ // Find longest common prefix+ var commonPrefixLength = 0+ for i in 0..<min(prevWords.count, currWords.count) {+ if prevWords[i].lowercased().trimmingCharacters(in: .punctuationCharacters) ==+ currWords[i].lowercased().trimmingCharacters(in: .punctuationCharacters) {+ commonPrefixLength = i + 1+ } else {+ break+ }+ }++ // If >50% overlap, keep stable prefix and add new words+ if commonPrefixLength > prevWords.count / 2 {+ let stableWords = Array(currWords[0..<min(commonPrefixLength, currWords.count)])+ let newWords = currWords.count > commonPrefixLength ? Array(currWords[commonPrefixLength...]) : []+ return (stableWords + newWords).joined(separator: " ")+ } else {+ return current // Significant change+ }+ }+// MARK: - Typing convenience for compatibilityprivate let typingService = TypingService() // Reuse instance to avoid conflicts@@ -632,3 +764,4 @@ final class ASRService: ObservableObjecttypingService.typeTextInstantly(text)}}+diff --git a/Sources/Fluid/Services/ListeningOverlayController.swift b/Sources/Fluid/Services/ListeningOverlayController.swiftindex 57844bbf..0559766d 100644--- a/Sources/Fluid/Services/ListeningOverlayController.swift+++ b/Sources/Fluid/Services/ListeningOverlayController.swift@@ -4,33 +4,73 @@ final class ListeningOverlayController{private var panel: NSPanel?private var asrService: ASRService+ private var line1TextField: NSTextField? // Top - faded (previous)+ private var line2TextField: NSTextField? // Bottom - bright (current)+ private var previousText: String = ""+ private var unifiedContainer: NSView?+ private var orbView: NSView?+ private var isShowingPreview: Bool = trueinit(asrService: ASRService){self.asrService = asrService}- func show(with view: NSView)+ func show(with view: NSView, showPreview: Bool = true){- if panel == nil- {- let style: NSWindow.StyleMask = [.borderless, .nonactivatingPanel]- let p = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 280, height: 80),- styleMask: style,- backing: .buffered,- defer: false)- p.level = .statusBar- p.isOpaque = false- p.hasShadow = true- p.hidesOnDeactivate = false- p.ignoresMouseEvents = true- p.collectionBehavior = [.canJoinAllSpaces, .transient, .fullScreenAuxiliary]- p.backgroundColor = .clear- p.titleVisibility = .hidden- p.titlebarAppearsTransparent = true- panel = p+ // CRITICAL: Always clean up existing panel first to prevent duplicates+ if let existingPanel = panel {+ existingPanel.orderOut(nil)+ existingPanel.contentView = nil+ panel = nil}- panel?.contentView = view++ isShowingPreview = showPreview++ // Dynamic sizing based on preview state+ let width: CGFloat = 340+ let height: CGFloat = showPreview ? 100 : 90 // Compact for 2 lines+ let orbY: CGFloat = showPreview ? 40 : 10++ // Create fresh panel with dynamic size+ let style: NSWindow.StyleMask = [.borderless, .nonactivatingPanel]+ let p = NSPanel(contentRect: NSRect(x: 0, y: 0, width: width, height: height),+ styleMask: style,+ backing: .buffered,+ defer: false)+ p.level = .statusBar+ p.isOpaque = false+ p.hasShadow = true+ p.hidesOnDeactivate = false+ p.ignoresMouseEvents = true+ p.collectionBehavior = [.canJoinAllSpaces, .transient, .fullScreenAuxiliary]+ p.backgroundColor = .clear+ p.titleVisibility = .hidden+ p.titlebarAppearsTransparent = true+ panel = p++ // CRITICAL FIX: Create ONE unified container with background for both orb and text+ let container = NSView(frame: NSRect(x: 0, y: 0, width: width, height: height))+ container.wantsLayer = true+ container.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.85).cgColor+ container.layer?.cornerRadius = 12+ unifiedContainer = container++ // Create inner container for layout+ let containerView = NSView(frame: NSRect(x: 0, y: 0, width: width, height: height))+ container.addSubview(containerView)++ // Add SwiftUI hosting view to container (at top, no background)+ view.frame = NSRect(x: 0, y: orbY, width: width, height: 70)+ containerView.addSubview(view)+ orbView = view++ // Add text fields to container (at bottom) - only if preview enabled+ if showPreview {+ setupTranscriptionTextField(in: containerView)+ }++ panel?.contentView = containerpositionCenteredLower()panel?.orderFrontRegardless()}@@ -58,6 +98,162 @@ final class ListeningOverlayControllerlet yPosition = visible.minY + bottomPaddingpanel.setFrameOrigin(NSPoint(x: centerX.rounded(), y: yPosition.rounded()))}++ private func setupTranscriptionTextField(in containerView: NSView)+ {+ // Remove existing text fields if any+ line1TextField?.removeFromSuperview()+ line2TextField?.removeFromSuperview()++ // Create container for two-line scrolling layout (no background, uses unified)+ let textContainer = NSView(frame: .zero)+ textContainer.translatesAutoresizingMaskIntoConstraints = false+ containerView.addSubview(textContainer)++ // Line 1 (top) - Faded, previous+ let line1 = createTextField(alpha: 0.45, fontSize: 9, weight: .regular)+ textContainer.addSubview(line1)++ // Line 2 (bottom) - Bright, current+ let line2 = createTextField(alpha: 1.0, fontSize: 10, weight: .medium)+ textContainer.addSubview(line2)++ // Layout constraints for two-line stack (super compact)+ NSLayoutConstraint.activate([+ // Line 1 (top)+ line1.topAnchor.constraint(equalTo: textContainer.topAnchor, constant: 2),+ line1.leadingAnchor.constraint(equalTo: textContainer.leadingAnchor, constant: 10),+ line1.trailingAnchor.constraint(equalTo: textContainer.trailingAnchor, constant: -10),++ // Line 2 (bottom)+ line2.topAnchor.constraint(equalTo: line1.bottomAnchor, constant: 1),+ line2.leadingAnchor.constraint(equalTo: textContainer.leadingAnchor, constant: 10),+ line2.trailingAnchor.constraint(equalTo: textContainer.trailingAnchor, constant: -10),+ line2.bottomAnchor.constraint(equalTo: textContainer.bottomAnchor, constant: -2)+ ])++ // Position container at the bottom (super compact)+ NSLayoutConstraint.activate([+ textContainer.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 8),+ textContainer.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -8),+ textContainer.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -5),+ textContainer.heightAnchor.constraint(equalToConstant: 32) // Super compact for 2 lines+ ])++ line1TextField = line1+ line2TextField = line2++ // Hide container initially+ textContainer.alphaValue = 0.0+ }++ private func createTextField(alpha: CGFloat, fontSize: CGFloat, weight: NSFont.Weight) -> NSTextField {+ let field = NSTextField(frame: .zero)+ field.isEditable = false+ field.isBordered = false+ field.drawsBackground = false+ field.textColor = .white+ field.alignment = .center+ field.font = NSFont.systemFont(ofSize: fontSize, weight: weight)+ field.lineBreakMode = .byTruncatingTail+ field.maximumNumberOfLines = 1+ field.cell?.wraps = false+ field.cell?.isScrollable = false+ field.stringValue = ""+ field.alphaValue = alpha+ field.translatesAutoresizingMaskIntoConstraints = false+ return field+ }++ func setPreviewEnabled(_ enabled: Bool) {+ guard isShowingPreview != enabled else { return }+ isShowingPreview = enabled++ // Resize panel and container+ let width: CGFloat = 340+ let height: CGFloat = enabled ? 100 : 90 // Compact for 2 lines+ let orbY: CGFloat = enabled ? 40 : 10++ NSAnimationContext.runAnimationGroup({ context in+ context.duration = 0.3+ context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)++ if let panel = panel {+ var frame = panel.frame+ let oldHeight = frame.size.height+ frame.size.height = height+ frame.size.width = width+ frame.origin.y += (oldHeight - height) // Keep bottom aligned+ panel.animator().setFrame(frame, display: true)+ }++ if let container = unifiedContainer {+ container.animator().frame = NSRect(x: 0, y: 0, width: width, height: height)+ }++ if let orb = orbView {+ orb.animator().frame = NSRect(x: 0, y: orbY, width: width, height: 70)+ }+ })++ // Show/hide text fields+ if enabled {+ if line1TextField == nil, let containerView = orbView?.superview {+ setupTranscriptionTextField(in: containerView)+ }+ } else {+ line1TextField?.superview?.animator().alphaValue = 0.0+ }+ }++ func updateTranscriptionText(_ text: String)+ {+ guard isShowingPreview else { return } // Don't update if preview disabled++ guard let line1 = line1TextField,+ let line2 = line2TextField,+ let container = line2.superview else { return }++ if text.isEmpty {+ // Fade out container and reset+ NSAnimationContext.runAnimationGroup({ context in+ context.duration = 0.3+ container.animator().alphaValue = 0.0+ })+ line1.stringValue = ""+ line2.stringValue = ""+ previousText = ""+ return+ }++ // Simple scrolling: show last ~100 characters across 2 lines+ let maxChars = 100+ let displayText = text.count > maxChars ? String(text.suffix(maxChars)) : text++ // Split into 2 lines based on space+ let words = displayText.split(separator: " ").map(String.init)++ if words.count <= 6 {+ // Short: only line 2+ line1.stringValue = ""+ line2.stringValue = displayText+ } else {+ // Long: split roughly in half+ let midPoint = words.count / 2+ line1.stringValue = words[..<midPoint].joined(separator: " ")+ line2.stringValue = words[midPoint...].joined(separator: " ")+ }++ previousText = text++ // Fade in container if needed+ if container.alphaValue < 1.0 {+ NSAnimationContext.runAnimationGroup({ context in+ context.duration = 0.3+ container.animator().alphaValue = 1.0+ })+ }+ }}diff --git a/Sources/Fluid/Services/MeetingTranscriptionService.swift b/Sources/Fluid/Services/MeetingTranscriptionService.swiftnew file mode 100644index 00000000..fa23cf22--- /dev/null+++ b/Sources/Fluid/Services/MeetingTranscriptionService.swift@@ -0,0 +1,186 @@+import Foundation+import AVFoundation+import FluidAudio+import Combine++/// Result of a transcription operation+struct TranscriptionResult: Identifiable, Sendable, Codable {+ let id = UUID()+ let text: String+ let confidence: Float+ let duration: TimeInterval+ let processingTime: TimeInterval+ let fileName: String+ let timestamp: Date = Date()++ enum CodingKeys: String, CodingKey {+ case text, confidence, duration, processingTime, fileName, timestamp+ }+}++/// Service for transcribing complete audio/video files with optional speaker diarization+@MainActor+final class MeetingTranscriptionService: ObservableObject {+ @Published var isTranscribing: Bool = false+ @Published var progress: Double = 0.0+ @Published var currentStatus: String = ""+ @Published var error: String?+ @Published var result: TranscriptionResult?++ private var asrManager: AsrManager?+ private var models: AsrModels?++ enum TranscriptionError: LocalizedError {+ case modelLoadFailed(String)+ case audioConversionFailed(String)+ case transcriptionFailed(String)+ case fileNotSupported(String)++ var errorDescription: String? {+ switch self {+ case .modelLoadFailed(let msg):+ return "Failed to load ASR models: \(msg)"+ case .audioConversionFailed(let msg):+ return "Failed to convert audio: \(msg)"+ case .transcriptionFailed(let msg):+ return "Transcription failed: \(msg)"+ case .fileNotSupported(let msg):+ return "File format not supported: \(msg)"+ }+ }+ }++ /// Initialize the ASR models (call this once at app startup or before first transcription)+ func initializeModels() async throws {+ guard models == nil else { return }++ currentStatus = "Downloading ASR models..."+ progress = 0.1++ do {+ models = try await AsrModels.downloadAndLoad()++ asrManager = AsrManager(config: .default)+ try await asrManager?.initialize(models: models!)++ currentStatus = "Models ready"+ progress = 0.0+ } catch {+ throw TranscriptionError.modelLoadFailed(error.localizedDescription)+ }+ }++ /// Transcribe an audio or video file+ /// - Parameters:+ /// - fileURL: URL to the audio/video file+ func transcribeFile(_ fileURL: URL) async throws -> TranscriptionResult {+ isTranscribing = true+ error = nil+ progress = 0.0+ let startTime = Date()++ defer {+ isTranscribing = false+ progress = 0.0+ }++ do {+ // Initialize models if not already done+ if models == nil {+ try await initializeModels()+ }++ guard let asrManager = asrManager else {+ throw TranscriptionError.modelLoadFailed("ASR Manager not initialized")+ }++ // Convert audio to required format (16kHz mono Float32)+ currentStatus = "Converting audio..."+ progress = 0.3++ let converter = AudioConverter()+ let samples: [Float]++ // Check file extension+ let fileExtension = fileURL.pathExtension.lowercased()+ let supportedFormats = ["wav", "mp3", "m4a", "aac", "flac", "aiff", "caf", "mp4", "mov"]++ guard supportedFormats.contains(fileExtension) else {+ throw TranscriptionError.fileNotSupported("Format .\(fileExtension) not supported. Supported: \(supportedFormats.joined(separator: ", "))")+ }++ do {+ samples = try converter.resampleAudioFile(fileURL)+ } catch {+ throw TranscriptionError.audioConversionFailed(error.localizedDescription)+ }++ let duration = Double(samples.count) / 16000.0 // 16kHz sample rate++ // Transcribe+ currentStatus = "Transcribing audio (\(Int(duration))s)..."+ progress = 0.6++ let transcriptionResult = try await asrManager.transcribe(samples, source: .system)++ currentStatus = "Complete!"+ progress = 1.0++ let processingTime = Date().timeIntervalSince(startTime)++ let result = TranscriptionResult(+ text: transcriptionResult.text,+ confidence: transcriptionResult.confidence,+ duration: duration,+ processingTime: processingTime,+ fileName: fileURL.lastPathComponent+ )++ self.result = result+ return result++ } catch let error as TranscriptionError {+ self.error = error.localizedDescription+ throw error+ } catch {+ let wrappedError = TranscriptionError.transcriptionFailed(error.localizedDescription)+ self.error = wrappedError.localizedDescription+ throw wrappedError+ }+ }++ /// Export transcription result to text file+ nonisolated func exportToText(_ result: TranscriptionResult, to destinationURL: URL) throws {+ var content = """+ Transcription: \(result.fileName)+ Date: \(result.timestamp.formatted())+ Duration: \(String(format: "%.1f", result.duration))s+ Processing Time: \(String(format: "%.1f", result.processingTime))s+ Confidence: \(String(format: "%.1f%%", result.confidence * 100))++ ---++ \(result.text)+ """++ try content.write(to: destinationURL, atomically: true, encoding: .utf8)+ }++ /// Export transcription result to JSON+ nonisolated func exportToJSON(_ result: TranscriptionResult, to destinationURL: URL) throws {+ let encoder = JSONEncoder()+ encoder.outputFormatting = [.prettyPrinted, .sortedKeys]+ encoder.dateEncodingStrategy = .iso8601++ let jsonData = try encoder.encode(result)+ try jsonData.write(to: destinationURL)+ }++ /// Reset the service state+ func reset() {+ result = nil+ error = nil+ currentStatus = ""+ progress = 0.0+ }+}diff --git a/Sources/Fluid/TalkingAnimations.swift b/Sources/Fluid/TalkingAnimations.swiftindex 6d379351..19551d1a 100644--- a/Sources/Fluid/TalkingAnimations.swift+++ b/Sources/Fluid/TalkingAnimations.swift@@ -393,8 +393,6 @@ struct PremiumTalkingParticle: View {struct TalkingListeningOverlayView: View {let audioLevelPublisher: AnyPublisher<CGFloat, Never>@StateObject private var appTracker = ActiveAppTracker()- @State private var recordingTime: TimeInterval = 0- @State private var timer: Timer?private var appDisplayName: String {if let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String, name.isEmpty == false {@@ -416,140 +414,12 @@ struct TalkingListeningOverlayView: View {var body: some View {ZStack {- // Premium glassmorphism container- RoundedRectangle(cornerRadius: 16)- .fill(- LinearGradient(- gradient: Gradient(colors: [- Color.black.opacity(0.7),- Color.black.opacity(0.9)- ]),- startPoint: .topLeading,- endPoint: .bottomTrailing- )- )- .background(- RoundedRectangle(cornerRadius: 16)- .fill(- RadialGradient(- gradient: Gradient(colors: [- Color.purple.opacity(0.2),- Color.black.opacity(0.4)- ]),- center: .center,- startRadius: 0,- endRadius: 100- )- )- .blur(radius: 25)- )- .overlay(- RoundedRectangle(cornerRadius: 16)- .stroke(- LinearGradient(- gradient: Gradient(colors: [- Color.white.opacity(0.2),- Color.cyan.opacity(0.1),- Color.purple.opacity(0.1),- Color.clear- ]),- startPoint: .topLeading,- endPoint: .bottomTrailing- ),- lineWidth: 1.5- )- )- .overlay(- // Inner glow- RoundedRectangle(cornerRadius: 16)- .stroke(- Color.white.opacity(0.1),- lineWidth: 0.5- )- .blur(radius: 1)- .offset(x: -1, y: -1)- )-- // Timer - absolutely positioned top-left- Text(formatTime(recordingTime))- .font(.system(size: 12, weight: .medium, design: .monospaced))- .foregroundColor(.white.opacity(0.8))- .padding(.horizontal, 8)- .padding(.vertical, 4)- .background(- RoundedRectangle(cornerRadius: 6)- .fill(Color.black.opacity(0.5))- .overlay(- RoundedRectangle(cornerRadius: 6)- .stroke(Color.white.opacity(0.1), lineWidth: 0.5)- )- )- .padding(.leading, 12)- .padding(.top, 8)- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)+ // NO BACKGROUND - Using unified container from ListeningOverlayController// Centered visualizer - absolutely positionedTalkingAudioVisualizationView(audioLevelPublisher: audioLevelPublisher)- // App name box - absolutely positioned top-right- HStack {- Spacer()- HStack(spacing: 6) {- Image(systemName: "app.fill")- .font(.caption2)- .foregroundColor(.cyan.opacity(0.8))- VStack(alignment: .leading, spacing: 2) {- Text(appTracker.activeAppName)- .font(.caption)- .fontWeight(.medium)- .foregroundColor(.white.opacity(0.95))- .lineLimit(1)- .truncationMode(.tail)- if !appTracker.activeWindowTitle.isEmpty {- Text(appTracker.activeWindowTitle)- .font(.caption2)- .foregroundColor(.white.opacity(0.7))- .lineLimit(1)- .truncationMode(.tail)- }- }- }- .padding(.horizontal, 10)- .padding(.vertical, 6)- .background(- RoundedRectangle(cornerRadius: 8)- .fill(- LinearGradient(- gradient: Gradient(colors: [- Color.black.opacity(0.6),- Color.black.opacity(0.8)- ]),- startPoint: .topLeading,- endPoint: .bottomTrailing- )- )- .overlay(- RoundedRectangle(cornerRadius: 8)- .stroke(- LinearGradient(- gradient: Gradient(colors: [- Color.cyan.opacity(0.3),- Color.purple.opacity(0.2),- Color.clear- ]),- startPoint: .topLeading,- endPoint: .bottomTrailing- ),- lineWidth: 1- )- )- )- .shadow(color: Color.black.opacity(0.4), radius: 3, x: 0, y: 2)- .padding(.trailing, 12)- }- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topTrailing)-- // Brand label - absolutely positioned bottom-right (wordmark if available, else icon + name)+ // Brand label - absolutely positioned center-right (wordmark if available, else icon + name)HStack {Spacer()HStack(spacing: 4) {@@ -559,7 +429,7 @@ struct TalkingListeningOverlayView: View {.interpolation(.high).antialiased(true).scaledToFit()- .frame(height: 35)+ .frame(height: 24).shadow(color: .black.opacity(0.5), radius: 1, x: 0, y: 1)} else {if let nsIcon = NSApp.applicationIconImage {@@ -567,14 +437,14 @@ struct TalkingListeningOverlayView: View {.resizable().interpolation(.high).antialiased(true)- .frame(width: 12, height: 12)+ .frame(width: 14, height: 14).cornerRadius(3).shadow(color: .black.opacity(0.5), radius: 1, x: 0, y: 1)}Text(appDisplayName.uppercased()).font(.system(size: 11, weight: .semibold, design: .rounded))- .kerning(0.6)- .foregroundColor(.white.opacity(0.5))+ .kerning(0.5)+ .foregroundColor(.white.opacity(0.6)).shadow(color: .black.opacity(0.8), radius: 2, x: 1, y: 1).shadow(color: .black.opacity(0.6), radius: 4, x: 2, y: 2).shadow(color: .black.opacity(0.3), radius: 8, x: 0, y: 0)@@ -583,7 +453,7 @@ struct TalkingListeningOverlayView: View {.padding(.horizontal, 8).padding(.vertical, 4).background(- RoundedRectangle(cornerRadius: 12)+ RoundedRectangle(cornerRadius: 14).fill(LinearGradient(gradient: Gradient(colors: [@@ -595,7 +465,7 @@ struct TalkingListeningOverlayView: View {)).overlay(- RoundedRectangle(cornerRadius: 12)+ RoundedRectangle(cornerRadius: 14).stroke(Color.white.opacity(0.1),lineWidth: 0.5@@ -604,47 +474,12 @@ struct TalkingListeningOverlayView: View {).shadow(color: Color.black.opacity(0.3), radius: 2, x: 0, y: 1).padding(.trailing, 12)- .padding(.bottom, 8)}- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)}- .frame(width: 280, height: 80)- .shadow(color: Color.black.opacity(0.6), radius: 25, x: 0, y: 15)- .shadow(color: Color.cyan.opacity(0.2), radius: 15, x: 0, y: 0)- .shadow(color: Color.purple.opacity(0.1), radius: 30, x: 0, y: 5)- .onAppear { startTimerIfNeeded() }- .onDisappear { stopTimer() }+ .frame(maxWidth: .infinity, maxHeight: .infinity).onReceive(audioLevelPublisher) { _ in }}-- private func startTimer() {- recordingTime = 0- timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { _ in- recordingTime += 0.1- }- if let timer {- RunLoop.main.add(timer, forMode: .common)- }- }-- private func startTimerIfNeeded() {- if timer == nil {- startTimer()- }- }-- private func stopTimer() {- timer?.invalidate()- timer = nil- recordingTime = 0- }-- private func formatTime(_ time: TimeInterval) -> String {- let minutes = Int(time) / 60- let seconds = Int(time) % 60- let tenths = Int((time.truncatingRemainder(dividingBy: 1)) * 10)- return String(format: "%02d:%02d.%d", minutes, seconds, tenths)- }}// MARK: - Individual Spokenly Bardiff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swiftnew file mode 100644index 00000000..704ddf7e--- /dev/null+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift@@ -0,0 +1,390 @@+import SwiftUI+import UniformTypeIdentifiers++struct MeetingTranscriptionView: View {+ @StateObject private var transcriptionService = MeetingTranscriptionService()+ @State private var selectedFileURL: URL?+ @State private var showingFilePicker = false+ @State private var showingExportDialog = false+ @State private var exportFormat: ExportFormat = .text+ @State private var showingCopyConfirmation = false++ enum ExportFormat: String, CaseIterable {+ case text = "Text (.txt)"+ case json = "JSON (.json)"++ var fileExtension: String {+ switch self {+ case .text: return "txt"+ case .json: return "json"+ }+ }+ }++ var body: some View {+ VStack(spacing: 0) {+ // Header+ VStack(spacing: 8) {+ Image(systemName: "waveform.circle.fill")+ .font(.system(size: 48))+ .foregroundStyle(.blue.gradient)++ Text("Meeting Transcription")+ .font(.title2)+ .fontWeight(.semibold)++ Text("Upload audio or video files to transcribe")+ .font(.subheadline)+ .foregroundColor(.secondary)+ }+ .padding(.top, 40)+ .padding(.bottom, 30)++ // Main Content Area+ ScrollView {+ VStack(spacing: 24) {+ // File Selection Card+ fileSelectionCard++ // Progress Card (only show when transcribing)+ if transcriptionService.isTranscribing {+ progressCard+ }++ // Results Card (only show when we have results)+ if let result = transcriptionService.result {+ resultsCard(result: result)+ }++ // Error Card (only show when we have an error)+ if let error = transcriptionService.error {+ errorCard(error: error)+ }+ }+ .padding(24)+ }+ }+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .background(Color(nsColor: .windowBackgroundColor))+ .overlay(alignment: .topTrailing) {+ if showingCopyConfirmation {+ Text("Copied!")+ .font(.caption)+ .padding(.horizontal, 12)+ .padding(.vertical, 6)+ .background(.green.opacity(0.9))+ .foregroundColor(.white)+ .cornerRadius(8)+ .padding()+ .transition(.move(edge: .top).combined(with: .opacity))+ }+ }+ }++ // MARK: - File Selection Card++ private var fileSelectionCard: some View {+ VStack(spacing: 16) {+ if let fileURL = selectedFileURL {+ // Show selected file+ HStack {+ Image(systemName: "doc.fill")+ .font(.title2)+ .foregroundColor(.blue)++ VStack(alignment: .leading, spacing: 4) {+ Text(fileURL.lastPathComponent)+ .font(.headline)++ Text(formatFileSize(fileURL: fileURL))+ .font(.caption)+ .foregroundColor(.secondary)+ }++ Spacer()++ Button(action: {+ selectedFileURL = nil+ transcriptionService.reset()+ }) {+ Image(systemName: "xmark.circle.fill")+ .foregroundColor(.secondary)+ }+ .buttonStyle(.plain)+ }+ .padding()+ .background(Color(nsColor: .controlBackgroundColor))+ .cornerRadius(8)++ // Transcribe Button+ Button(action: {+ Task {+ await transcribeFile()+ }+ }) {+ HStack {+ Image(systemName: "waveform")+ Text("Transcribe")+ }+ .frame(maxWidth: .infinity)+ .padding(.vertical, 12)+ }+ .buttonStyle(.borderedProminent)+ .disabled(transcriptionService.isTranscribing)++ } else {+ // File picker button+ Button(action: {+ showingFilePicker = true+ }) {+ VStack(spacing: 12) {+ Image(systemName: "arrow.up.doc.fill")+ .font(.system(size: 32))++ Text("Choose Audio or Video File")+ .font(.headline)++ Text("Supported: WAV, MP3, M4A, MP4, MOV, and more")+ .font(.caption)+ .foregroundColor(.secondary)+ }+ .frame(maxWidth: .infinity)+ .padding(32)+ }+ .buttonStyle(.plain)+ .background(Color(nsColor: .controlBackgroundColor))+ .cornerRadius(12)+ .overlay(+ RoundedRectangle(cornerRadius: 12)+ .strokeBorder(style: StrokeStyle(lineWidth: 2, dash: [8]))+ .foregroundColor(.blue.opacity(0.3))+ )+ }+ }+ .fileImporter(+ isPresented: $showingFilePicker,+ allowedContentTypes: [+ .audio,+ .movie,+ .mpeg4Movie,+ UTType(filenameExtension: "wav")!,+ UTType(filenameExtension: "mp3")!,+ UTType(filenameExtension: "m4a")!,+ ],+ allowsMultipleSelection: false+ ) { result in+ switch result {+ case .success(let urls):+ if let url = urls.first {+ selectedFileURL = url+ transcriptionService.reset()+ }+ case .failure(let error):+ print("File picker error: \(error)")+ }+ }+ }++ // MARK: - Progress Card++ private var progressCard: some View {+ VStack(spacing: 16) {+ ProgressView(value: transcriptionService.progress)+ .progressViewStyle(.linear)++ HStack {+ ProgressView()+ .controlSize(.small)++ Text(transcriptionService.currentStatus)+ .font(.subheadline)+ .foregroundColor(.secondary)+ }+ }+ .padding()+ .background(Color(nsColor: .controlBackgroundColor))+ .cornerRadius(12)+ }++ // MARK: - Results Card++ private func resultsCard(result: TranscriptionResult) -> some View {+ VStack(alignment: .leading, spacing: 16) {+ // Header with stats+ HStack {+ VStack(alignment: .leading, spacing: 4) {+ Text("Transcription Complete")+ .font(.headline)++ HStack(spacing: 16) {+ Label("\(String(format: "%.1f", result.duration))s", systemImage: "clock")+ Label("\(String(format: "%.0f%%", result.confidence * 100))", systemImage: "checkmark.circle")+ Label("\(String(format: "%.1f", result.duration / result.processingTime))x", systemImage: "speedometer")+ }+ .font(.caption)+ .foregroundColor(.secondary)+ }++ Spacer()++ // Action buttons+ HStack(spacing: 8) {+ Button(action: {+ copyToClipboard(result.text)+ }) {+ Image(systemName: "doc.on.doc")+ }+ .help("Copy to clipboard")++ Button(action: {+ showingExportDialog = true+ }) {+ Image(systemName: "square.and.arrow.up")+ }+ .help("Export transcription")+ }+ .buttonStyle(.borderless)+ }++ Divider()++ // Transcription text+ ScrollView {+ Text(result.text)+ .font(.body)+ .textSelection(.enabled)+ .frame(maxWidth: .infinity, alignment: .leading)+ .padding()+ }+ .frame(maxHeight: 300)+ .background(Color(nsColor: .textBackgroundColor))+ .cornerRadius(8)+ }+ .padding()+ .background(Color(nsColor: .controlBackgroundColor))+ .cornerRadius(12)+ .fileExporter(+ isPresented: $showingExportDialog,+ document: TranscriptionDocument(+ result: result,+ format: exportFormat,+ service: transcriptionService+ ),+ contentType: exportFormat == .text ? .plainText : .json,+ defaultFilename: "\(result.fileName)_transcript.\(exportFormat.fileExtension)"+ ) { result in+ switch result {+ case .success:+ print("File exported successfully")+ case .failure(let error):+ print("Export failed: \(error)")+ }+ }+ }++ // MARK: - Error Card++ private func errorCard(error: String) -> some View {+ HStack {+ Image(systemName: "exclamationmark.triangle.fill")+ .foregroundColor(.red)++ Text(error)+ .font(.subheadline)++ Spacer()++ Button("Dismiss") {+ transcriptionService.reset()+ }+ .buttonStyle(.borderless)+ }+ .padding()+ .background(Color.red.opacity(0.1))+ .cornerRadius(12)+ }++ // MARK: - Helper Functions++ private func transcribeFile() async {+ guard let fileURL = selectedFileURL else { return }++ do {+ _ = try await transcriptionService.transcribeFile(fileURL)+ } catch {+ print("Transcription error: \(error)")+ }+ }++ private func formatFileSize(fileURL: URL) -> String {+ guard let attributes = try? FileManager.default.attributesOfItem(atPath: fileURL.path),+ let fileSize = attributes[.size] as? Int64 else {+ return "Unknown size"+ }++ let formatter = ByteCountFormatter()+ formatter.countStyle = .file+ return formatter.string(fromByteCount: fileSize)+ }++ private func copyToClipboard(_ text: String) {+ NSPasteboard.general.clearContents()+ NSPasteboard.general.setString(text, forType: .string)++ withAnimation {+ showingCopyConfirmation = true+ }++ DispatchQueue.main.asyncAfter(deadline: .now() + 2) {+ withAnimation {+ showingCopyConfirmation = false+ }+ }+ }+}++// MARK: - Document for Export++struct TranscriptionDocument: FileDocument {+ static var readableContentTypes: [UTType] { [.plainText, .json] }++ let result: TranscriptionResult+ let format: MeetingTranscriptionView.ExportFormat+ let service: MeetingTranscriptionService++ init(result: TranscriptionResult,+ format: MeetingTranscriptionView.ExportFormat,+ service: MeetingTranscriptionService) {+ self.result = result+ self.format = format+ self.service = service+ }++ init(configuration: ReadConfiguration) throws {+ fatalError("Reading not supported")+ }++ func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {+ let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent("temp.\(format.fileExtension)")++ switch format {+ case .text:+ try service.exportToText(result, to: tempURL)+ case .json:+ try service.exportToJSON(result, to: tempURL)+ }++ let data = try Data(contentsOf: tempURL)+ try? FileManager.default.removeItem(at: tempURL)++ return FileWrapper(regularFileWithContents: data)+ }+}++// MARK: - Preview++#Preview {+ MeetingTranscriptionView()+ .frame(width: 700, height: 800)+}+