枚举NAudio中的录音设备 [英] Enumerate Recording Devices in NAudio

查看:418
本文介绍了枚举NAudio中的录音设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用NAudio获取计算机上所有录音设备的列表?要记录时,必须给它提供要使用的设备的索引,但是无法知道它是什么设备.我希望能够从麦克风,立体声混音等中进行选择.

How can you get a list of all the recording devices on a computer using NAudio? When you want to record, you have to give it the index of the device you want to use, but there's no way of knowing what device that is. I'd like to be able to select from Mic, Stereo Mix, etc.

推荐答案

对于WaveIn,您可以使用静态WaveIn.GetCapabilities方法.这将为您提供一个设备名称,但是有一个令人讨厌的限制,即最多31个字符.我仍在寻找全名的方法(请参阅我的问题这里).

For WaveIn, you can use the static WaveIn.GetCapabilities method. This will give you a device name, but with the annoying limitation that it is a maximum of 31 characters. I am still looking for the way to get the full name (see my question here).

int waveInDevices = WaveIn.DeviceCount;
for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++)
{
    WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
    Console.WriteLine("Device {0}: {1}, {2} channels", waveInDevice, deviceInfo.ProductName, deviceInfo.Channels);
}

对于WASAPI(Vista及更高版本),可以使用MMDeviceEnumerator:

For WASAPI (Vista and above), you can use the MMDeviceEnumerator:

MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All))
{
    Console.WriteLine("{0}, {1}", device.FriendlyName, device.State);
}

我倾向于推荐WaveIn,因为它得到了更广泛的支持,并且在记录采样率方面具有更大的灵活性.

I tend to recommend WaveIn, as it is more widely supported, and allows more flexibility over recording sample rates.

这篇关于枚举NAudio中的录音设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