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
Lint and format
altic-dev335e7012de98
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex 9e803d36..7545e95a 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -917,12 +917,12 @@ final class SettingsStore: ObservableObject {// MARK: - FluidAudio Models (Apple Silicon Only)case parakeetTDT = "parakeet-tdt"-+// MARK: - Apple Nativecase appleSpeech = "apple-speech"case appleSpeechAnalyzer = "apple-speech-analyzer"-+// MARK: - Whisper Models (Universal)case whisperTiny = "whisper-tiny"@@ -1028,7 +1028,7 @@ final class SettingsStore: ObservableObject {static var availableModels: [SpeechModel] {allCases.filter { model in// Filter by Apple Silicon requirement- if model.requiresAppleSilicon && !CPUArchitecture.isAppleSilicon {+ if model.requiresAppleSilicon, !CPUArchitecture.isAppleSilicon {return false}// Filter by macOS 26 requirementdiff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex 9f909e8d..dbea1c2f 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -177,7 +177,6 @@ final class ASRService: ObservableObject {return provider}-/// Returns the user-friendly name of the currently selected speech modelvar activeProviderName: String {SettingsStore.shared.selectedSpeechModel.displayName@@ -187,7 +186,7 @@ final class ASRService: ObservableObject {func resetTranscriptionProvider() {let newModel = SettingsStore.shared.selectedSpeechModelDebugLogger.shared.info("ASRService: Switching to '\(newModel.displayName)', resetting provider state...", source: "ASRService")-+self.isAsrReady = falseself.modelsExistOnDisk = falseself.ensureReadyTask?.cancel()@@ -197,7 +196,7 @@ final class ASRService: ObservableObject {// CRITICAL FIX: Immediately check if the NEW model's files exist on disk// This prevents UI from showing "Download" when model is already downloadedself.checkIfModelsExist()-+DebugLogger.shared.info("ASRService: Provider reset complete, will initialize '\(newModel.displayName)' on next use", source: "ASRService")}@@ -1081,8 +1080,8 @@ final class ASRService: ObservableObject {/// Cache for compiled custom dictionary regexes./// Key: trigger word, Value: (compiled regex, replacement text)/// Cleared when dictionary entries change.- private static var cachedDictionaryPatterns: [(regex: NSRegularExpression, replacement: String)]?- private static var cachedDictionaryVersion: Int = 0+ private static var cachedDictionaryPatterns: [(regex: NSRegularExpression, replacement: String)] = []+ private static var dictionaryCacheNeedsRebuild: Bool = true/// Rebuilds the regex cache if dictionary has changed./// Called lazily on first apply after settings change.@@ -1104,12 +1103,13 @@ final class ASRService: ObservableObject {}}- cachedDictionaryPatterns = patterns+ self.cachedDictionaryPatterns = patterns+ self.dictionaryCacheNeedsRebuild = false}/// Invalidates the dictionary cache. Called when settings change.static func invalidateDictionaryCache() {- cachedDictionaryPatterns = nil+ self.dictionaryCacheNeedsRebuild = true}/// Applies custom dictionary replacements to transcribed text.@@ -1122,18 +1122,18 @@ final class ASRService: ObservableObject {guard !entries.isEmpty else { return text }// Rebuild cache if needed (lazy initialization)- if cachedDictionaryPatterns == nil {- rebuildDictionaryCache()+ if self.dictionaryCacheNeedsRebuild {+ self.rebuildDictionaryCache()}- guard let patterns = cachedDictionaryPatterns, !patterns.isEmpty else {+ guard !self.cachedDictionaryPatterns.isEmpty else {return text}var result = text// Apply cached regexes - O(n) where n = number of patterns- for pattern in patterns {+ for pattern in self.cachedDictionaryPatterns {result = pattern.regex.stringByReplacingMatches(in: result,range: NSRange(result.startIndex..., in: result),diff --git a/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift b/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swiftindex 1bd2807f..67686981 100644--- a/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift+++ b/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift@@ -63,7 +63,7 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {// Report progress periodically during downloadlet progress = downloader.progressTask {- while !progress.isFinished && !progress.isCancelled {+ while !progress.isFinished, !progress.isCancelled {progressHandler?(progress.fractionCompleted)try? await Task.sleep(for: .milliseconds(100))}@@ -97,7 +97,7 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {// MARK: - Transcriptionfunc transcribe(_ samples: [Float]) async throws -> ASRTranscriptionResult {- guard isReady, let analyzerFormat = self.analyzerFormat else {+ guard self.isReady, let analyzerFormat = self.analyzerFormat else {throw NSError(domain: "AppleSpeechAnalyzerProvider",code: 2,@@ -198,7 +198,7 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {private func createPCMBuffer(from samples: [Float]) -> AVAudioPCMBuffer? {guard let format = AVAudioFormat(commonFormat: .pcmFormatFloat32,- sampleRate: 16000,+ sampleRate: 16_000,channels: 1,interleaved: false) else {diff --git a/Sources/Fluid/Services/AppleSpeechProvider.swift b/Sources/Fluid/Services/AppleSpeechProvider.swiftindex 6aba5bbd..af32948a 100644--- a/Sources/Fluid/Services/AppleSpeechProvider.swift+++ b/Sources/Fluid/Services/AppleSpeechProvider.swift@@ -32,7 +32,7 @@ final class AppleSpeechProvider: TranscriptionProvider {func prepare(progressHandler: ((Double) -> Void)?) async throws {// 1. Request Authorizationlet status = await self.requestAuthorization()-+switch status {case .authorized:self.isReady = true@@ -91,11 +91,11 @@ final class AppleSpeechProvider: TranscriptionProvider {// 4. Execute Recognitionreturn try await withCheckedThrowingContinuation { continuation invar hasResumed = false-+recognizer.recognitionTask(with: request) { result, error in// Ensure we only resume onceguard !hasResumed else { return }-+if let error = error {hasResumed = true// Ignore "No speech detected" errors often returned for silent chunks@@ -120,7 +120,7 @@ final class AppleSpeechProvider: TranscriptionProvider {/// Converts raw [Float] samples (16kHz mono) to AVAudioPCMBufferprivate func createPCMBuffer(from samples: [Float]) -> AVAudioPCMBuffer? {// Define format: 16kHz, Mono, Float32 (standard for ML/ASR)- guard let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16000, channels: 1, interleaved: false) else {+ guard let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16_000, channels: 1, interleaved: false) else {return nil}@@ -132,7 +132,7 @@ final class AppleSpeechProvider: TranscriptionProvider {// Efficient copyguard let channelData = buffer.floatChannelData else { return nil }-+// Use withUnsafeBufferPointer for safe memory accesssamples.withUnsafeBufferPointer { samplePtr inguard let baseAddress = samplePtr.baseAddress else { return }diff --git a/Sources/Fluid/UI/CustomDictionaryView.swift b/Sources/Fluid/UI/CustomDictionaryView.swiftindex 1a89ff79..f0e22dbd 100644--- a/Sources/Fluid/UI/CustomDictionaryView.swift+++ b/Sources/Fluid/UI/CustomDictionaryView.swift@@ -295,7 +295,7 @@ struct CustomDictionaryView: View {/// Returns all existing trigger words for duplicate detectionprivate func allExistingTriggers(excluding entryId: UUID? = nil) -> Set<String> {var triggers = Set<String>()- for entry in entries where entry.id != entryId {+ for entry in self.entries where entry.id != entryId {for trigger in entry.triggers {triggers.insert(trigger.lowercased())}@@ -394,8 +394,8 @@ struct AddDictionaryEntrySheet: View {private var canSave: Bool {!self.parseTriggers().isEmpty &&- !self.replacement.trimmingCharacters(in: .whitespaces).isEmpty &&- self.duplicateTriggers.isEmpty+ !self.replacement.trimmingCharacters(in: .whitespaces).isEmpty &&+ self.duplicateTriggers.isEmpty}var body: some View {@@ -537,8 +537,8 @@ struct EditDictionaryEntrySheet: View {private var canSave: Bool {!self.parseTriggers().isEmpty &&- !self.replacement.trimmingCharacters(in: .whitespaces).isEmpty &&- self.duplicateTriggers.isEmpty+ !self.replacement.trimmingCharacters(in: .whitespaces).isEmpty &&+ self.duplicateTriggers.isEmpty}var body: some View {