关于.net:如何使用 C# 和 NAudio 从 USB 麦克风获取音频输入 | 珊瑚贝

How to get audio input from usb microphone with C# and NAudio


我正在尝试使用 NAudio 从 USB 设备获取音频输入。
我正在使用 WavIn 类,但像这样:

1
2
NAudio.Wave.WaveIn input = new NAudio.Wave.WaveIn();
input.DeviceNumber=0;

但我不知道如何获取我的 micro 设备号。
我知道这种方法:

1
WaveIn.GetCapabilities();

但是没有my micro,因为它不被识别为麦克风。
我也可以像 thi 一样获得我的 USB 设备:

1
2
3
4
5
6
7
8
    System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(@”Select * From Win32_USBHub”);
    var devices = searcher.Get();
    foreach(var d in devices)
    {
        var deviceId = (string)d.GetPropertyValue(“DeviceID”);
        var pnpDeviceID = (string)d.GetPropertyValue(“PNPDeviceID”);
        var description = (string)d.GetPropertyValue(“Description”);
    }

但我不能将它传递给 WaveIn。

如何使用 NAudio 获取 USB 设备输入?


如果你想用 WaveIn 记录它,你需要它出现在可用 WaveIn 设备列表中:

1
2
3
4
5
for (int n = 0; n < WaveIn.DeviceCount; n++)
{
    var caps = WaveIn.GetCapabilities(n);
    Console.WriteLine($“{n}: {caps.ProductName} {caps.Channels}”);
}

或者,它可以通过 WasapiCapture:

访问

1
2
3
4
5
6
var deviceEnum = new MMDeviceEnumerator();

foreach (var device in deviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active))
{
    Console.WriteLine($“{device.ID}: {device.DeviceFriendlyName} / {device.FriendlyName}”);
}


来源:https://www.codenong.com/46182408/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9006.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?