I want to be able to control the master volume (not for an application, but for the current active speaker) in Python. This seems to be a tricky topic; I tried doing it in C# but I couldn't even get it to work there. Is there a way to accomplish this? (Windows 7 x64)
Please note that this question has not been answered before since my question is specifically about Python. Also, the project VonC is referring to there does't work on Windows 7.
The easy way to do this is through ISimpleAudioVolume
.
If you're using the Win32 COM wrappers from the pywin32
project, this should be pretty easy to access in Python.
As the documentation explains, there are multiple ways to get a reference to an ISimpleAudioVolume
. You need to get a cross-process session, the way sndvol.exe
does. See the top-level documentation on WASAPI for details.
The pseudocode will look something like this:
mmde = CoCreateInstance(CLSID_MMDeviceEnumerator, None,
CLSCTX_ALL, IID_IMMDeviceEnumerator)
mmd = mmde.GetDefaultAudioEndpoint(eRender, eMultimedia)
mgr = mmd.Activate(IID_IAudioSessionManager)
sav = mgr.GetSimpleAudioVolume(None, True)
sav.SetMasterVolume(0.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With