Python: Change Windows 7 Master Volume
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
Solution 1:
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)
Post a Comment for "Python: Change Windows 7 Master Volume"