Skip to content

Release audio session after alarm so other audio is no longer ducked - #806

Open
bjorkert wants to merge 5 commits into
devfrom
fix/alarm-audio-session-release
Open

bjorkert wants to merge 5 commits into
devfrom
fix/alarm-audio-session-release

Conversation

@bjorkert

@bjorkert bjorkert commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

The alarm releases the audio session with notifyOthersOnDeactivation when it is stopped or snoozed and when its last sound finishes, so audio from other apps that was ducked during the alarm returns to full volume right away, also when the app is kept alive in the background by a Bluetooth heartbeat. With Silent Tune holding the session it stays active and goes back to the mixable category Silent Tune uses. Spoken BG and the Speak BG quick action share one speech output that ducks other audio and uses the same release path, so neither an alarm nor speech deactivates the session while the other is still playing; when an alarm ends during speech, the release happens once the speech finishes.

Related to #782.

@marionbarker

marionbarker commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

I asked Claude to review and got an approval with some comments for you to review. Seems like the interaction with Speak BG may be one thing to consider.

Issues

  1. The reverse race isn’t guarded. If an alarm stops or finishes while spoken BG is still talking, releaseAudioSession() tries to deactivate under the speech. That usually fails with an isBusy error, which gets logged, and the release then happens at speech didFinish. It’s harmless in practice, but adding MainViewController.shared?.speechSynthesizer.isSpeaking != true to the guard would make the release logic symmetric.
  2. The Silent Tune branch never deactivates, so other apps are never notified. Changing the category on an active session should stop ducking. But if the alarm activated with [] (Silent Tune or foreground), it interrupted other audio rather than ducking it. Interrupted apps such as a podcast or music player only auto-resume when they receive an interruption-ended notice. A category change doesn’t send one, so for Silent Tune users the other app’s audio will likely stay paused until they press play. That may be acceptable, since you can’t deactivate without losing Silent Tune’s background hold, but the PR description should say so. It’s also the main thing to check on a device.

Minor:
The Speak BG quick action in AppSceneDelegate uses its own synthesizer with no delegate, so it still never releases the session. That isn’t new with this PR, but it’s in the same area if you want to fix it.

marionbarker
marionbarker previously approved these changes Nov 5, 2026

@marionbarker marionbarker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successful build. Please read the Claude comments as well.

@cjmlcr

cjmlcr commented Nov 12, 2026

Copy link
Copy Markdown

I tested the branch for a few days and the two problems that I reported have been resolved. The podcast volume now goes back to where it was between alarm repeats and the Omnipod Dash heartbeat warning no longer shows up.

@bjorkert

Copy link
Copy Markdown
Member Author

Thanks Marion. I tested both points on a phone with a podcast playing.

The first one is real and worse than a logged error. When an alarm finished while spoken BG was still talking, the session was deactivated under the speech, the speech was cut off mid-sentence, and the synthesizer stayed in speaking state, so every later spoken BG was queued behind it and never heard until the app was restarted. With your isSpeaking check the speech continues to the end, the release happens in didFinish, the podcast comes back and the next spoken BG works. Added in 650194d.

On Silent Tune, it turned out not to happen. With Silent Tune holding the session in the background, the alarm never interrupted the podcast, it kept playing through the alarm and afterwards, so there is nothing that needs a resume notice. In the foreground without Silent Tune the alarm does interrupt it, and the podcast resumed on its own right after the release.

The Speak BG quick action I'll take in a separate PR.

@bjorkert

Copy link
Copy Markdown
Member Author

The Speak BG quick action turned out to be small enough to fix here. On a phone it paused a playing podcast, which stayed paused afterwards. It now speaks through the same speech output as spoken BG (b1f5a45), so the podcast is only ducked and keeps playing, both when the app is running and when the quick action launches it. The alarm during spoken BG case still behaves as above with this change.

…n-release

# Conflicts:
#	LoopFollow/ViewControllers/MainViewController.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Volume attenuated after LoopFollow alarm

3 participants