FluidVoice icon indicating copy to clipboard operation
FluidVoice copied to clipboard

feat(media): add option to duck media volume instead of pausing

Open akar016012 opened this issue 5 months ago • 5 comments

What

Adds a "Lower Volume Instead of Pausing" sub-option under the existing Pause Media During Transcription setting. When enabled, FluidVoice lowers the system output volume while you dictate and restores it afterward, instead of fully stopping playback — handy for keeping a video audible but quiet during narration/dictation.

Why

Today the only choice is to fully pause media during transcription. Some users would rather keep media playing at a lower volume than have it stop and resume.

Changes

  • SystemAudioVolumeController (new): a small CoreAudio wrapper that reads/sets the default output device's volume (master element with a per-channel fallback).
  • MediaPlaybackService: now either pauses or ducks based on the setting, recording which action it took so it reverts exactly what it applied. On restore it:
    • leaves the volume untouched if the user changed it mid-dictation, and
    • falls back to pausing if the volume can't be lowered.
  • Settings (SettingsStore + BackupService): adds duckMediaInsteadOfPausing (Bool) and duckMediaVolumeLevel (fraction of current volume, default 20%, clamped 5–100%), including backup/restore with backward-compatible decoding.
  • UI (SettingsView): nested toggle + level slider, shown only when media pausing is enabled.

Notes / trade-offs

  • CoreAudio output volume is system-wide, so ducking lowers all output from the default device, not just a single app. macOS does not expose per-app media ducking to third-party apps. The UI copy makes this explicit.
  • Behavior is arm64-only, consistent with the existing pause feature (which relies on MediaRemoteAdapter for playback detection). Intel remains a no-op.
  • No entitlement changes required (app is not sandboxed).

Testing

Verified the new CoreAudio file with swiftc -typecheck against the macOS SDK, and swiftc -parse on all edited files (clean). I was able to run the application using my team id on a M1 Pro chip MacBook Pro and verified the functionality

Type of Change

  • [ ] 🐞 Bug fix (non-breaking change which fixes an issue)
  • [x] ✨ New feature (non-breaking change which adds functionality)
  • [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] 🧹 Chore
  • [ ] 📝 Documentation update
image

akar016012 avatar Jun 28 '26 16:06 akar016012

@altic-dev Could you take a look at this PR and approve if you want to go ahead with this feature? Please release a new version so that people can start testing or maybe release a pre-release version so that people can start testing and let me know if there are any issues and I'll work on it right away.

akar016012 avatar Jun 29 '26 01:06 akar016012

I think there was a stale PR on this. Did you check if it's the same stuff? Would love to merge it once its cleared up and can release as part of next version later :)

Don't think this could be a release by itself ahah.

altic-dev avatar Jun 29 '26 02:06 altic-dev

I think there was a stale PR on this. Did you check if it's the same stuff? Would love to merge it once its cleared up and can release as part of next version later :)

Don't think this could be a release by itself ahah.

Next release would do just fine, thank you 😊. I can build and run this locally until the next release.

I will look into the stale PR and let you know.

akar016012 avatar Jun 29 '26 11:06 akar016012

