c# - C# 中的捕获设备列表(例如麦克风、立体声混音...)

标签 c# wpf audio device

我如何获得可用声音设备的列表?我的意思是该图片中的内容。

enter image description here

我想要它在组合框中。我的意思是:

  • 麦克风
  • 立体声混音
  • 在线
  • ..等等..

但一定是因为系统根据语言本地化系统更改了设备的名称,而这正是我所需要的。

例如,在我的语言中,麦克风称为 Mikrofon 和 Stereo Mix = Směšovač stereo

enter image description here

我需要获取这些设备名称,仅此而已

可以制作示例代码吗?

最佳答案

这是做我需要的..

    [DllImport("winmm.dll", SetLastError = true)]
    static extern uint waveInGetNumDevs();

    [DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern uint waveInGetDevCaps(uint hwo, ref WAVEOUTCAPS pwoc, uint cbwoc);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct WAVEOUTCAPS
    {
        public ushort wMid;
        public ushort wPid;
        public uint vDriverVersion;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
        public string szPname;
        public uint dwFormats;
        public ushort wChannels;
        public ushort wReserved1;
        public uint dwSupport;
    }

    public static string[] GetSoundDevices()
    {
        uint devices = waveInGetNumDevs();
        string[] result = new string[devices];
        WAVEOUTCAPS caps = new WAVEOUTCAPS();
        using (StreamWriter sw = new StreamWriter("appdata/audio/name"))
        {
            for (uint i = 0; i < devices; i++)
            {
                waveInGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
                result[i] = caps.szPname;
                sw.WriteLine(caps.szPname);
            }
            return result;
        }
    }

.. 但是每一行都被缩短了,我无法全部写完。

enter image description here

如何修改列出整体名称的代码?

谢谢!

关于c# - C# 中的捕获设备列表(例如麦克风、立体声混音...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29936641/

相关文章:

c++ - 从字节数组中获取音频样本

c# - MySql 使用.Net/Connector 批处理存储过程调用?

c# - 如何在 ASP.NET 中处理微前端?

C# 工作流引擎 - 对于最终用户

wpf - 从代码访问 WPF 控件验证规则

c# - 如何在 WPF 中进行随机化

c# - .net c#一次加载XML文件的方法

c# - Windows Mobile 上的 vector 图形

ffmpeg可以解码G711音频吗

java - MediaPlayer无法在Android中播放音频