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
feat: add pause media during transcription option
altic-dev7937d87b8136
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex 6c4a8a54..b9fa1bd6 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -90,6 +90,9 @@ final class SettingsStore: ObservableObject {static let overlayBottomOffset = "OverlayBottomOffset"static let overlaySize = "OverlaySize"+ // Media Playback Control+ static let pauseMediaDuringTranscription = "PauseMediaDuringTranscription"+// Custom Dictation Promptstatic let customDictationPrompt = "CustomDictationPrompt"@@ -1310,6 +1313,18 @@ final class SettingsStore: ObservableObject {}}+ // MARK: - Media Playback Control++ /// When enabled, automatically pauses system media playback when transcription starts.+ /// Only resumes if FluidVoice was the one that paused it.+ var pauseMediaDuringTranscription: Bool {+ get { self.defaults.object(forKey: Keys.pauseMediaDuringTranscription) as? Bool ?? false }+ set {+ objectWillChange.send()+ self.defaults.set(newValue, forKey: Keys.pauseMediaDuringTranscription)+ }+ }+// MARK: - Custom Dictionary/// A custom dictionary entry that maps multiple misheard/alternate spellings to a correct replacement.diff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex fbc93529..8f2eb4d2 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -260,6 +260,10 @@ final class ASRService: ObservableObject {private var previousFullTranscription: String = ""private let transcriptionExecutor = TranscriptionExecutor() // Serializes all CoreML access+ /// Tracks whether we paused system media for this recording session.+ /// Used to resume playback only if we were the ones who paused it.+ private var didPauseMediaForThisSession: Bool = false+private var audioLevelSubject = PassthroughSubject<CGFloat, Never>()var audioLevelPublisher: AnyPublisher<CGFloat, Never> { self.audioLevelSubject.eraseToAnyPublisher() }private var lastAudioLevelSentAt: TimeInterval = 0@@ -405,6 +409,22 @@ final class ASRService: ObservableObject {return}+ // Reset media pause state for this session+ self.didPauseMediaForThisSession = false++ // Pause system media if the setting is enabled and something is playing+ if SettingsStore.shared.pauseMediaDuringTranscription {+ Task { @MainActor [weak self] in+ guard let self = self else { return }+ // Only attempt pause if we're still in the "about to start" or "running" state+ let didPause = await MediaPlaybackService.shared.pauseIfPlaying()+ self.didPauseMediaForThisSession = didPause+ if didPause {+ DebugLogger.shared.info("🎵 Paused system media for transcription", source: "ASRService")+ }+ }+ }+DebugLogger.shared.debug("🧹 Clearing buffers and state", source: "ASRService")self.finalText.removeAll()self.audioBuffer.clear(keepingCapacity: true) // specific optimization for restart@@ -507,6 +527,20 @@ final class ASRService: ObservableObject {return ""}+ // Capture media pause state before we reset it, for resuming at the end+ let shouldResumeMedia = SettingsStore.shared.pauseMediaDuringTranscription && self.didPauseMediaForThisSession+ self.didPauseMediaForThisSession = false // Reset for next session++ // Resume media playback at the end of this function if we paused it+ defer {+ if shouldResumeMedia {+ Task { @MainActor in+ await MediaPlaybackService.shared.resumeIfWePaused(true)+ DebugLogger.shared.info("🎵 Resumed system media after transcription", source: "ASRService")+ }+ }+ }+DebugLogger.shared.debug("📍 Preparing final transcription", source: "ASRService")// CRITICAL: Set isRunning to false FIRST to signal any in-flight chunks to abort early@@ -600,6 +634,20 @@ final class ASRService: ObservableObject {func stopWithoutTranscription() async {guard self.isRunning else { return }+ // Capture media pause state before we reset it, for resuming at the end+ let shouldResumeMedia = SettingsStore.shared.pauseMediaDuringTranscription && self.didPauseMediaForThisSession+ self.didPauseMediaForThisSession = false // Reset for next session++ // Resume media playback at the end of this function if we paused it+ defer {+ if shouldResumeMedia {+ Task { @MainActor in+ await MediaPlaybackService.shared.resumeIfWePaused(true)+ DebugLogger.shared.info("🎵 Resumed system media after stopping without transcription", source: "ASRService")+ }+ }+ }+DebugLogger.shared.info("🛑 Stopping recording - releasing audio devices", source: "ASRService")// CRITICAL: Set isRunning to false FIRST to signal any in-flight chunks to abort earlydiff --git a/Sources/Fluid/Services/MediaPlaybackService.swift b/Sources/Fluid/Services/MediaPlaybackService.swiftnew file mode 100644index 00000000..4b623e7f--- /dev/null+++ b/Sources/Fluid/Services/MediaPlaybackService.swift@@ -0,0 +1,103 @@+import Foundation+import MediaRemoteAdapter++/// Service that wraps MediaRemoteAdapter's MediaController to provide+/// controlled pause/resume functionality during transcription.+///+/// This service ensures we only pause media if it's currently playing,+/// and only resume if we were the ones who paused it.+@MainActor+final class MediaPlaybackService {+ static let shared = MediaPlaybackService()++ private let mediaController = MediaController()++ private init() {}++ // MARK: - Public API++ /// Pauses system media playback if something is currently playing.+ ///+ /// - Returns: `true` if we successfully paused playback, `false` if nothing was playing+ /// or if we couldn't determine playback state.+ func pauseIfPlaying() async -> Bool {+ return await withCheckedContinuation { continuation in+ self.mediaController.getTrackInfo { [weak self] trackInfo in+ guard let self = self else {+ continuation.resume(returning: false)+ return+ }++ // If no track info is available, nothing is playing+ guard let trackInfo = trackInfo else {+ DebugLogger.shared.debug(+ "MediaPlaybackService: No track info available, nothing to pause",+ source: "MediaPlaybackService"+ )+ continuation.resume(returning: false)+ return+ }++ // Determine if media is currently playing+ // Use isPlaying if available, otherwise check playbackRate+ let isPlaying: Bool+ if let playing = trackInfo.payload.isPlaying {+ isPlaying = playing+ } else {+ // playbackRate of 1.0 typically means playing, 0.0 means paused+ isPlaying = (trackInfo.payload.playbackRate ?? 0.0) > 0.0+ }++ // Log what we found+ DebugLogger.shared.debug(+ """+ MediaPlaybackService: Track info received+ - App: \(trackInfo.payload.applicationName ?? "Unknown")+ - Bundle: \(trackInfo.payload.bundleIdentifier ?? "Unknown")+ - Title: \(trackInfo.payload.title ?? "Unknown")+ - isPlaying: \(trackInfo.payload.isPlaying?.description ?? "nil")+ - playbackRate: \(trackInfo.payload.playbackRate?.description ?? "nil")+ - Determined playing: \(isPlaying)+ """,+ source: "MediaPlaybackService"+ )++ if isPlaying {+ DebugLogger.shared.info(+ "MediaPlaybackService: Media is playing, sending pause command",+ source: "MediaPlaybackService"+ )+ self.mediaController.pause()+ continuation.resume(returning: true)+ } else {+ DebugLogger.shared.debug(+ "MediaPlaybackService: Media is not playing, no action needed",+ source: "MediaPlaybackService"+ )+ continuation.resume(returning: false)+ }+ }+ }+ }++ /// Resumes media playback only if we were the ones who paused it.+ ///+ /// - Parameter wePaused: `true` if `pauseIfPlaying()` returned `true` for this session.+ func resumeIfWePaused(_ wePaused: Bool) async {+ guard wePaused else {+ DebugLogger.shared.debug(+ "MediaPlaybackService: We didn't pause media, not resuming",+ source: "MediaPlaybackService"+ )+ return+ }++ DebugLogger.shared.info(+ "MediaPlaybackService: Resuming media playback (we paused it)",+ source: "MediaPlaybackService"+ )++ // Use explicit play() command - never toggle+ mediaController.play()+ }+}diff --git a/Sources/Fluid/UI/SettingsView.swift b/Sources/Fluid/UI/SettingsView.swiftindex 9a395da6..55106e3f 100644--- a/Sources/Fluid/UI/SettingsView.swift+++ b/Sources/Fluid/UI/SettingsView.swift@@ -438,6 +438,17 @@ struct SettingsView: View {Divider().padding(.vertical, 8)+ self.optionToggleRow(+ title: "Pause Media During Transcription",+ description: "Automatically pause currently playing audio/video when transcription starts. Resumes only if FluidVoice paused it.",+ isOn: Binding(+ get: { SettingsStore.shared.pauseMediaDuringTranscription },+ set: { SettingsStore.shared.pauseMediaDuringTranscription = $0 }+ )+ )++ Divider().padding(.vertical, 8)+self.optionToggleRow(title: "Share Anonymous Analytics",description: "Send anonymous usage and performance metrics to help improve FluidVoice. Never includes transcription text or prompts.",