You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在.NET Core 7控制台应用中使用NAudio列出音频输出设备?

Answer to Your Questions

1. Listing Audio Output Devices in a Windows-only .NET Core Console App

Yes, you can list audio output devices in a .NET Core 7 console app without relying on NAudio.WinForms. The core NAudio package includes WaveOutEvent—a WinForms-independent alternative to WaveOut—and WasapiOut (for modern Windows audio systems) that work in console environments.

Using WaveOutEvent (Legacy Windows Audio)

using NAudio.Wave;

// Enumerate WaveOut-compatible audio devices
for (int i = 0; i < WaveOutEvent.DeviceCount; i++)
{
    var deviceInfo = WaveOutEvent.GetCapabilities(i);
    Console.WriteLine($"Device {i}: {deviceInfo.ProductName}");
}

Using WasapiOut (Modern Windows Audio)

For better compatibility with newer Windows versions and audio features, use WASAPI:

using NAudio.Wave;

// Enumerate WASAPI audio devices
var deviceNames = WasapiOut.GetDeviceNames();
for (int i = 0; i < deviceNames.Count; i++)
{
    Console.WriteLine($"WASAPI Device {i}: {deviceNames[i]}");
}

2. NAudio on Linux: Usage and Required Libraries

NAudio does support Linux, but it requires a platform-specific package and system-level dependencies:

  • NuGet Package: Instead of NAudio.Alsa, install the NAudio.Linux package via NuGet—this provides ALSA (Advanced Linux Sound Architecture) bindings for NAudio.
  • System Dependencies: On Debian/Ubuntu-based systems, install the ALSA development library first with:
    sudo apt-get install libasound2-dev
    

Enumerating Linux Audio Devices with NAudio.Linux

using NAudio.Linux;

// Enumerate ALSA audio output devices
var alsaDevices = AlsaOut.GetDeviceNames();
foreach (var device in alsaDevices)
{
    Console.WriteLine($"ALSA Device: {device}");
}

内容的提问来源于stack exchange,提问作者AngryHacker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 11:33:28