如何在Python中访问DirectSound设备信息?
我在StackOverflow上找到了一些关于如何在.NET中列举音频输出设备信息的内容,但我不知道怎么把这些信息用在Python里。你可能能看出来,我在Windows API编程方面几乎没有经验。
我能通过WMI获取一些基本信息,但我需要更多的信息,看起来下面这段C#代码可能正是我需要的,但我就是不知道怎么在Python中访问DirectSound对象。我已经用ctypes搞明白了一些基本的东西,但我不知道该加载哪个DirectX的.dll文件,也不知道怎么加载……
DevicesCollection devColl = new DevicesCollection();
foreach (DeviceInformation devInfo in devColl)
{
Device dev = new Device(devInfo.DriverGuid);
//use dev.Caps, devInfo to access a fair bit of info about the sound device
}
有没有什么建议?
1 个回答
1
如果你想用一种简单的方法访问 .NET 库,可以看看 “Python for .NET”。
不过,使用 IronPython 可能会更容易访问 DirectSound 设备,因为它通过 clr
库与 .NET 进行了连接。
以下是来自 IronPython 食谱的一些小贴士:
import clr
clr.AddReference('Microsoft.DirectX.AudioVideoPlayback')
from Microsoft.DirectX import AudioVideoPlayback
mp3 = AudioVideoPlayback.Audio("C:\\myreallyfunky.mp3")
mp3.Play()
关于如何在 IronPython 中使用 Managed DirectX 的更详细教程,可以在 http://www.neotitans.com/resources/dot-net/mdx-ironpython-1.html 找到。