Comparison: this PR (#459) vs #325

Both PRs implement the same core feature — duck (lower) system volume during transcription instead of fully pausing media — landing on overlapping files.

Overview

#459 (this PR) #325
Title feat(media): add option to duck media volume instead of pausing Music duck and keep-awake behaviour during dictation
Author akar016012 AndrewBeniston
Created 2026-06-28 2026-05-06 (~7 wks earlier)
State Open, MERGEABLE Open, CONFLICTING (needs rebase)
Commits 7 3
Diff size +414 / −21, 6 files +610 / −64, 8 files
Scope Ducking only Ducking + Keep Mac Awake (2 features)

Feature & UX

Dimension #459 (this PR) #325
Settings UI Nested sub-toggle + slider under existing "Pause Media" toggle (keeps the Bool) Replaces the Bool with a 3-mode picker: Leave Playing / Pause / Lower Volume
Duck level Configurable slider, default 20%, clamped 5–100% Hardcoded 10%
Fade Instant set (no ramp) Animated fade down/up over 200ms on a detached Task; new fade cancels in-flight one
Snappiness work — Hoists duck to top of beginDictationRecording + synchronous half-step so fade lines up with hotkey/start sound
Extra feature None Keep Mac Awake via IOPMAssertion (prevents display sleep while recording)

Implementation

Dimension #459 (this PR) #325
New CoreAudio file SystemAudioVolumeController.swift (196 ln) SystemVolumeController.swift (186 ln) — nearly identical concept
Other new file — SleepPreventionService.swift (68 ln)
Per-channel balance ✅ OutputVolumeSnapshot records each element, scales by factor, preserves L/R balance ✅ SystemVolumeSnapshot enum (master scalar or distinct L/R)
Trigger point Via MediaPlaybackService apply/restore suppression Threaded through ASRService.start() as preAppliedMediaAction
Restore timing On suppression revert; refuses new suppression while one active Fires the moment audio engine tears down (snaps back on hotkey release, not after transcription)

Persistence / robustness

Dimension #459 (this PR) #325
Backup/restore ✅ duckMediaInsteadOfPausing + duckMediaVolumeLevel fully backed up with backward-compat decoding ⚠️ Duck setting does not survive a backup round-trip (deliberate, called out as acceptable)
Legacy migration N/A (keeps existing Bool, adds alongside) Migrates pauseMediaDuringTranscription Bool → MediaBehaviorDuringTranscription enum, keeps Bool as a shim
Edge cases hardened Duplicate getTrackInfo re-duck; cue-volume race vs TranscriptionSoundPlayer; settable-only elements; concurrent sessions; Settings-preview scoping Skips duck if volume already ≤10%; restores on start() failure paths; tap-and-release fade handoff

Bottom line

  • Same core idea, different polish. #325 is broader (bundles keep-awake + animated fades + snappiness tuning) and was first. This PR is tighter-scoped, configurable (slider vs hardcoded 10%), fully backup-safe, and currently mergeable while #325 conflicts.
  • This PR's edge-case hardening is deeper on the ducking path specifically — duplicate-callback gating, cue-volume ownership race, concurrent-session refusal, and settable-element capture are all things #325 doesn't address.
  • Where #325 is ahead: the animated fade + hotkey-aligned responsiveness is a nicer UX, and the keep-awake feature is absent here.

akar016012 avatar Jun 29 '26 11:06 akar016012

@altic-dev Do you want me to fix anything else before you can merge this? I have been testing this last couple of days in my M1 Pro MacBook running MacOS Tahoe 26.5.1 and I really love this feature + it works very good.

akar016012 avatar Jul 02 '26 00:07 akar016012

@altic-dev What's the verdict on this? Do you want me to spend time on resolving the conflict?

akar016012 avatar Jul 11 '26 17:07 akar016012

Greptile Summary

This PR adds an optional "Lower Volume Instead of Pausing" mode under the existing Pause Media During Transcription setting. When active, a new SystemAudioVolumeController captures the default output device's per-channel volume, scales it to the user-configured fraction (5–100%, default 20%), and restores the original levels — with per-channel balance preserved — when dictation ends.

  • SystemAudioVolumeController implements a three-tier capture strategy (master scalar → stereo channel scalars → HAL virtual main volume) to maximise device compatibility, with an explicit ApplyOutcome that surfaces partial writes so MediaPlaybackService can undo them before falling back to pausing.
  • MediaPlaybackService now stores activeSuppression (.paused / .ducked) to revert exactly what it applied, with a guard preventing double-suppression when sessions overlap. The three issues identified in the previous review round (property selector mismatch, mid-session ownership race, silent restore failure) have all been addressed in the commits cited by the author.
  • TranscriptionSoundPlayer snapshots the ducking-precedence decision at start-cue time so a mid-dictation settings toggle cannot reintroduce the volume-ownership race.

Confidence Score: 5/5

Safe to merge. The ducking logic is well-isolated behind @MainActor, and all three previously identified race and restore gaps have been closed.

The implementation is carefully structured: @MainActor on MediaPlaybackService ensures activeSuppression is always read and written on the main thread, the three-tier capture strategy in SystemAudioVolumeController handles the range of macOS audio device types, the partial-duck undo path is explicit and correct, and the backup fields are Optional for backward compatibility.

No files require special attention.

Reviews (5): Last reviewed commit: "fix(media): require a complete stereo sn..." | Re-trigger Greptile

greptile-apps avatar Jul 11 '26 18:07 greptile-apps

@altic-dev What's the verdict on this? Do you want me to spend time on resolving the conflict?

I did it anyway :) please check.

akar016012 avatar Jul 11 '26 19:07 akar016012

Hey man, sorry for the delay. Working on several things now and asked Rohith to take care of PRs

