Skip to content

Say the volume as soon as it changes - #451

Open
nibarAhmed wants to merge 5 commits into
trypsynth:masterfrom
nibarAhmed:speak-volume-right-away
Open

nibarAhmed wants to merge 5 commits into
trypsynth:masterfrom
nibarAhmed:speak-volume-right-away

Conversation

@nibarAhmed

@nibarAhmed nibarAhmed commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

TalkBack waited until the volume keys had been still for 2 seconds before saying the volume, and it didn't say the media volume while media played. That made the volume keys feel slow. Connecting headphones could also make Backtalk read out the level they brought with them.

Now Backtalk says the new volume as soon as it changes:

  • A press says the new level right away and interrupts speech, except during continuous reading. A held key says the first level, then the level you end at when you let go. Quick changes to the same stream say only the percentage.
  • The media volume is said while media plays too, and so are mute and unmute, which follow Speak volume changes like any other level.
  • Changes that aren't yours stay quiet: Backtalk's own changes, the media, call, notification and accessibility levels headphones bring when they connect or disconnect, and headphones repeating their level. A volume key is always said. Where each of these plays is looked up at each change, because Android can report the headphones' level before it reports that they connected. The ringer keeps one level on every output, so it isn't checked.
  • "Backtalk off" is now said at the accessibility volume on Samsung phones too, and on whichever output is in use.

The volume code moved out of Google's VolumeMonitor into VolumeAnnouncer, so Google's Java files only get small hooks. differences.md describes the new behaviour.

Fixes #295. The issue's optional sound cues instead of speech are left out. Making a new volume on Bluetooth headphones as loud as the speech after it is in #460, which builds on this one.

Testing

  • Unit tests for the announcer, held keys, outputs and "Backtalk off" (VolumeMonitorTest, FinalAnnouncementVolumeTest).
  • Tested on a Galaxy S26 Ultra running Android 17 with the Vocalizer TTS engine, using Galaxy Buds4 Pro and Razer BlackShark V2 Pro headphones. This included connecting and disconnecting while the speaker and the headphones were at different media and call levels, and switching the buds between the phone and a PC.
  • Another user tested it as well.

Created with Claude Opus 5.5 in Claude Code, through T3 Code.

🤖 Generated with Claude Code

@nibarAhmed
nibarAhmed force-pushed the speak-volume-right-away branch from 5ca1252 to 8979dc2 Compare November 8, 2026 23:19
@trypsynth

Copy link
Copy Markdown
Owner

Thanks, this is laid out well: the volume code is in files of its own, and Google's files only get small hooks. It's still three changes in one, though, and I'd like to take them one at a time:

  1. Saying the volume at once, plus the media volume while media plays. That's Enhancement: Reduce delay of volume announcement for physical volume keys #295, and it's the part I want first.
  2. Staying quiet for levels that headphones bring when they connect or disconnect, and for headphones repeating their level.
  3. On Bluetooth, nudging the accessibility volume down and back up, and playing silence first when the nudge isn't allowed.

I'm least sure about 3. It briefly changes the user's volume on every announcement, and I'd want it tried on more than one phone and pair of headphones before it goes in. Could you split this so that 1 is here and 2 and 3 come after it?

@nibarAhmed

nibarAhmed commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Claude Opus 5.5 responding on behalf of nibarAhmed

I can split out 3, but I'd like to keep 1 and 2 together. On its own, 1 makes connecting headphones worse than it is now.

When headphones connect, Android switches the media level to theirs and sends a volume change for it. Today that change is said 2 seconds later, and not at all while music plays, because shouldAnnounceStream skips STREAM_MUSIC while isMusicActive(). Part 1 removes the delay and that check, so with 1 alone, connecting or disconnecting headphones would announce their level right away, even in the middle of music. Since every push to master goes out as the dev build, people would hear that until 2 landed. Part 2 is what stops it: isIgnoredChange in VolumeAnnouncer, about 40 lines plus tests.

3, the Bluetooth nudge, can come apart into a PR of its own. Without it nothing breaks; announcements on Bluetooth can just be a little louder or quieter than the speech after them, as before. I can put it behind a setting that's off by default, so it can be tried on more phones and headphones before anyone gets it. The "Backtalk off" fix in FinalAnnouncementVolume would stay here.

Since opening this, another user has tested the change as well.

Does that work for you? If so, this PR keeps 1 and 2, and I'll open 3 after it.

@trypsynth

Copy link
Copy Markdown
Owner

That makes sense. You're right that 1 alone would announce the headphones' level mid-song, so keep 1 and 2 together. Please move 3 into its own PR, off by default as you suggest, and take with it whatever in QuietBeforeAnnouncement only the nudge uses, so that this PR keeps just what's needed to recognise Backtalk's own changes. I'll review it again after that.

nibarAhmed and others added 3 commits November 14, 2026 12:26
TalkBack waited until the volume keys had been still for 2 seconds, and
didn't say the media volume while media played. Backtalk now says each
new level right away, says a held key's level when it's released, keeps
changes that aren't the user's quiet, such as the level headphones bring
when they connect, and nudges the accessibility volume on Bluetooth so
the announcement plays at the new level. "Backtalk off" is said at the
accessibility volume on Samsung phones and on each output.

Fixes trypsynth#295

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nibarAhmed

Copy link
Copy Markdown
Contributor Author

Note

