A gentleman asked this question 9 months ago. It was never answered correctly and the thread was closed. He was told to do this:
On Windows, use pycaw:
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
volume.GetMasterVolumeLevelScalar()
And with this, the thread was closed but this is NOT the answer, this scalar level is NOT the 0-100level of master volume displayed on a PC monitor in the systray. I have pycaw and comtypes installed and am on the current python 3.11.1. I have entered all the above commands into my python. Please may I know what command to use to get the exact output of my master volume. If my pc volume is 50 I want an output of 50. With the above instructions, at pc volume level 100, the scalar level output is 1. Thats worthless to me. Please help.
I tried using the command
volume.GetMasterVolume()
hoping to get the master level return. instead I got an error:
>>> volume.GetMasterVolume()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'POINTER(IAudioEndpointVolume)' object has no attribute 'GetMasterVolume'. Did you mean: 'GetMasterVolumeLevel'?
So I tried volume.GetMasterVolumeLevel() and at 100 master volume this returned 0.0 again worthless.
Why does volume.GetMasterVolume() not work? What do I have to do to make it work?