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 fixes related to apple speech API

altic-deve40e4bf1ed8d
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swift
index dbea1c2f..9f8e9283 100644
--- a/Sources/Fluid/Services/ASRService.swift
+++ b/Sources/Fluid/Services/ASRService.swift
@@ -193,11 +193,14 @@ final class ASRService: ObservableObject {
self.ensureReadyTask = nil
self.ensureReadyProviderKey = nil
- // CRITICAL FIX: Immediately check if the NEW model's files exist on disk
+ // CRITICAL FIX: Check if the NEW model's files exist on disk
// This prevents UI from showing "Download" when model is already downloaded
- self.checkIfModelsExist()
-
- DebugLogger.shared.info("ASRService: Provider reset complete, will initialize '\(newModel.displayName)' on next use", source: "ASRService")
+ // Use Task for async check to support providers like AppleSpeechAnalyzerProvider
+ Task { [weak self] in
+ guard let self = self else { return }
+ await self.checkIfModelsExistAsync()
+ DebugLogger.shared.info("ASRService: Provider reset complete, will initialize '\(newModel.displayName)' on next use", source: "ASRService")
+ }
}
// CRITICAL FIX (launch-time crash mitigation):
@@ -282,14 +285,17 @@ final class ASRService: ObservableObject {
self.registerDefaultDeviceChangeListener()
- // Check if models exist on disk (deferred from init to avoid FluidAudio/CoreML race)
- self.checkIfModelsExist()
-
- // Auto-load models if they exist on disk to avoid "Downloaded but not loaded" state
- if self.modelsExistOnDisk {
- DebugLogger.shared.info("Models found on disk, auto-loading...", source: "ASRService")
- Task { [weak self] in
- guard let self = self else { return }
+ // Check if models exist on disk and auto-load if present
+ // This is done in a Task to support async model detection (e.g., AppleSpeechAnalyzerProvider)
+ Task { [weak self] in
+ guard let self = self else { return }
+
+ // Use async check to accurately detect models (especially for Apple Speech Analyzer)
+ await self.checkIfModelsExistAsync()
+
+ // Auto-load models if they exist on disk to avoid "Downloaded but not loaded" state
+ if self.modelsExistOnDisk {
+ DebugLogger.shared.info("Models found on disk, auto-loading...", source: "ASRService")
do {
try await self.ensureAsrReady()
DebugLogger.shared.info("Models auto-loaded successfully on startup", source: "ASRService")
@@ -300,12 +306,38 @@ final class ASRService: ObservableObject {
}
}
- /// Check if models exist on disk without loading them
+ /// Check if models exist on disk without loading them (synchronous).
+ ///
+ /// **Note**: For `AppleSpeechAnalyzerProvider`, this returns a cached value that may be stale.
+ /// Use `checkIfModelsExistAsync()` for an up-to-date result.
func checkIfModelsExist() {
self.modelsExistOnDisk = self.transcriptionProvider.modelsExistOnDisk()
DebugLogger.shared.debug("Models exist on disk: \(self.modelsExistOnDisk)", source: "ASRService")
}
+ /// Check if models exist on disk without loading them (async).
+ ///
+ /// This method performs an accurate async check for providers that require it
+ /// (e.g., `AppleSpeechAnalyzerProvider` uses `SpeechTranscriber.installedLocales`).
+ func checkIfModelsExistAsync() async {
+ let model = SettingsStore.shared.selectedSpeechModel
+
+ // For Apple Speech Analyzer, use the async refresh method
+ if model == .appleSpeechAnalyzer {
+ if #available(macOS 26.0, *) {
+ let provider = self.getAppleSpeechAnalyzerProvider()
+ let isInstalled = await provider.refreshModelsExistOnDiskAsync()
+ self.modelsExistOnDisk = isInstalled
+ DebugLogger.shared.debug("Models exist on disk (async): \(self.modelsExistOnDisk)", source: "ASRService")
+ return
+ }
+ }
+
+ // For other providers, use the synchronous method
+ self.modelsExistOnDisk = self.transcriptionProvider.modelsExistOnDisk()
+ DebugLogger.shared.debug("Models exist on disk: \(self.modelsExistOnDisk)", source: "ASRService")
+ }
+
func requestMicAccess() {
AVCaptureDevice.requestAccess(for: .audio) { [weak self] granted in
guard let self = self else { return }
diff --git a/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift b/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift
index 67686981..3cd4e1f0 100644
--- a/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift
+++ b/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift
@@ -27,6 +27,11 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {
/// The required audio format for the analyzer
private var analyzerFormat: AVAudioFormat?
+ /// Thread-safe cache for model installation status.
+ /// Protected by `_cacheQueue` for thread-safe access from both sync and async contexts.
+ private var _modelsInstalledCache: Bool = false
+ private let _cacheQueue = DispatchQueue(label: "com.fluidvoice.speechanalyzer.cache")
+
init() {}
// MARK: - Lifecycle
@@ -77,6 +82,10 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {
self.converter = BufferConverter()
self.isReady = true
+
+ // Update cache to reflect that model is now installed (thread-safe)
+ self._cacheQueue.sync { self._modelsInstalledCache = true }
+
DebugLogger.shared.info("AppleSpeechAnalyzerProvider ready", source: "AppleSpeechAnalyzerProvider")
}
@@ -86,12 +95,44 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {
for locale in reserved {
await AssetInventory.release(reservedLocale: locale)
}
+
+ // Reset cache to reflect models are no longer installed (thread-safe)
+ self._cacheQueue.sync { self._modelsInstalledCache = false }
+
+ self.isReady = false
}
+ /// Returns the cached result of whether models are installed (thread-safe).
+ ///
+ /// **Important**: This method returns a cached value that defaults to `false`.
+ /// For an accurate result, call `refreshModelsExistOnDiskAsync()` first.
+ ///
+ /// The synchronous nature of this protocol method makes it impossible to
+ /// perform the actual async `SpeechTranscriber.installedLocales` check inline.
+ /// Callers should use `refreshModelsExistOnDiskAsync()` during initialization
+ /// to populate the cache before relying on this value.
func modelsExistOnDisk() -> Bool {
- // Check synchronously - we'll report true optimistically
- // since this is called before prepare()
- return true
+ return self._cacheQueue.sync { self._modelsInstalledCache }
+ }
+
+ /// Performs an async check to determine if speech models are installed for the current locale.
+ /// Updates the internal cache so that subsequent `modelsExistOnDisk()` calls return accurate results.
+ /// Thread-safe: uses dispatch queue to update cache.
+ ///
+ /// - Returns: `true` if the current locale's speech model is installed on disk, `false` otherwise.
+ func refreshModelsExistOnDiskAsync() async -> Bool {
+ let installedLocales = await SpeechTranscriber.installedLocales
+ let currentLocaleID = Locale.current.identifier(.bcp47)
+ let isInstalled = installedLocales.map { $0.identifier(.bcp47) }.contains(currentLocaleID)
+
+ self._cacheQueue.sync { self._modelsInstalledCache = isInstalled }
+
+ DebugLogger.shared.debug(
+ "AppleSpeechAnalyzer: Model installed check - locale: \(currentLocaleID), installed: \(isInstalled)",
+ source: "AppleSpeechAnalyzerProvider"
+ )
+
+ return isInstalled
}
// MARK: - Transcription
diff --git a/Sources/Fluid/UI/AISettingsView.swift b/Sources/Fluid/UI/AISettingsView.swift
index 71690d52..d925d815 100644
--- a/Sources/Fluid/UI/AISettingsView.swift
+++ b/Sources/Fluid/UI/AISettingsView.swift
@@ -90,7 +90,10 @@ struct AISettingsView: View {
// CRITICAL FIX: Refresh model status immediately on appear
// This ensures the speech recognition card shows current download status
- self.asr.checkIfModelsExist()
+ // Use async variant for accurate detection (especially for AppleSpeechAnalyzerProvider)
+ Task {
+ await self.asr.checkIfModelsExistAsync()
+ }
}
.onChange(of: self.enableAIProcessing) { _, newValue in
SettingsStore.shared.enableAIProcessing = newValue
diff --git a/Sources/Fluid/UI/WelcomeView.swift b/Sources/Fluid/UI/WelcomeView.swift
index 9cccbee5..c3ff1d4d 100644
--- a/Sources/Fluid/UI/WelcomeView.swift
+++ b/Sources/Fluid/UI/WelcomeView.swift
@@ -470,8 +470,8 @@ struct WelcomeView: View {
// Check microphone status without triggering the full initialize() delay
self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)
- // Check if models exist on disk
- self.asr.checkIfModelsExist()
+ // Check if models exist on disk (async for accurate detection with AppleSpeechAnalyzerProvider)
+ await self.asr.checkIfModelsExistAsync()
}
}
}