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
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()
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
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()