Overall looks like a good feature and alignment. Did you take care of the review bots? Added greptile recently as well so more things to help and worry bout haha.

On Sat, Jul 11, 2026 at 12:46 PM Aditya Kar @.***> wrote:

akar016012 left a comment (altic-dev/FluidVoice#459) https://github.com/altic-dev/FluidVoice/pull/459#issuecomment-4948523633

@altic-dev https://github.com/altic-dev What's the verdict on this? Do you want me to spend time on resolving the conflict?

I did it anyway :) please check.

— Reply to this email directly, view it on GitHub https://github.com/altic-dev/FluidVoice/pull/459?email_source=notifications&email_token=BVSOW2RY6G25N32QAENU6MD5EKKRHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJUHA2TEMZWGMZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4948523633, or unsubscribe https://github.com/notifications/unsubscribe-auth/BVSOW2X7AZYETXGBNQZS6C35EKKRHAVCNFSNUABGKJSXA33TNF2G64TZHMYTANRRGMZDOMZRGE5US43TOVSTWNBXGYZDQNJQHA2DNILWAI . You are receiving this because you were mentioned.Message ID: @.***>

altic-dev avatar Jul 11 '26 19:07 altic-dev

Hey man, sorry for the delay. Working on several things now and asked Rohith to take care of PRs Overall looks like a good feature and alignment. Did you take care of the review bots? Added greptile recently as well so more things to help and worry bout haha. … On Sat, Jul 11, 2026 at 12:46 PM Aditya Kar @.> wrote: akar016012 left a comment (altic-dev/FluidVoice#459) <#459 (comment)> @altic-dev https://github.com/altic-dev What's the verdict on this? Do you want me to spend time on resolving the conflict? I did it anyway :) please check. — Reply to this email directly, view it on GitHub <#459?email_source=notifications&email_token=BVSOW2RY6G25N32QAENU6MD5EKKRHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJUHA2TEMZWGMZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4948523633>, or unsubscribe https://github.com/notifications/unsubscribe-auth/BVSOW2X7AZYETXGBNQZS6C35EKKRHAVCNFSNUABGKJSXA33TNF2G64TZHMYTANRRGMZDOMZRGE5US43TOVSTWNBXGYZDQNJQHA2DNILWAI . You are receiving this because you were mentioned.Message ID: @.>

No worries at all. Yes, I took care of the findings 👍

akar016012 avatar Jul 11 '26 20:07 akar016012

Few comments based on my initial checks.

PR adds 5 SwiftLint errors plus SwiftFormat failure.

Partial per-channel volume writes can leave one channel permanently ducked.

altic-dev avatar Jul 12 '26 09:07 altic-dev

Few comments based on my initial checks.

PR adds 5 SwiftLint errors plus SwiftFormat failure.

Partial per-channel volume writes can leave one channel permanently ducked.

Thanks for the review — all three points are addressed in 87daf26:

SwiftLint: All 5 violations are fixed (inclusive_language, for_where, and 3× strict_fileprivate in SystemAudioVolumeController.swift). The PR's additions had also pushed SettingsView over the type_body_length limit, so I moved the duck-settings UI into a private extension SettingsView (same pattern as the existing lowLatencyAudioCaptureToggle). SwiftLint now reports zero violations on every file this PR touches.

SwiftFormat: Fixed the one error the PR introduced (0.05 ... 1.0 → 0.05...1.0, per --ranges nospace). The remaining SwiftFormat failures on these files (wrapIfStatementBodies in SettingsStore.swift, docComments in MediaPlaybackService.swift) exist identically on main, so I left them untouched to keep this PR's diff focused — happy to clean those up in a separate PR if you'd like.

Partial per-channel writes: Good catch — apply() returned true if any channel wrote, so a restore that failed on one channel reported success and left it ducked with no log. It now returns applied/partial/failed:

  • A restore that isn't fully applied falls back to setting the HAL virtual main volume to the original level (approximate, but no channel gets stuck), with a warning logged.
  • A partial duck is undone before falling back to pausing media, so a mixed left/right state can't persist through a session.

Verified locally: SwiftLint clean on all changed files, SwiftFormat back to main's baseline, and the app builds.

akar016012 avatar Jul 12 '26 12:07 akar016012

I did not forget this! Just fixing a lot of bugs before pushing in new features. sorry for the delay @akar016012 - hope you understand :)

altic-dev avatar Jul 21 '26 00:07 altic-dev