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

fix gate onboarding audio startup

altic-devc0652d60aa6c
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swift
index 065b0f0c..79d59f15 100644
--- a/Sources/Fluid/Services/ASRService.swift
+++ b/Sources/Fluid/Services/ASRService.swift
@@ -1081,6 +1081,7 @@ final class ASRService: ObservableObject {
private var inputFormat: AVAudioFormat?
private var micPermissionGranted = false
+ private var isRequestingMicrophoneAccess = false
// Internal access for MeetingTranscriptionService to share models
// Note: Only available when using FluidAudioProvider (Apple Silicon)
@@ -1476,18 +1477,31 @@ final class ASRService: ObservableObject {
}
func requestMicAccess() {
- AVCaptureDevice.requestAccess(for: .audio) { [weak self] granted in
- guard let self = self else { return }
- Task { @MainActor in
- self.micPermissionGranted = granted
- self.micStatus = granted ? .authorized : .denied
- if granted {
- AppServices.shared.microphonePreferenceCoordinator.scheduleStartupNoticeIfEligible(
- microphoneAuthorized: true,
- launchAllowsPresentation: (NSApp.delegate as? AppDelegate)?
- .shouldPresentStartupMicrophoneNotice ?? true
- )
- await self.prewarmConfiguredAudioCaptureIfPossible(reason: "permission_granted")
+ guard self.isRequestingMicrophoneAccess == false else { return }
+ self.isRequestingMicrophoneAccess = true
+ Task { @MainActor [weak self] in
+ await AudioStartupGate.shared.scheduleOpenAfterInitialUISettled()
+ await AudioStartupGate.shared.waitUntilOpen()
+ guard let self else { return }
+ guard self.isTerminating == false else {
+ self.isRequestingMicrophoneAccess = false
+ return
+ }
+
+ AVCaptureDevice.requestAccess(for: .audio) { [weak self] granted in
+ guard let self else { return }
+ Task { @MainActor in
+ self.isRequestingMicrophoneAccess = false
+ self.micPermissionGranted = granted
+ self.micStatus = granted ? .authorized : .denied
+ if granted {
+ AppServices.shared.microphonePreferenceCoordinator.scheduleStartupNoticeIfEligible(
+ microphoneAuthorized: true,
+ launchAllowsPresentation: (NSApp.delegate as? AppDelegate)?
+ .shouldPresentStartupMicrophoneNotice ?? true
+ )
+ await self.prewarmConfiguredAudioCaptureIfPossible(reason: "permission_granted")
+ }
}
}
}
diff --git a/Sources/Fluid/UI/WelcomeView.swift b/Sources/Fluid/UI/WelcomeView.swift
index 8c69c124..24377be0 100644
--- a/Sources/Fluid/UI/WelcomeView.swift
+++ b/Sources/Fluid/UI/WelcomeView.swift
@@ -392,13 +392,10 @@ struct WelcomeView: View {
}
}
.onAppear {
- // CRITICAL FIX: Refresh microphone and model status immediately on appear
- // This prevents the Quick Setup from showing stale status before ASRService.initialize() runs
Task { @MainActor in
- // Check microphone status without triggering the full initialize() delay
+ await AudioStartupGate.shared.scheduleOpenAfterInitialUISettled()
+ await AudioStartupGate.shared.waitUntilOpen()
self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)
-
- // Check if models exist on disk (async for accurate detection with AppleSpeechAnalyzerProvider)
await self.asr.checkIfModelsExistAsync()
}
}
@@ -948,13 +945,7 @@ struct OnboardingFlowView: View {
self.isOnboardingFlowVisible = true
self.syncOnboardingSelectionFromSettings()
self.playLandingWelcomeSoundIfNeeded()
- Task { @MainActor in
- self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)
- if self.step == .permissions, self.isMicrophoneReady {
- self.refreshOnboardingMicrophones(startPreview: true)
- }
- await self.asr.checkIfModelsExistAsync()
- }
+ self.refreshOnboardingMicrophoneAuthorization(checkModels: true)
}
.onChange(of: self.currentStep) { _, _ in
if self.step != .voiceModel {
@@ -1020,10 +1011,7 @@ struct OnboardingFlowView: View {
}
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
self.syncOnboardingSelectionFromSettings()
- self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)
- if self.step == .permissions, self.isMicrophoneReady {
- self.refreshOnboardingMicrophones(startPreview: true)
- }
+ self.refreshOnboardingMicrophoneAuthorization()
}
}
@@ -1146,8 +1134,16 @@ struct OnboardingFlowView: View {
private func playLandingWelcomeSoundIfNeeded() {
guard self.step == .landing, !self.hasPlayedLandingWelcomeSound else { return }
- self.hasPlayedLandingWelcomeSound = true
- OnboardingSoundPlayer.shared.playWelcomeSound()
+ Task { @MainActor in
+ await AudioStartupGate.shared.scheduleOpenAfterInitialUISettled()
+ await AudioStartupGate.shared.waitUntilOpen()
+ guard self.isOnboardingFlowVisible,
+ self.step == .landing,
+ self.hasPlayedLandingWelcomeSound == false
+ else { return }
+ self.hasPlayedLandingWelcomeSound = true
+ OnboardingSoundPlayer.shared.playWelcomeSound()
+ }
}
private var languageStep: some View {
@@ -2812,36 +2808,62 @@ struct OnboardingFlowView: View {
}
private extension OnboardingFlowView {
+ func refreshOnboardingMicrophoneAuthorization(checkModels: Bool = false) {
+ Task { @MainActor in
+ await AudioStartupGate.shared.scheduleOpenAfterInitialUISettled()
+ await AudioStartupGate.shared.waitUntilOpen()
+ guard self.isOnboardingFlowVisible else { return }
+
+ self.asr.micStatus = AVCaptureDevice.authorizationStatus(for: .audio)
+ if self.step == .permissions, self.isMicrophoneReady {
+ self.refreshOnboardingMicrophones(startPreview: true)
+ }
+ if checkModels {
+ await self.asr.checkIfModelsExistAsync()
+ }
+ }
+ }
+
func refreshOnboardingMicrophones(startPreview: Bool) {
guard self.isOnboardingFlowVisible else { return }
self.onboardingMicrophoneRefreshGeneration &+= 1
let generation = self.onboardingMicrophoneRefreshGeneration
let suppressedUIDs = self.settings.suppressedMicrophoneUIDs
- DispatchQueue.global(qos: .userInitiated).async {
- let inputs = AudioDevice.listInputDevicesRefreshingLiveness()
- let defaultInputUID = AudioDevice.getDefaultInputDevice()?.uid
- let usableInputs = inputs.filter { device in
- suppressedUIDs.contains(device.uid) == false && AudioDevice.isInputDeviceUsable(device)
- }
+ Task { @MainActor in
+ await AudioStartupGate.shared.scheduleOpenAfterInitialUISettled()
+ await AudioStartupGate.shared.waitUntilOpen()
+ guard generation == self.onboardingMicrophoneRefreshGeneration,
+ self.isOnboardingFlowVisible,
+ self.step == .permissions,
+ self.isMicrophoneReady
+ else { return }
- DispatchQueue.main.async {
- guard generation == self.onboardingMicrophoneRefreshGeneration,
- self.isOnboardingFlowVisible,
- self.step == .permissions,
- self.isMicrophoneReady
- else { return }
+ DispatchQueue.global(qos: .userInitiated).async {
+ let inputs = AudioDevice.listInputDevicesRefreshingLiveness()
+ let defaultInputUID = AudioDevice.getDefaultInputDevice()?.uid
+ let usableInputs = inputs.filter { device in
+ suppressedUIDs.contains(device.uid) == false && AudioDevice.isInputDeviceUsable(device)
+ }
- let selectedInput = self.appServices.microphonePreferenceCoordinator
- .reconcileMicrophoneSelection(
- availableInputs: inputs,
- defaultInputUID: defaultInputUID
- )
- self.onboardingInputDevices = usableInputs
- self.selectedOnboardingInputUID = selectedInput?.uid ?? usableInputs.first?.uid ?? ""
+ DispatchQueue.main.async {
+ guard generation == self.onboardingMicrophoneRefreshGeneration,
+ self.isOnboardingFlowVisible,
+ self.step == .permissions,
+ self.isMicrophoneReady
+ else { return }
+
+ let selectedInput = self.appServices.microphonePreferenceCoordinator
+ .reconcileMicrophoneSelection(
+ availableInputs: inputs,
+ defaultInputUID: defaultInputUID
+ )
+ self.onboardingInputDevices = usableInputs
+ self.selectedOnboardingInputUID = selectedInput?.uid ?? usableInputs.first?.uid ?? ""
- if startPreview {
- self.startOnboardingMicrophonePreviewIfNeeded()
+ if startPreview {
+ self.startOnboardingMicrophonePreviewIfNeeded()
+ }
}
}
}