Skip to content

Add AudioDevice.volume_percent property (percentage based master volume)#109

Merged
AndreMiras merged 1 commit into
AndreMiras:developfrom
ahmetberber:feature/volume-percent
Jul 19, 2026
Merged

Add AudioDevice.volume_percent property (percentage based master volume)#109
AndreMiras merged 1 commit into
AndreMiras:developfrom
ahmetberber:feature/volume-percent

Conversation

@ahmetberber

Copy link
Copy Markdown
Contributor

Closes #13, where percentage based volume control was requested and a PR was invited — this adds it as a small convenience on AudioDevice.

What

  • AudioDevice.volume_percent property (getter/setter) exposing the master volume on the 0–100 scale the Windows volume mixer uses, wrapping GetMasterVolumeLevelScalar() / SetMasterVolumeLevelScalar(). The setter clamps out-of-range values.
  • examples/master_volume_percent_example.py — runnable example (reads, sets to 50 %, restores).
  • Unit test covering the scalar mapping and clamping (mock based, no audio device needed).
  • README usage snippet + CHANGELOG entry.

Why

The dB based SetMasterVolumeLevel() vs. scalar confusion is a recurring stumbling block for pycaw users (see #13); a discoverable volume_percent next to EndpointVolume makes the common case obvious without changing any existing API.

Verification

Tested on Windows 11, Python 3.12.10, real hardware (TOPPING USB DAC):

Device found: Speakers (TOPPING USB DAC)
volume_percent: 60%
setting volume to 50%
volume_percent: 50%
restoring original volume
volume_percent: 60%

tests/test_core.py — 5 passed (including the new test_volume_percent). black / isort / flake8 clean on the touched files.

🤖 Generated with Claude Code

Convenience getter/setter exposing the master volume on the 0-100 scale
the Windows volume mixer uses, wrapping Get/SetMasterVolumeLevelScalar so
users don't reach for the decibel based SetMasterVolumeLevel by mistake.
The setter clamps values to the valid range.

Includes a runnable example, a unit test, and README/CHANGELOG updates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@AndreMiras AndreMiras left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM

@AndreMiras

Copy link
Copy Markdown
Owner

Thanks for the contribution

@AndreMiras
AndreMiras merged commit 4cd4a46 into AndreMiras:develop Jul 19, 2026
8 checks passed
ahmetberber added a commit to ahmetberber/windows-apple-music-remote that referenced this pull request Jul 19, 2026
…llback

volume_percent (merged AndreMiras/pycaw#109) exposes the 0-100 master volume
directly; use it when the installed pycaw provides it and fall back to the
existing GetMasterVolumeLevelScalar()*100 path on older releases so the
autostart server never crashes on an outdated pycaw. No behaviour change today
(current PyPI pycaw 20251023 lacks the property); picks up the property
automatically once a pycaw release ships it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Setting master volume level with percentages

2 participants