Python Change Master/Application Volume

audio, python, volume, windows

Solution

I'd hope after 5 years this is no longer a problem for you, but I've just had to do the same thing. It's possible using the PyCaw library.

Simple proof of concept, based on PyCaw's examples

from __future__ import print_function
from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume


def main():
    sessions = AudioUtilities.GetAllSessions()
    for session in sessions:
        volume = session._ctl.QueryInterface(ISimpleAudioVolume)
        if session.Process and session.Process.name() == "vlc.exe":
            print("volume.GetMasterVolume(): %s" % volume.GetMasterVolume())
            volume.SetMasterVolume(0.6, None)


if __name__ == "__main__":
    main()

Problem

How do I change it? I'm looking for something like: ``` SetMasterVolume(0.5) SetAppVolume('FooBar',0.5) ``` I tried using ctypes.windll.winmm, but I can't find much documentation on how to use it. Thanks in advance.

Original source