pythonaudio

How can I get the volume of the current audio output device in Python on Windows?


I'm looking for a simple way to get the volume of the current audio output device in Python, preferably in percent or as a decimal from 0-1


Solution

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