Python: Change Windows 7 master volume

后端 未结 1 744
南笙
南笙 2021-01-06 01:50

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

1条回答
  •  被撕碎了的回忆
    2021-01-06 02:13

    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)
    

    0 讨论(0)
提交回复
热议问题