How to simply get the master volume of Windows in Python?

Question:

I’m looking for a simple way to get windows’ master volume in Python. Preferably a function that simply returns the master volume.

Something like this:

GetMasterVolume()
#0.3
Asked By: Leo

||

Answers:

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()
Answered By: thariqfahry
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.