🤖 Claude Opus 5.5 responding on behalf of nibarAhmed

Done: the Bluetooth nudge is now in #460, behind Verbosity > Steady volume announcements on Bluetooth, off by default.

  • All of QuietBeforeAnnouncement went with it. Its isOwnChange only recognises the nudge's own two accessibility volume steps, so without the nudge this PR has no changes of its own to recognise and needs none of that file. LowLatencyAudio is back to master here too.
  • What stays: saying the volume at once and media while it plays, keeping the levels a newly connected output brings quiet, and the "Backtalk off" fix (FinalAnnouncementVolume).
  • This branch is rebased onto master (3f5d2d5), down to three commits. The last one, "Leave the Bluetooth nudge to a change of its own", is the removal. Volume tests and lint pass.

#460 builds on this branch, so it should merge after this one; I'll rebase it onto master once this is in.

@trypsynth

Copy link
Copy Markdown
Owner

Thanks for splitting it. This reads well, and the shape is right. A few things before it goes in:

  1. A press at the limit says nothing. Once control is acquired, the existing volume == prevVolume return in internalOnVolumeChanged comes before volumeAnnouncer.onVolumeChanged. Pressing volume up again at 100% within the control window is silent, where before the level was said on release. Please say the level for a key press even when it didn't change.
  2. Mute during playback. Removing the shouldAnnounceStream check from internalOnStreamMuted means "Music muted" is now spoken while media plays, through the old path. It ignores Speak volume changes and the new output checks, and can double up with "set to 0 percent". Could mute go through the announcer too, or keep the old check?
  3. Listener before ignoring. isIgnoredChange runs before notifyVolumeChangedListener, so a selector or voice command change made just after the output changed is dropped as a new-output change, and its one-shot listener stays registered for the next key press. Please notify the listener first, or don't ignore a change a listener is waiting for.
  4. A question: STREAM_ACCESSIBILITY isn't in PER_OUTPUT_STREAMS. If headphones and the speaker have different accessibility levels, does connecting them announce it? The gesture's listener only exists for a moment.

Smaller, if you have time: outputsFor repeats the lookup that FinalAnnouncementVolume.outputDeviceType and AudioDeviceRouter already do, so one shared helper would be better. And outputOf() makes an audio service call on the main thread for every repeat while a key is held.

nibarAhmed and others added 2 commits November 15, 2026 03:17
@nibarAhmed

nibarAhmed commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Claude Opus 5.5 responding on behalf of nibarAhmed

Points 2 and 3, question 4 and both smaller items are fixed in 193a34b. Point 1 is left as it is, because master doesn't say a press at the limit either. Latest master is merged in (d0ec992).

1. A press at the limit (not changed). Android doesn't send a volume broadcast for a press that can't change the level. That means the volume == prevVolume branch never sees a press at the limit, on master or here.

  • On an Android 17 emulator, dumpsys audio logs sending VOLUME_CHANGED for 15→14 and 14→15, and nothing for a further press at 15.
  • What master says "on release" is its 2-second wait after the last real change. Each change restarts that timer (releaseControlDelayed), and when it runs out master says the level once. The press at the limit plays no part in it.
  • On a Galaxy S26 Ultra running master, a press at the limit never said the level more than once.
  • With this PR, the level is said right away when the last real change happens, so nothing goes unsaid.

I tried saying the level again when a key is released at the limit soon after a change. It needed a guess about which stream the key would change, it stayed silent after a pause anyway, and it didn't fire reliably on the emulator, so I dropped it. If you want a press at the limit to give feedback, that would be a new feature, best done separately.

2. Mute. internalOnStreamMuted now calls VolumeAnnouncer.onStreamMuted.

  • Speak volume changes, the call check, held keys and focused sliders apply to mute the same way they do to levels.
  • Mute is spoken in the volume utterance group, so it replaces the level said for the same press instead of doubling up.

3. Listener first. notifyVolumeChangedListener runs before isIgnoredChange, and a change a listener is waiting for is never ignored. Test: aListenerHearsAChangeThatComesWithANewOutput.

4. Accessibility per output. Yes. Each output keeps its own accessibility level, so connecting headphones would have said theirs.

  • STREAM_ACCESSIBILITY is now in PER_OUTPUT_STREAMS.
  • Android won't build attributes from that stream, so its output is looked up with USAGE_ASSISTANCE_ACCESSIBILITY.
  • Test: theAccessibilityLevelHeadphonesBringIsNotSaid. This is covered by the unit test. This is nibar with an edit, Tested on the s26 ultra and works as it should from my testing when using the galaxy buds 4 pro. This doesn't really happen in practise during daily use. But it's a good catch and I think the change should be kept as it's a cheep check.
    Smaller items.
  • AudioManager.outputsFor in audio/AudioOutputs.kt is now the one lookup that AudioDeviceRouter, FinalAnnouncementVolume and VolumeAnnouncer use.
  • The repeats of a held key reuse the last output instead of asking the audio service. A single press still looks it up once.
  • The speakWithCompletion path in VolumeMonitor is gone, since nothing calls it any more.

./gradlew testPhoneDebugUnitTest :lintPhoneDebug :lintWearDebug passes on the merged head.

@hamadatrichine

Copy link
Copy Markdown

Tested and works on the galaxy S24 Ultra.
Same goes for #460

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.

Enhancement: Reduce delay of volume announcement for physical volume keys

3 participants