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 isolate microphone availability updates

altic-dev3e04401a16c0
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index b2383181..a3cacb21 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -389,6 +389,9 @@ struct ContentView: View {
self.selectedOutputUID = sysOut
}
}
+ .onChange(of: self.audioObserver.inputAvailabilityTick) { _, _ in
+ self.refreshInputDevices()
+ }
.onDisappear {
Task { await self.asr.stopWithoutTranscription() }
self.cancelPrewarmDictationIfNeeded()
@@ -1537,6 +1540,24 @@ struct ContentView: View {
}
}
+ private func refreshInputDevices() {
+ DispatchQueue.global(qos: .userInitiated).async {
+ let inputs = AudioDevice.listInputDevicesRefreshingLiveness()
+ let defaultInputUID = AudioDevice.getDefaultInputDevice()?.uid
+ DispatchQueue.main.async {
+ self.inputDevices = inputs
+ if let selectedInput = self.appServices.microphonePreferenceCoordinator
+ .reconcileMicrophoneSelection(
+ availableInputs: inputs,
+ defaultInputUID: defaultInputUID
+ )
+ {
+ self.selectedInputUID = selectedInput.uid
+ }
+ }
+ }
+ }
+
// MARK: - Model Management Functions
private func saveModels() {
diff --git a/Sources/Fluid/Services/AudioDeviceService.swift b/Sources/Fluid/Services/AudioDeviceService.swift
index b2d50d5e..4cd86152 100644
--- a/Sources/Fluid/Services/AudioDeviceService.swift
+++ b/Sources/Fluid/Services/AudioDeviceService.swift
@@ -400,6 +400,7 @@ final class AudioHardwareObserver: ObservableObject {
/// Using a simple `@Published` value avoids putting `AnyPublisher`/`SubscriptionView` generics into
/// SwiftUI's root view type, which can trigger AttributeGraph metadata-instantiation crashes at launch.
@Published private(set) var changeTick: UInt64 = 0
+ @Published private(set) var inputAvailabilityTick: UInt64 = 0
private var installed: Bool = false
private var devicesListenerToken: AudioObjectPropertyListenerBlock?
@@ -427,7 +428,7 @@ final class AudioHardwareObserver: ObservableObject {
@MainActor
func signalInputAvailabilityChanged() {
- self.changeTick &+= 1
+ self.inputAvailabilityTick &+= 1
}
func restartObservingAfterAudioServiceReset() {
@@ -484,7 +485,7 @@ final class AudioHardwareObserver: ObservableObject {
self?.refreshInputAvailabilityListeners()
}
let defaultInToken: AudioObjectPropertyListenerBlock = { [weak self] _, _ in
- self?.changeTick &+= 1
+ self?.inputAvailabilityTick &+= 1
}
let defaultOutToken: AudioObjectPropertyListenerBlock = { [weak self] _, _ in
self?.changeTick &+= 1
@@ -594,7 +595,7 @@ final class AudioHardwareObserver: ObservableObject {
_ = AudioDevice.listInputDevicesRefreshingLiveness()
DispatchQueue.main.async { [weak self] in
guard let self else { return }
- self.changeTick &+= 1
+ self.inputAvailabilityTick &+= 1
NotificationCenter.default.post(
name: .inputDeviceAvailabilityDidChange,
object: self,
@@ -706,7 +707,7 @@ final class AudioHardwareObserver: ObservableObject {
let isClosed = ClamshellState.isClosed
guard isClosed != self.lastClamshellClosed else { return }
self.lastClamshellClosed = isClosed
- self.changeTick &+= 1
+ self.inputAvailabilityTick &+= 1
DebugLogger.shared.info(
"MacBook clamshell state changed (closed=\(isClosed))",
source: "AudioHardwareObserver"
diff --git a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
index b23ab78c..00e56455 100644
--- a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
+++ b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
@@ -993,6 +993,16 @@ final class HotkeyShortcutTests: XCTestCase {
XCTAssertFalse(AudioDevice.isInputDeviceAlive(unavailable))
}
+ @MainActor
+ func testInputAvailabilitySignalDoesNotEmitGenericHardwareChange() {
+ let observer = AudioHardwareObserver()
+
+ observer.signalInputAvailabilityChanged()
+
+ XCTAssertEqual(observer.inputAvailabilityTick, 1)
+ XCTAssertEqual(observer.changeTick, 0)
+ }
+
@MainActor
func testClamshellSkipsEnumeratedUnusableBuiltInMicrophone() throws {
try self.withRestoredDefaults(keys: [