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 first-run microphone selection

altic-devef28156ac758
diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swift
index d4838b8a..f7027fa8 100644
--- a/Sources/Fluid/Services/ASRService.swift
+++ b/Sources/Fluid/Services/ASRService.swift
@@ -186,6 +186,11 @@ final class ASRService: ObservableObject {
@Published var downloadingModelId: String? = nil // Tracks which model is currently being downloaded
@Published private(set) var isCancellingModelDownload: Bool = false
@Published private(set) var isDictionaryTrainingCaptureActive: Bool = false
+ @Published private(set) var isMicrophonePreviewActive: Bool = false
+ @Published private(set) var microphonePreviewError: String?
+ @Published private(set) var audioCaptureStateSettledTick: UInt64 = 0
+ private var microphonePreviewOperationGeneration: UInt64 = 0
+ private var isMicrophonePreviewRequested = false
private(set) var lastDictionaryTrainingResult: ASRTranscriptionResult?
private(set) var dictionaryTrainingAudioGeneration = 0
@@ -1488,6 +1493,122 @@ final class ASRService: ObservableObject {
}
}
+ func startMicrophonePreview() async {
+ guard self.micStatus == .authorized,
+ self.isRunning == false,
+ self.isStarting == false,
+ self.isTerminating == false
+ else { return }
+
+ self.microphonePreviewOperationGeneration &+= 1
+ let operationGeneration = self.microphonePreviewOperationGeneration
+ self.isMicrophonePreviewRequested = true
+
+ if self.isMicrophonePreviewActive || self.audioCapturePipeline.isLevelMonitoringEnabled {
+ self.audioCapturePipeline.setLevelMonitoringEnabled(false)
+ _ = await self.directAudioLifecycleController.stop(
+ retainPrepared: false,
+ reason: "onboarding_microphone_preview_restart"
+ )
+ guard operationGeneration == self.microphonePreviewOperationGeneration,
+ self.isMicrophonePreviewRequested,
+ self.isRunning == false,
+ self.isStarting == false,
+ self.isTerminating == false
+ else { return }
+ self.activeAudioCaptureBackend = .none
+ self.isMicrophonePreviewActive = false
+ self.audioLevelSubject.send(0)
+ }
+
+ self.audioEngineStandbyTask?.cancel()
+ self.audioEngineStandbyTask = nil
+ await self.audioEngineRetirementDrain.waitForScheduledReleases()
+ guard operationGeneration == self.microphonePreviewOperationGeneration,
+ self.isMicrophonePreviewRequested,
+ self.isRunning == false,
+ self.isStarting == false,
+ self.isTerminating == false
+ else { return }
+ self.microphonePreviewError = nil
+ self.audioCapturePipeline.setLevelMonitoringEnabled(true)
+
+ do {
+ guard let selection = self.directCoreAudioDeviceSelection() else {
+ throw NSError(
+ domain: "ASRService",
+ code: -4,
+ userInfo: [NSLocalizedDescriptionKey: "No usable microphone is available."]
+ )
+ }
+ let device = try await self.directAudioLifecycleController.resolveDevice(
+ selection: selection,
+ reason: "onboarding_microphone_preview"
+ )
+ try Task.checkCancellation()
+ guard operationGeneration == self.microphonePreviewOperationGeneration,
+ self.isRunning == false,
+ self.isStarting == false,
+ self.isTerminating == false
+ else { throw CancellationError() }
+ _ = try await self.directAudioLifecycleController.start(
+ deviceID: device.id,
+ deviceName: device.name,
+ reason: "onboarding_microphone_preview"
+ )
+ try Task.checkCancellation()
+ guard operationGeneration == self.microphonePreviewOperationGeneration,
+ self.isRunning == false,
+ self.isStarting == false,
+ self.isTerminating == false
+ else { throw CancellationError() }
+ self.activeAudioCaptureBackend = .directCoreAudio
+ self.isMicrophonePreviewActive = true
+ DebugLogger.shared.info(
+ "Started onboarding microphone preview with '\(device.name)'",
+ source: "ASRService"
+ )
+ } catch {
+ // A newer preview, page-exit stop, or dictation start owns cleanup
+ // after invalidating this operation. Do not tear down its capture.
+ guard operationGeneration == self.microphonePreviewOperationGeneration else {
+ return
+ }
+ self.audioCapturePipeline.setLevelMonitoringEnabled(false)
+ await self.directAudioLifecycleController.invalidate(
+ reason: "onboarding_microphone_preview_failed"
+ )
+ self.activeAudioCaptureBackend = .none
+ self.isMicrophonePreviewActive = false
+ self.isMicrophonePreviewRequested = false
+ self.microphonePreviewError = error is CancellationError ? nil : error.localizedDescription
+ guard error is CancellationError == false else { return }
+ DebugLogger.shared.warning(
+ "Onboarding microphone preview failed: \(error.localizedDescription)",
+ source: "ASRService"
+ )
+ }
+ }
+
+ func stopMicrophonePreview(retainPreparedCapture: Bool = true) async {
+ self.microphonePreviewOperationGeneration &+= 1
+ let operationGeneration = self.microphonePreviewOperationGeneration
+ self.isMicrophonePreviewRequested = false
+ guard self.isMicrophonePreviewActive || self.audioCapturePipeline.isLevelMonitoringEnabled else {
+ return
+ }
+
+ self.audioCapturePipeline.setLevelMonitoringEnabled(false)
+ _ = await self.directAudioLifecycleController.stop(
+ retainPrepared: retainPreparedCapture,
+ reason: "onboarding_microphone_preview_stop"
+ )
+ guard operationGeneration == self.microphonePreviewOperationGeneration else { return }
+ self.activeAudioCaptureBackend = .none
+ self.isMicrophonePreviewActive = false
+ self.audioLevelSubject.send(0)
+ }
+
func openSystemSettingsForMic() {
if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone") {
NSWorkspace.shared.open(url)
@@ -1533,6 +1654,9 @@ final class ASRService: ObservableObject {
DebugLogger.shared.warning("START() blocked - app is terminating", source: "ASRService")
return .failed
}
+ if self.isMicrophonePreviewActive || self.audioCapturePipeline.isLevelMonitoringEnabled {
+ await self.stopMicrophonePreview()
+ }
self.audioCaptureStartGeneration &+= 1
let startGeneration = self.audioCaptureStartGeneration
self.isStarting = true
@@ -1909,6 +2033,7 @@ final class ASRService: ObservableObject {
private func finishAudioCaptureStart() {
self.isStarting = false
+ self.audioCaptureStateSettledTick &+= 1
let waiters = self.audioCaptureStartWaiters
self.audioCaptureStartWaiters.removeAll(keepingCapacity: false)
waiters.forEach { $0.resume() }
@@ -1998,6 +2123,7 @@ final class ASRService: ObservableObject {
await self.stopActiveAudioCapture(reason: "recording_stop")
self.audioCapturePipeline.finishRecording()
+ self.audioCaptureStateSettledTick &+= 1
// A prepared direct IOProc owns only fixed memory and registration; it
// does not run hardware, show the mic indicator, or hold Bluetooth in
@@ -2365,6 +2491,7 @@ final class ASRService: ObservableObject {
// Cancel/no-transcription paths stay conservative and retire the engine.
await self.retireAudioEngineAndWait(reason: "stop_without_transcription")
+ self.audioCaptureStateSettledTick &+= 1
// CRITICAL FIX: Await completion of streaming task AND any pending transcriptions
// This prevents use-after-free crashes (EXC_BAD_ACCESS) when clearing buffer
@@ -3028,6 +3155,8 @@ final class ASRService: ObservableObject {
private func recoverIdleAudioRoute(_ request: AudioRouteRecoveryRequest) async {
let shouldRebuild = self.hasPreparedAudioCapture || request.requiresIdlePrewarm
guard shouldRebuild else { return }
+ let shouldRestoreMicrophonePreview = self.isMicrophonePreviewRequested
+ let microphonePreviewGeneration = self.microphonePreviewOperationGeneration
// If another event arrives while retirement is draining, the next
// generation still needs to restore the prepared capture backend.
@@ -3043,10 +3172,17 @@ final class ASRService: ObservableObject {
await self.retireAudioEngineAndWait(reason: "idle_route_change:\(request.reason)")
guard request.generation == self.audioRouteRecoveryGeneration, Task.isCancelled == false else { return }
- await self.prewarmConfiguredAudioCaptureIfPossible(
- reason: "idle_route_change",
- allowDuringRouteRecovery: true
- )
+ if shouldRestoreMicrophonePreview,
+ self.isMicrophonePreviewRequested,
+ microphonePreviewGeneration == self.microphonePreviewOperationGeneration
+ {
+ await self.startMicrophonePreview()
+ } else {
+ await self.prewarmConfiguredAudioCaptureIfPossible(
+ reason: "idle_route_change",
+ allowDuringRouteRecovery: true
+ )
+ }
}
private func recoverActiveAudioRoute(_ request: AudioRouteRecoveryRequest) async {
@@ -4614,6 +4750,7 @@ private final nonisolated class AudioCapturePipeline: @unchecked Sendable {
private let lock = NSLock()
private var recordingEnabled: Bool = false
+ private var levelMonitoringEnabled: Bool = false
private var firstAudioReported: Bool = false
private var recordingSessionID: Int = 0
private var recordingAttemptID: UInt64 = 0
@@ -4679,6 +4816,25 @@ private final nonisolated class AudioCapturePipeline: @unchecked Sendable {
self.lock.unlock()
}
+ var isLevelMonitoringEnabled: Bool {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ return self.levelMonitoringEnabled
+ }
+
+ func setLevelMonitoringEnabled(_ enabled: Bool) {
+ self.lock.lock()
+ self.levelMonitoringEnabled = enabled
+ if enabled == false, self.recordingEnabled == false {
+ self.levelHistory.removeAll(keepingCapacity: true)
+ self.smoothedLevel = 0
+ }
+ self.lock.unlock()
+ if enabled == false {
+ self.onLevel(0)
+ }
+ }
+
/// Sets the exact last acquisition time accepted for the current session.
/// Capture remains enabled until the backend has stopped and drained.
func markRecordingEnd(atHostTime hostTime: UInt64) {
@@ -4745,8 +4901,15 @@ private final nonisolated class AudioCapturePipeline: @unchecked Sendable {
}
self.lock.lock()
- guard self.recordingEnabled else {
+ let recordingEnabled = self.recordingEnabled
+ let levelMonitoringEnabled = self.levelMonitoringEnabled
+ guard recordingEnabled || levelMonitoringEnabled else {
+ self.lock.unlock()
+ return
+ }
+ if recordingEnabled == false {
self.lock.unlock()
+ self.onLevel(self.calculateAudioLevel(samples))
return
}
let startHostTime = self.recordingStartHostTime
diff --git a/Sources/Fluid/Services/MicrophonePreferenceCoordinator.swift b/Sources/Fluid/Services/MicrophonePreferenceCoordinator.swift
index 082835d2..b996f037 100644
--- a/Sources/Fluid/Services/MicrophonePreferenceCoordinator.swift
+++ b/Sources/Fluid/Services/MicrophonePreferenceCoordinator.swift
@@ -87,10 +87,13 @@ final class MicrophonePreferenceCoordinator: ObservableObject {
let enumeratedPreferredInput = availableInputs.first { input in
input.uid == self.settings.preferredInputDeviceUID
}
+ let enumeratedDefaultInput = defaultInputUID.flatMap { uid in
+ availableInputs.first { $0.uid == uid }
+ }
let defaultInput = defaultInputUID.flatMap { uid in
usableInputs.first { $0.uid == uid }
}
- let migrationInputs = defaultInput.map { input in
+ let migrationInputs = enumeratedDefaultInput.map { input in
[input] + availableInputs.filter { $0.uid != input.uid }
} ?? availableInputs
let previousMode = self.settings.storedMicSelectionModeForMigration
@@ -133,9 +136,11 @@ final class MicrophonePreferenceCoordinator: ObservableObject {
?? defaultInput
?? self.fallbackInput(from: usableInputs, defaultInputUID: defaultInputUID)
} else if migrationVersion == 0 {
- selectedInput = defaultInput
- ?? preferredInput
- ?? self.fallbackInput(from: usableInputs, defaultInputUID: defaultInputUID)
+ // A fresh install must mirror macOS's selected input, not permanently
+ // promote whichever fallback happened to enumerate first at launch.
+ // If HAL has not exposed the default yet, leave migration pending;
+ // capture can still use a temporary fallback without saving it.
+ selectedInput = enumeratedDefaultInput
} else if migrationVersion == 1,
let preferredInput,
preferredInput.isBuiltIn,
@@ -151,6 +156,11 @@ final class MicrophonePreferenceCoordinator: ObservableObject {
?? self.fallbackInput(from: usableInputs, defaultInputUID: defaultInputUID)
}
guard let selectedInput else {
+ if migrationVersion == 0,
+ previousMode == .system
+ {
+ return
+ }
self.settings.reconcileMicrophonePriority(with: migrationInputs)
return
}
diff --git a/Sources/Fluid/UI/WelcomeView.swift b/Sources/Fluid/UI/WelcomeView.swift
index 7d70c779..8c69c124 100644
--- a/Sources/Fluid/UI/WelcomeView.swift
+++ b/Sources/Fluid/UI/WelcomeView.swift
@@ -652,6 +652,15 @@ struct OnboardingFlowView: View {
@State private var hoveredModelRouteID: String?
@State private var hoveredModelActionButtonID: String?
@State private var hoveredPermissionButtonID: String?
+ @State private var onboardingInputDevices: [AudioDevice.Device] = []
+ @State private var selectedOnboardingInputUID = ""
+ @State private var previewedOnboardingInputUID: String?
+ @State private var onboardingMicrophoneLevel: CGFloat = 0
+ @State private var lastOnboardingMicrophoneLevelUpdate: TimeInterval = 0
+ @State private var microphonePreviewTask: Task<Void, Never>?
+ @State private var microphonePreviewGeneration: UInt64 = 0
+ @State private var onboardingMicrophoneRefreshGeneration: UInt64 = 0
+ @State private var isOnboardingFlowVisible = false
@State private var hoveredFooterButton: OnboardingFooterButton?
@State private var isShowingAllLanguages = false
@State private var isShowingOtherModelRoutes = false
@@ -936,10 +945,14 @@ struct OnboardingFlowView: View {
}
}
.onAppear {
+ 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()
}
}
@@ -947,14 +960,70 @@ struct OnboardingFlowView: View {
if self.step != .voiceModel {
self.cancelOnboardingModelPreparation()
}
+ if self.step == .permissions, self.isMicrophoneReady {
+ self.refreshOnboardingMicrophones(startPreview: true)
+ } else {
+ self.stopOnboardingMicrophonePreview()
+ }
self.playLandingWelcomeSoundIfNeeded()
}
+ .onChange(of: self.isMicrophoneReady) { _, isReady in
+ guard self.step == .permissions else { return }
+ if isReady {
+ self.refreshOnboardingMicrophones(startPreview: true)
+ } else {
+ self.stopOnboardingMicrophonePreview()
+ }
+ }
+ .onChange(of: self.asr.isStarting) { _, isStarting in
+ guard self.isOnboardingFlowVisible,
+ self.step == .permissions,
+ self.isMicrophoneReady
+ else { return }
+ if isStarting {
+ self.suspendOnboardingMicrophonePreviewForDictation()
+ }
+ }
+ .onChange(of: self.asr.audioCaptureStateSettledTick) { _, _ in
+ guard self.isOnboardingFlowVisible,
+ self.step == .permissions,
+ self.isMicrophoneReady
+ else { return }
+ if self.asr.isRunning || self.asr.isStarting {
+ self.suspendOnboardingMicrophonePreviewForDictation()
+ } else {
+ self.refreshOnboardingMicrophones(startPreview: true)
+ }
+ }
.onDisappear {
+ self.isOnboardingFlowVisible = false
+ self.onboardingMicrophoneRefreshGeneration &+= 1
self.cancelOnboardingModelPreparation()
+ self.stopOnboardingMicrophonePreview()
+ }
+ .onReceive(self.asr.audioLevelPublisher) { level in
+ guard self.step == .permissions, self.isMicrophoneReady else { return }
+ let now = ProcessInfo.processInfo.systemUptime
+ guard level == 0 || now - self.lastOnboardingMicrophoneLevelUpdate >= 0.05 else {
+ return
+ }
+ self.lastOnboardingMicrophoneLevelUpdate = now
+ self.onboardingMicrophoneLevel = level
+ }
+ .onChange(of: self.appServices.audioObserver.changeTick) { _, _ in
+ guard self.step == .permissions, self.isMicrophoneReady else { return }
+ self.refreshOnboardingMicrophones(startPreview: true)
+ }
+ .onChange(of: self.appServices.audioObserver.inputAvailabilityTick) { _, _ in
+ guard self.step == .permissions, self.isMicrophoneReady else { return }
+ self.refreshOnboardingMicrophones(startPreview: true)
}
.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)
+ }
}
}
@@ -1696,9 +1765,9 @@ struct OnboardingFlowView: View {
VStack(spacing: 14) {
self.permissionRow(
stepNumber: 1,
- title: self.isMicrophoneReady ? "Microphone is ready" : "Allow microphone",
+ title: self.isMicrophoneReady ? "Microphone access allowed" : "Allow microphone",
subtitle: self.isMicrophoneReady
- ? "FluidVoice can hear your dictation."
+ ? "Choose the microphone you want FluidVoice to use."
: "macOS will ask once. Click Allow to start dictating.",
systemImage: "mic.fill",
isReady: self.isMicrophoneReady,
@@ -1707,6 +1776,17 @@ struct OnboardingFlowView: View {
self.handleMicrophoneAction()
}
+ if self.isMicrophoneReady {
+ OnboardingMicrophoneSetupPanel(
+ devices: self.orderedOnboardingInputDevices,
+ selectedUID: self.selectedOnboardingInputUID,
+ level: self.onboardingMicrophoneLevel,
+ errorMessage: self.asr.microphonePreviewError,
+ onSelect: { self.selectOnboardingMicrophone(uid: $0) }
+ )
+ .transition(.opacity.combined(with: .move(edge: .top)))
+ }
+
self.permissionRow(
stepNumber: 2,
title: self.accessibilityPermissionTitle,
@@ -2566,6 +2646,17 @@ struct OnboardingFlowView: View {
)
}
+ private var orderedOnboardingInputDevices: [AudioDevice.Device] {
+ let devicesByUID = Dictionary(
+ self.onboardingInputDevices.map { ($0.uid, $0) },
+ uniquingKeysWith: { current, _ in current }
+ )
+ var ordered = self.settings.microphonePriority.compactMap { devicesByUID[$0.uid] }
+ let knownUIDs = Set(ordered.map(\.uid))
+ ordered.append(contentsOf: self.onboardingInputDevices.filter { !knownUIDs.contains($0.uid) })
+ return ordered
+ }
+
private func isOnboardingRouteSelected(_ route: VoiceEngineLanguageRoute) -> Bool {
self.selectedOnboardingRoute?.id == route.id || self.isRouteSelectedInSettings(route)
}
@@ -2719,3 +2810,225 @@ struct OnboardingFlowView: View {
self.goNext()
}
}
+
+private extension OnboardingFlowView {
+ 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)
+ }
+
+ 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()
+ }
+ }
+ }
+ }
+
+ func selectOnboardingMicrophone(uid: String) {
+ guard let device = self.onboardingInputDevices.first(where: { $0.uid == uid }) else {
+ return
+ }
+
+ self.settings.recordInputDeviceSelection(device.uid, name: device.name)
+ self.selectedOnboardingInputUID = device.uid
+ self.onboardingMicrophoneLevel = 0
+ self.lastOnboardingMicrophoneLevelUpdate = 0
+ self.startOnboardingMicrophonePreviewIfNeeded(forceRestart: true)
+ }
+
+ func startOnboardingMicrophonePreviewIfNeeded(forceRestart: Bool = false) {
+ guard self.step == .permissions,
+ self.isOnboardingFlowVisible,
+ self.isMicrophoneReady,
+ self.selectedOnboardingInputUID.isEmpty == false
+ else { return }
+ if forceRestart == false,
+ self.previewedOnboardingInputUID == self.selectedOnboardingInputUID,
+ self.asr.isMicrophonePreviewActive || self.microphonePreviewTask != nil
+ {
+ return
+ }
+
+ let selectedUID = self.selectedOnboardingInputUID
+ self.microphonePreviewGeneration &+= 1
+ let generation = self.microphonePreviewGeneration
+ self.microphonePreviewTask?.cancel()
+ self.previewedOnboardingInputUID = selectedUID
+ self.microphonePreviewTask = Task { @MainActor in
+ await self.asr.stopMicrophonePreview(retainPreparedCapture: false)
+ guard generation == self.microphonePreviewGeneration,
+ Task.isCancelled == false,
+ self.step == .permissions,
+ self.isMicrophoneReady,
+ self.selectedOnboardingInputUID == selectedUID
+ else {
+ if generation == self.microphonePreviewGeneration {
+ self.microphonePreviewTask = nil
+ }
+ return
+ }
+
+ await self.asr.startMicrophonePreview()
+ guard generation == self.microphonePreviewGeneration,
+ Task.isCancelled == false,
+ self.step == .permissions,
+ self.selectedOnboardingInputUID == selectedUID
+ else {
+ if generation == self.microphonePreviewGeneration {
+ await self.asr.stopMicrophonePreview()
+ self.microphonePreviewTask = nil
+ }
+ return
+ }
+ if self.asr.isMicrophonePreviewActive == false {
+ self.previewedOnboardingInputUID = nil
+ }
+ self.microphonePreviewTask = nil
+ }
+ }
+
+ func stopOnboardingMicrophonePreview() {
+ self.microphonePreviewGeneration &+= 1
+ let generation = self.microphonePreviewGeneration
+ self.microphonePreviewTask?.cancel()
+ self.microphonePreviewTask = Task { @MainActor in
+ await self.asr.stopMicrophonePreview()
+ guard generation == self.microphonePreviewGeneration else { return }
+ self.onboardingMicrophoneLevel = 0
+ self.lastOnboardingMicrophoneLevelUpdate = 0
+ self.previewedOnboardingInputUID = nil
+ self.microphonePreviewTask = nil
+ }
+ }
+
+ func suspendOnboardingMicrophonePreviewForDictation() {
+ self.microphonePreviewGeneration &+= 1
+ self.microphonePreviewTask?.cancel()
+ self.microphonePreviewTask = nil
+ self.onboardingMicrophoneLevel = 0
+ self.lastOnboardingMicrophoneLevelUpdate = 0
+ self.previewedOnboardingInputUID = nil
+ }
+}
+
+private struct OnboardingMicrophoneSetupPanel: View {
+ let devices: [AudioDevice.Device]
+ let selectedUID: String
+ let level: CGFloat
+ let errorMessage: String?
+ let onSelect: (String) -> Void
+
+ private var status: (text: String, color: Color) {
+ if let errorMessage, errorMessage.isEmpty == false {
+ return ("Microphone unavailable", Color.orange)
+ }
+ return ("Input level", Color.white.opacity(0.52))
+ }
+
+ var body: some View {
+ let shape = RoundedRectangle(cornerRadius: 16, style: .continuous)
+ let activeBarCount = min(16, max(0, Int(ceil(self.level * 16))))
+
+ VStack(spacing: 0) {
+ HStack(spacing: 14) {
+ Text("Select your microphone")
+ .font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(Color.white.opacity(0.58))
+
+ Spacer(minLength: 12)
+
+ if self.devices.isEmpty {
+ Text("No microphone available")
+ .font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(Color.orange.opacity(0.9))
+ } else {
+ Picker(
+ "Input microphone",
+ selection: Binding(
+ get: { self.selectedUID },
+ set: self.onSelect
+ )
+ ) {
+ ForEach(self.devices) { device in
+ Text(device.name).tag(device.uid)
+ }
+ }
+ .labelsHidden()
+ .pickerStyle(.menu)
+ .frame(width: 248)
+ .tint(.white)
+ .accessibilityHint("Moves the selected microphone to first in FluidVoice priority")
+ }
+ }
+ .padding(.horizontal, 18)
+ .frame(height: 62)
+
+ Rectangle()
+ .fill(Color.white.opacity(0.08))
+ .frame(height: 1)
+ .padding(.horizontal, 18)
+
+ HStack(spacing: 12) {
+ Circle()
+ .fill(self.status.color)
+ .frame(width: 6, height: 6)
+
+ Text(self.status.text)
+ .font(.system(size: 11, weight: .semibold))
+ .foregroundStyle(self.status.color)
+
+ Spacer()
+
+ HStack(spacing: 0) {
+ ForEach(0..<16, id: \.self) { index in
+ Capsule()
+ .fill(
+ index < activeBarCount
+ ? FluidOnboardingLandingColors.blue.opacity(0.92)
+ : Color.white.opacity(0.14)
+ )
+ .frame(width: 5, height: 15)
+
+ if index < 15 {
+ Spacer(minLength: 0)
+ }
+ }
+ }
+ .frame(width: 248)
+ .accessibilityElement(children: .ignore)
+ .accessibilityLabel("Microphone input level")
+ .accessibilityValue("\(Int((self.level * 100).rounded())) percent")
+ }
+ .padding(.horizontal, 18)
+ .frame(height: 50)
+ }
+ .background(
+ shape
+ .fill(Color.white.opacity(0.040))
+ .overlay(shape.stroke(Color.white.opacity(0.10), lineWidth: 1))
+ )
+ }
+}
diff --git a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
index a846001a..0275b5bf 100644
--- a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
+++ b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
@@ -697,6 +697,91 @@ final class HotkeyShortcutTests: XCTestCase {
}
}
+ @MainActor
+ func testFreshInstallWaitsForMacOSDefaultInsteadOfPersistingFallback() throws {
+ try self.withRestoredDefaults(keys: [
+ self.microphoneSelectionModeKey,
+ self.preferredInputDeviceUIDKey,
+ self.microphoneSelectionMigrationVersionKey,
+ ]) {
+ UserDefaults.standard.set(
+ SettingsStore.MicrophoneSelectionMode.system.rawValue,
+ forKey: self.microphoneSelectionModeKey
+ )
+ SettingsStore.shared.preferredInputDeviceUID = nil
+ SettingsStore.shared.microphoneSelectionMigrationVersion = 0
+ let fallback = Self.device(uid: "fallback", name: "Available Fallback")
+ let unsettledDevices = FakeAudioDeviceManager(
+ inputs: [fallback],
+ defaultInputUID: "system-default"
+ )
+ let unsettledCoordinator = MicrophonePreferenceCoordinator(
+ settings: .shared,
+ devices: unsettledDevices
+ )
+
+ let temporarySelection = unsettledCoordinator.reconcileMicrophoneSelection(
+ availableInputs: unsettledDevices.inputs,
+ defaultInputUID: unsettledDevices.defaultInputUID
+ )
+
+ XCTAssertEqual(temporarySelection, fallback)
+ XCTAssertTrue(SettingsStore.shared.microphonePriority.isEmpty)
+ XCTAssertNil(SettingsStore.shared.preferredInputDeviceUID)
+ XCTAssertEqual(SettingsStore.shared.microphoneSelectionMigrationVersion, 0)
+
+ let systemDefault = Self.device(uid: "system-default", name: "macOS Default")
+ let settledDevices = FakeAudioDeviceManager(
+ inputs: [fallback, systemDefault],
+ defaultInputUID: systemDefault.uid
+ )
+ let settledCoordinator = MicrophonePreferenceCoordinator(
+ settings: .shared,
+ devices: settledDevices
+ )
+
+ settledCoordinator.migrateMicrophonePriorityIfNeeded()
+
+ XCTAssertEqual(SettingsStore.shared.microphonePriority.first?.uid, systemDefault.uid)
+ XCTAssertEqual(SettingsStore.shared.preferredInputDeviceUID, systemDefault.uid)
+ XCTAssertEqual(SettingsStore.shared.microphoneSelectionMigrationVersion, 4)
+ }
+ }
+
+ @MainActor
+ func testFreshInstallPrioritizesMacOSDefaultWhileTemporarilyUnusable() throws {
+ try self.withRestoredDefaults(keys: [
+ self.microphoneSelectionModeKey,
+ self.preferredInputDeviceUIDKey,
+ self.microphoneSelectionMigrationVersionKey,
+ ]) {
+ UserDefaults.standard.set(
+ SettingsStore.MicrophoneSelectionMode.system.rawValue,
+ forKey: self.microphoneSelectionModeKey
+ )
+ SettingsStore.shared.preferredInputDeviceUID = nil
+ SettingsStore.shared.microphoneSelectionMigrationVersion = 0
+ let systemDefault = Self.device(uid: "system-default", name: "macOS Default")
+ let fallback = Self.device(uid: "fallback", name: "Available Fallback")
+ let devices = FakeAudioDeviceManager(
+ inputs: [fallback, systemDefault],
+ defaultInputUID: systemDefault.uid,
+ unusableInputUIDs: [systemDefault.uid]
+ )
+ let coordinator = MicrophonePreferenceCoordinator(settings: .shared, devices: devices)
+
+ let resolved = coordinator.reconcileMicrophoneSelection(
+ availableInputs: devices.inputs,
+ defaultInputUID: devices.defaultInputUID
+ )
+
+ XCTAssertEqual(SettingsStore.shared.microphonePriority.map(\.uid), [systemDefault.uid, fallback.uid])
+ XCTAssertEqual(SettingsStore.shared.preferredInputDeviceUID, systemDefault.uid)
+ XCTAssertEqual(resolved, fallback)
+ XCTAssertEqual(SettingsStore.shared.microphoneSelectionMigrationVersion, 4)
+ }
+ }
+
@MainActor
func testMicrophoneMigrationWaitsForAUsableDeviceList() throws {
try self.withRestoredDefaults(keys: [