winforms 如何列出所有已启用并存在的音频设备,用于录制PC的输出音频?

bwitn5fc  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(136)

我想记录与ffmpeg后,整个桌面,包括音频。我想让它自动为我找到录音设备。
我正在使用MMDeviceEnumerator。
我尝试的所有其他方法返回空列表返回0音频设备。我用naudio和ffmpeg试过了

public Form1()
        {
            InitializeComponent();

            InitializeRecordingIndicator();

            MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
            foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All))
            {
                StreamWriter w = new StreamWriter(@"d:\audiodev.txt", true);
                cmbAudioDevices.Items.Add(device.FriendlyName);
                w.WriteLine(device.FriendlyName + " " + device.State);
                w.Close();
            }
        }

这是我系统中所有音频设备的列表。但它们都不存在或被禁用。而且我的电脑上有音频,我可以听到游戏视频任何东西。
那么我会从这个列表中选择什么作为录制pc输出音频的音频设备呢?或者也许我需要找另一种方法来找到正确的音频设备?

Front Green In (Realtek(R) Audio) NotPresent
Rear (Realtek(R) Audio) NotPresent
Center (Realtek(R) Audio) NotPresent
Microphone (Realtek(R) Audio) NotPresent
Rear Grey In (Realtek(R) Audio) NotPresent
Side (Realtek(R) Audio) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Rear Pink In (Realtek(R) Audio) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Front (Realtek(R) Audio) NotPresent
Rear Orange In (Realtek(R) Audio) NotPresent
Line In (Realtek(R) Audio) NotPresent
Front Pink In (Realtek(R) Audio) NotPresent
Line In (Realtek(R) Audio) Unplugged
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Microphone (Realtek(R) Audio) Unplugged
Subwoofer (Realtek(R) Audio) NotPresent
Rear Black In (Realtek(R) Audio) NotPresent
Stereo Mix (Realtek(R) Audio) Disabled
Rear Green In (Realtek(R) Audio) NotPresent
Microphone (Realtek(R) Audio) NotPresent
Rear Blue In (Realtek(R) Audio) NotPresent
Front Green In (Realtek(R) Audio) NotPresent
Rear (Realtek(R) Audio) NotPresent
Center (Realtek(R) Audio) NotPresent
Microphone (Realtek(R) Audio) NotPresent
Rear Grey In (Realtek(R) Audio) NotPresent
Side (Realtek(R) Audio) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Rear Pink In (Realtek(R) Audio) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Front (Realtek(R) Audio) NotPresent
Rear Orange In (Realtek(R) Audio) NotPresent
Line In (Realtek(R) Audio) NotPresent
Front Pink In (Realtek(R) Audio) NotPresent
Line In (Realtek(R) Audio) Unplugged
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Microphone (Realtek(R) Audio) Unplugged
Subwoofer (Realtek(R) Audio) NotPresent
Rear Black In (Realtek(R) Audio) NotPresent
Stereo Mix (Realtek(R) Audio) Disabled
Rear Green In (Realtek(R) Audio) NotPresent
Microphone (Realtek(R) Audio) NotPresent
Rear Blue In (Realtek(R) Audio) NotPresent
Front Green In (Realtek(R) Audio) NotPresent
Rear (Realtek(R) Audio) NotPresent
Center (Realtek(R) Audio) NotPresent
Microphone (Realtek(R) Audio) NotPresent
Rear Grey In (Realtek(R) Audio) NotPresent
Side (Realtek(R) Audio) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Rear Pink In (Realtek(R) Audio) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (NVIDIA High Definition Audio) NotPresent
Front (Realtek(R) Audio) NotPresent
Rear Orange In (Realtek(R) Audio) NotPresent
Line In (Realtek(R) Audio) NotPresent
Front Pink In (Realtek(R) Audio) NotPresent
Line In (Realtek(R) Audio) Unplugged
Internal AUX Jack (High Definition Audio Device) NotPresent
Internal AUX Jack (High Definition Audio Device) NotPresent
Microphone (Realtek(R) Audio) Unplugged
Subwoofer (Realtek(R) Audio) NotPresent
Rear Black In (Realtek(R) Audio) NotPresent
Stereo Mix (Realtek(R) Audio) Disabled
Rear Green In (Realtek(R) Audio) NotPresent
Microphone (Realtek(R) Audio) NotPresent
Rear Blue In (Realtek(R) Audio) NotPresent

这是我如何尝试与naudio,但它没有工作,它没有找到任何东西。:

using NAudio.Wave;
...

// Enumerate and list audio input devices
var devices = WaveInEvent.DeviceCount;
for (int deviceId = 0; deviceId < devices; deviceId++)
{
    var deviceInfo = WaveInEvent.GetCapabilities(deviceId);
    Console.WriteLine($"Device ID: {deviceId}, Name: {deviceInfo.ProductName}");
}

在此之前,我尝试了ffmpeg,但它也没有返回任何东西:

public static class FFmpegHelper
    {
        public static string[] GetAudioCaptureDevices()
        {
            string ffmpegPath = @"C:\path\to\ffmpeg.exe";
            Process process = new Process();
            process.StartInfo.FileName = ffmpegPath;
            process.StartInfo.Arguments = "-list_devices true -f dshow -i dummy";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
            process.Start();
            process.WaitForExit();

            string output = process.StandardError.ReadToEnd();
            string[] lines = output.Split('\n');
            var devices = lines.Where(line => line.Contains("audio")).Select(line => line.Trim()).ToArray();
            return devices;
        }
    }

使用它:

var audioDevices = FFmpegHelper.GetAudioCaptureDevices();
pb3s4cty

pb3s4cty1#

你的问题中有很多问题。首先,你需要重新阅读你自己的问题,看看它是否传达了你的意图。据我所知,您希望找到系统上的所有音频输出设备。并且您想要从这些输出设备录制音频输出。你的ffmpeg应该能用。但你做得很奇怪。
为什么要查看StandardError的输出?我觉得你不应该专门过滤“音频”这个词
试试这个

using System.Diagnostics;

static string[] GetAudioCaptureDevices()
{
    var process = new Process 
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = @"D:\temp\ffmpeg.exe",
            Arguments = "-list_devices true -f dshow -i dummy",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        }
    };
    process.Start();
    process.WaitForExit();
    while (!process.StandardOutput.EndOfStream)
    {
        var line = process.StandardOutput.ReadLine();
        Console.WriteLine(line);
    }
    return new string[] {};
}

GetAudioCaptureDevices();

它会给予你这样的输出

[dshow @ 000002ca4f7c89c0] DirectShow video devices (some may be both video and audio devices)
[dshow @ 000002ca4f7c89c0]  "Integrated Webcam"
[dshow @ 000002ca4f7c89c0]     Alternative name "@device_pnp_\\?\usb#vid_1bcf&pid_28c1&mi_00#6&2d640bac&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
[dshow @ 000002ca4f7c89c0] DirectShow audio devices
[dshow @ 000002ca4f7c89c0]  "Microphone (Realtek(R) Audio)"
[dshow @ 000002ca4f7c89c0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{7F236980-BB25-46A8-AC39-5C7F156FD2B7}"
[dshow @ 000002ca4f7c89c0]  "Microphone (Steam Streaming Microphone)"
[dshow @ 000002ca4f7c89c0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{E2C402FA-B9F9-4B04-BCD9-852C8B7C0A72}"

相关问题