【问题标题】:How to access DirectSound device info from Python?如何从 Python 访问 DirectSound 设备信息?
【发布时间】:2011-05-26 00:16:44
【问题描述】:

我在 SO 上找到了this 有关如何使用 .NET 枚举声音设备信息的信息,但我真的不知道如何在 Python 中使用这些信息。正如您可能知道的那样,我对 Windows API 编程的经验几乎为零。

我可以弄清楚如何通过 WMI 获取基本信息,但我需要更多信息,看起来可能下面的 C# 代码 sn-p 是我需要的,但我只是不知道如何访问 DirectSound 对象来自 Python。我已经用 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
    }

任何指针?

【问题讨论】:

  • 您使用的是哪种 Python? IronPython 对吗?
  • 我目前正在使用 CPython,但如果需要,我可以毫无问题地切换到 IronPython。

标签: python directx ctypes


【解决方案1】:

对于“穷人”的 .NET 库访问权限,请查看 "Python for .NET"

但是,使用 IronPython 访问 DirectSound 设备可能更容易,因为它通过 clr 库绑定了 .NET。

来自IronPython cookbook的提示:

Playing an MP3 song with DirectX:

import clr
clr.AddReference('Microsoft.DirectX.AudioVideoPlayback')
from Microsoft.DirectX import AudioVideoPlayback
mp3 = AudioVideoPlayback.Audio("C:\\myreallyfunky.mp3")
mp3.Play()

在 IronPython 中使用托管 DirectX 的更全面的教程可以从http://www.neotitans.com/resources/dot-net/mdx-ironpython-1.html 找到

【讨论】:

    猜你喜欢
    • 2013-02-28
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多