问题描述
我希望能够控制在Python主音量(未为应用程序,但是对于当前活跃说话者)。这似乎是一个棘手的话题;我试图在C#中这样做,但我甚至不能得到它在那里工作。有没有办法做到这一点? (Windows 7的64位)
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)
请注意,这个问题一直没有以前因为我的问题是关于具体的的Python 回答。此外,该项目VonC是指有简化版,在Windows 7上的工作。
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
.
如果您正在使用从项目,这应该是pretty容易在Python访问。
If you're using the Win32 COM wrappers from the pywin32
project, this should be pretty easy to access in Python.
由于文档解释,有多种方法可以得到一个 ISimpleAudioVolume
的参考。你需要得到一个跨进程会议上, sndvol.exe
的方式做。查看 WASAPI 一个顶层文档>了解详情。
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.
伪code会是这个样子:
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)
这篇关于的Python:更改Windows 7的主音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!