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

Added history toggle ; fixed transcrition bug for long sessions (potentially ; needs testing)

altic-dev8b8ff2e0facf
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
deleted file mode 100644
index e69de29b..00000000
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index da6681e8..c94475a9 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -334,7 +334,7 @@ struct ContentView: View {
if self.asr.isRunning {
DebugLogger.shared.debug("NSEvent monitor: Escape pressed, cancelling ASR recording", source: "ContentView")
- self.asr.stopWithoutTranscription()
+ Task { await self.asr.stopWithoutTranscription() }
handled = true
}
@@ -479,7 +479,7 @@ struct ContentView: View {
if self.isRecordingForCommand {
if self.asr.isRunning {
- self.asr.stopWithoutTranscription()
+ Task { await self.asr.stopWithoutTranscription() }
}
self.isRecordingForCommand = false
self.menuBarManager.setOverlayMode(.dictation)
@@ -495,7 +495,7 @@ struct ContentView: View {
if self.isRecordingForRewrite {
if self.asr.isRunning {
- self.asr.stopWithoutTranscription()
+ Task { await self.asr.stopWithoutTranscription() }
}
self.isRecordingForRewrite = false
self.rewriteModeService.clearState()
@@ -531,7 +531,7 @@ struct ContentView: View {
}
}
.onDisappear {
- self.asr.stopWithoutTranscription()
+ Task { await self.asr.stopWithoutTranscription() }
// Note: Overlay lifecycle is now managed by MenuBarManager
// Stop accessibility polling
@@ -1383,14 +1383,16 @@ struct ContentView: View {
DebugLogger.shared.info("Transcription finalized (chars: \(finalText.count))", source: "ContentView")
- // Save to transcription history (transcription mode only)
- let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()
- TranscriptionHistoryStore.shared.addEntry(
- rawText: transcribedText,
- processedText: finalText,
- appName: appInfo.name,
- windowTitle: appInfo.windowTitle
- )
+ // Save to transcription history (transcription mode only, if enabled)
+ if SettingsStore.shared.saveTranscriptionHistory {
+ let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()
+ TranscriptionHistoryStore.shared.addEntry(
+ rawText: transcribedText,
+ processedText: finalText,
+ appName: appInfo.name,
+ windowTitle: appInfo.windowTitle
+ )
+ }
// Copy to clipboard if enabled (happens before typing as a backup)
if SettingsStore.shared.copyTranscriptionToClipboard {
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index cb2c4c62..a9a15bb8 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -61,6 +61,7 @@ final class SettingsStore: ObservableObject {
// Stats Keys
static let userTypingWPM = "UserTypingWPM"
+ static let saveTranscriptionHistory = "SaveTranscriptionHistory"
// Filler Words
static let fillerWords = "FillerWords"
@@ -620,6 +621,19 @@ final class SettingsStore: ObservableObject {
}
}
+ /// Whether to save transcription history for stats tracking
+ /// When disabled, transcriptions are not stored and stats won't update
+ var saveTranscriptionHistory: Bool {
+ get {
+ let value = self.defaults.object(forKey: Keys.saveTranscriptionHistory)
+ return value as? Bool ?? true // Default to true (save history)
+ }
+ set {
+ objectWillChange.send()
+ self.defaults.set(newValue, forKey: Keys.saveTranscriptionHistory)
+ }
+ }
+
// MARK: - Private Methods
private func persistProviderAPIKeys(_ values: [String: String]) {
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swift
index 472c5f63..bd4556be 100644
--- a/Sources/Fluid/Services/ASRService.swift
+++ b/Sources/Fluid/Services/ASRService.swift
@@ -14,6 +14,7 @@ import CoreAudio
/// This implementation enforces strict serialization (non-reentrant) using a task chain.
private actor TranscriptionExecutor {
private var lastTask: Task<Void, Never>?
+ private var currentOperationTask: Task<Any, Error>?
func run<T>(_ operation: @escaping () async throws -> T) async throws -> T {
let previous = self.lastTask
@@ -21,9 +22,21 @@ private actor TranscriptionExecutor {
_ = await previous?.result
return try await operation()
}
+ self.currentOperationTask = Task<Any, Error> { try await task.value }
self.lastTask = Task { _ = try? await task.value }
return try await task.value
}
+
+ /// Cancels any pending operations and waits for the current chain to complete.
+ /// This ensures no in-flight transcription tasks can access deallocated memory.
+ func cancelAndAwaitPending() async {
+ // Cancel the current operation if running
+ self.currentOperationTask?.cancel()
+ // Wait for the last task in the chain to complete (or be cancelled)
+ _ = await self.lastTask?.result
+ self.lastTask = nil
+ self.currentOperationTask = nil
+ }
}
/// A comprehensive speech recognition service that handles real-time audio transcription.
@@ -348,16 +361,23 @@ final class ASRService: ObservableObject {
DebugLogger.shared.debug("stop(): cancelling streaming and preparing final transcription", source: "ASRService")
- self.stopStreamingTimer()
+ // CRITICAL: Set isRunning to false FIRST to signal any in-flight chunks to abort early
+ self.isRunning = false
+
+ // Stop the audio engine to stop new audio from coming in
self.removeEngineTap()
self.engine.stop()
self.engine.reset() // Reset engine state to fully release Bluetooth mic
- self.isRunning = false
+
+ // CRITICAL FIX: Await completion of streaming task AND any pending transcriptions
+ // This prevents use-after-free crashes (EXC_BAD_ACCESS) when clearing buffer
+ await self.stopStreamingTimerAndAwait()
self.isProcessingChunk = false
self.skipNextChunk = false
self.previousFullTranscription.removeAll()
+ // NOW it's safe to access the buffer - all pending tasks have completed
// Thread-safe copy of recorded audio
let pcm = self.audioBuffer.getAll()
self.audioBuffer.clear()
@@ -400,14 +420,21 @@ final class ASRService: ObservableObject {
}
}
- func stopWithoutTranscription() {
+ func stopWithoutTranscription() async {
guard self.isRunning else { return }
- self.stopStreamingTimer()
+ // CRITICAL: Set isRunning to false FIRST to signal any in-flight chunks to abort early
+ self.isRunning = false
+
self.removeEngineTap()
self.engine.stop()
self.engine.reset() // Reset engine state to fully release Bluetooth mic
- self.isRunning = false
+
+ // CRITICAL FIX: Await completion of streaming task AND any pending transcriptions
+ // This prevents use-after-free crashes (EXC_BAD_ACCESS) when clearing buffer
+ await self.stopStreamingTimerAndAwait()
+
+ // NOW it's safe to clear the buffer
self.audioBuffer.clear()
self.isRecordingWholeSession = false
self.partialTranscription.removeAll()
@@ -772,6 +799,24 @@ final class ASRService: ObservableObject {
}
}
+ /// Stops the streaming timer and waits for the task to complete.
+ /// This prevents race conditions where the buffer is cleared while
+ /// a transcription task is still running.
+ private func stopStreamingTimerAndAwait() async {
+ guard let task = self.streamingTask else { return }
+ task.cancel()
+ // Wait for the task to actually finish - this is critical!
+ // The task may be in the middle of processStreamingChunk()
+ _ = await task.result
+ self.streamingTask = nil
+
+ // Also cancel and await any pending transcription in the executor
+ // This prevents use-after-free when we clear the buffer
+ await self.transcriptionExecutor.cancelAndAwaitPending()
+ }
+
+ /// Legacy sync version for cases where we can't await (e.g., stopWithoutTranscription)
+ /// WARNING: This can cause crashes if buffer is cleared immediately after!
private func stopStreamingTimer() {
self.streamingTask?.cancel()
self.streamingTask = nil
diff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swift
index 5d1626c2..a39db9e3 100644
--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift
+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift
@@ -233,7 +233,7 @@ final class GlobalHotkeyManager: NSObject {
if self.asrService.isRunning {
DebugLogger.shared.info("Escape pressed - cancelling recording", source: "GlobalHotkeyManager")
Task { @MainActor in
- self.asrService.stopWithoutTranscription()
+ await self.asrService.stopWithoutTranscription()
}
handled = true
}
@@ -532,7 +532,7 @@ final class GlobalHotkeyManager: NSObject {
if let callback = stopAndProcessCallback {
await callback()
} else {
- self.asrService.stopWithoutTranscription()
+ await self.asrService.stopWithoutTranscription()
}
}
diff --git a/Sources/Fluid/UI/SettingsView.swift b/Sources/Fluid/UI/SettingsView.swift
index f63a1a49..a19335a1 100644
--- a/Sources/Fluid/UI/SettingsView.swift
+++ b/Sources/Fluid/UI/SettingsView.swift
@@ -367,6 +367,17 @@ struct SettingsView: View {
.onChange(of: self.copyToClipboard) { _, newValue in
SettingsStore.shared.copyTranscriptionToClipboard = newValue
}
+
+ Divider().padding(.vertical, 8)
+
+ self.optionToggleRow(
+ title: "Save Transcription History",
+ description: "Save transcriptions for stats tracking. Disable for privacy.",
+ isOn: Binding(
+ get: { SettingsStore.shared.saveTranscriptionHistory },
+ set: { SettingsStore.shared.saveTranscriptionHistory = $0 }
+ )
+ )
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 8, style: .continuous)
@@ -463,8 +474,10 @@ struct SettingsView: View {
SettingsStore.shared.preferredInputDeviceUID = newUID
_ = AudioDevice.setDefaultInputDevice(uid: newUID)
if self.asr.isRunning {
- self.asr.stopWithoutTranscription()
- self.startRecording()
+ Task {
+ await self.asr.stopWithoutTranscription()
+ self.startRecording()
+ }
}
}
// Sync selection when devices load or change