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

bug fix - menu bar optimizations ; extra useless debug removal from AI PP ; ASR better sleep mode for chunk processing

altic-dev3b59eb383e38
diff --git a/Sources/Fluid/Networking/AIProvider.swift b/Sources/Fluid/Networking/AIProvider.swift
index ee5f4fd3..2a67f34c 100644
--- a/Sources/Fluid/Networking/AIProvider.swift
+++ b/Sources/Fluid/Networking/AIProvider.swift
@@ -117,20 +117,17 @@ final class OpenAICompatibleProvider: AIProvider
{
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 DEBUG
+ DebugLogger.shared.debug("AI Request to: \(request.url?.absoluteString ?? "unknown")", source: "AIProvider")
if let http = response as? HTTPURLResponse {
- print("HTTP Status: \(http.statusCode)")
+ DebugLogger.shared.debug("HTTP Status: \(http.statusCode)", source: "AIProvider")
}
- if let responseText = String(data: data, encoding: .utf8) {
- print("Raw Response: \(responseText)")
- }
- print("============================")
+ #endif
if let http = response as? HTTPURLResponse, http.statusCode >= 400
{
let errText = String(data: data, encoding: .utf8) ?? "Unknown error"
+ DebugLogger.shared.error("AI API error HTTP \(http.statusCode): \(errText)", source: "AIProvider")
return "Error: HTTP \(http.statusCode): \(errText)"
}
let decoded = try JSONDecoder().decode(ChatResponse.self, from: data)
@@ -138,12 +135,12 @@ final class OpenAICompatibleProvider: AIProvider
}
catch
{
- print("=== OLLAMA DECODE ERROR ===")
- print("Error: \(error)")
+ DebugLogger.shared.error("AI API request failed: \(error.localizedDescription)", source: "AIProvider")
+ #if DEBUG
if let decodingError = error as? DecodingError {
- print("Decoding Error Details: \(decodingError)")
+ DebugLogger.shared.debug("Decoding error details: \(decodingError)", source: "AIProvider")
}
- print("==========================")
+ #endif
return "Error: \(error.localizedDescription)"
}
}
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swift
index 9e9154cb..496995f0 100644
--- a/Sources/Fluid/Services/ASRService.swift
+++ b/Sources/Fluid/Services/ASRService.swift
@@ -70,8 +70,8 @@ final class ASRService: ObservableObject
private var isRecordingWholeSession: Bool = false
private var recordedPCM: [Float] = []
- // Streaming transcription properties (timer-based, no VAD)
- private var streamingTimer: Timer?
+ // Streaming transcription state (no VAD)
+ private var streamingTask: Task<Void, Never>?
private var lastProcessedSampleCount: Int = 0
private let chunkDurationSeconds: Double = 2.0 // Safer interval to prevent ANE/CoreML conflicts
private var isProcessingChunk: Bool = false
@@ -684,24 +684,37 @@ final class ASRService: ObservableObject
// MARK: - Timer-based Streaming Transcription (No VAD)
private func startStreamingTranscription() {
- stopStreamingTimer()
+ streamingTask?.cancel()
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()
- }
- }
+
+ DebugLogger.shared.debug("Starting streaming transcription task (interval: \(chunkDurationSeconds)s)", source: "ASRService")
+
+ streamingTask = Task { [weak self] in
+ await self?.runStreamingLoop()
}
}
-
+
private func stopStreamingTimer() {
- streamingTimer?.invalidate()
- streamingTimer = nil
+ streamingTask?.cancel()
+ streamingTask = nil
+ }
+
+ @MainActor
+ private func runStreamingLoop() async {
+ while !Task.isCancelled {
+ await processStreamingChunk()
+
+ if Task.isCancelled || isRunning == false {
+ break
+ }
+
+ do {
+ try await Task.sleep(nanoseconds: UInt64(chunkDurationSeconds * 1_000_000_000))
+ } catch {
+ DebugLogger.shared.debug("Streaming transcription task cancelled", source: "ASRService")
+ break
+ }
+ }
}
@MainActor
diff --git a/Sources/Fluid/Services/MenuBarManager.swift b/Sources/Fluid/Services/MenuBarManager.swift
index e92c15a7..17348876 100644
--- a/Sources/Fluid/Services/MenuBarManager.swift
+++ b/Sources/Fluid/Services/MenuBarManager.swift
@@ -9,6 +9,10 @@ final class MenuBarManager: ObservableObject {
private var menu: NSMenu?
private var isSetup: Bool = false
+ // Cached menu items to avoid rebuilding entire menu
+ private var statusMenuItem: NSMenuItem?
+ private var aiMenuItem: NSMenuItem?
+
// References to app state
private weak var asrService: ASRService?
private var cancellables = Set<AnyCancellable>()
@@ -211,38 +215,22 @@ final class MenuBarManager: ObservableObject {
return image
}
- private func updateMenu() {
+ private func buildMenuStructure() {
guard let menu = menu else { return }
menu.removeAllItems()
- // Status indicator
- let statusTitle = isRecording ? "Recording..." : "Ready to Record"
- let statusItem = NSMenuItem(title: statusTitle, action: nil, keyEquivalent: "")
- statusItem.isEnabled = false
- menu.addItem(statusItem)
+ // Status indicator with hotkey info
+ statusMenuItem = NSMenuItem(title: "", action: nil, keyEquivalent: "")
+ statusMenuItem?.isEnabled = false
+ menu.addItem(statusMenuItem!)
menu.addItem(.separator())
- // Start/Stop Recording
- let recordingAction = isRecording ? "Stop Recording" : "Start Recording"
- let recordingItem = NSMenuItem(title: recordingAction, action: #selector(toggleRecording), keyEquivalent: "")
- recordingItem.target = self
-
- // Show hotkey if available
- let hotkeyShortcut = SettingsStore.shared.hotkeyShortcut
- recordingItem.keyEquivalent = "" // We'll show it in the title instead
- if !hotkeyShortcut.displayString.isEmpty {
- recordingItem.title = "\(recordingAction) (\(hotkeyShortcut.displayString))"
- }
-
- menu.addItem(recordingItem)
-
// AI Processing Toggle
- let aiTitle = aiProcessingEnabled ? "Disable AI Processing" : "Enable AI Processing"
- let aiItem = NSMenuItem(title: aiTitle, action: #selector(toggleAIProcessing), keyEquivalent: "")
- aiItem.target = self
- menu.addItem(aiItem)
+ aiMenuItem = NSMenuItem(title: "", action: #selector(toggleAIProcessing), keyEquivalent: "")
+ aiMenuItem?.target = self
+ menu.addItem(aiMenuItem!)
menu.addItem(.separator())
@@ -262,20 +250,33 @@ final class MenuBarManager: ObservableObject {
let quitItem = NSMenuItem(title: "Quit FluidVoice", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
quitItem.target = NSApp
menu.addItem(quitItem)
+
+ // Now update the text content
+ updateMenuItemsText()
}
- @objc private func toggleRecording() {
- guard let asrService = asrService else { return }
-
- if isRecording {
- Task {
- _ = await asrService.stop()
- }
+ private func updateMenu() {
+ // If menu structure hasn't been built yet, build it
+ if statusMenuItem == nil {
+ buildMenuStructure()
} else {
- asrService.start()
+ // Just update the text of existing items
+ updateMenuItemsText()
}
}
+ private func updateMenuItemsText() {
+ // Update status text with hotkey info
+ let hotkeyShortcut = SettingsStore.shared.hotkeyShortcut
+ let hotkeyInfo = hotkeyShortcut.displayString.isEmpty ? "" : " (\(hotkeyShortcut.displayString))"
+ let statusTitle = isRecording ? "Recording...\(hotkeyInfo)" : "Ready to Record\(hotkeyInfo)"
+ statusMenuItem?.title = statusTitle
+
+ // Update AI toggle text
+ let aiTitle = aiProcessingEnabled ? "Disable AI Processing" : "Enable AI Processing"
+ aiMenuItem?.title = aiTitle
+ }
+
@objc private func toggleAIProcessing() {
aiProcessingEnabled.toggle()
// Persist and broadcast change