简体   繁体   English

如何使用默认输出设备作为使用 AudioGraph 录制音频的源?

[英]How to use default output device as a source to record audio with AudioGraph?

In my UWP app I have the below code, that works with an input device (DeviceInformation), to record audio and to process this.在我的 UWP 应用程序中,我有以下代码,它与输入设备 (DeviceInformation) 配合使用,用于录制音频并进行处理。 I want to extend this, by also using the default output device instead of the mic.我想通过使用默认输出设备而不是麦克风来扩展它。 This basically means the app will analyze the audio going over the audio card and the speakers.这基本上意味着应用程序将分析通过声卡和扬声器的音频。

This is my code:这是我的代码:

 AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Media)
            {
                QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency
            };

            CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);

            if (result.Status != AudioGraphCreationStatus.Success)
            {
                // Cannot create graph
                System.Diagnostics.Debug.WriteLine(String.Format("AudioGraph Creation Error because {0}", result.Status.ToString()));
                return;
            }

            graph = result.Graph;

            // Create a device output node
            CreateAudioDeviceOutputNodeResult deviceOutputNodeResult = await graph.CreateDeviceOutputNodeAsync();
            if (deviceOutputNodeResult.Status != AudioDeviceNodeCreationStatus.Success)
            {
                return;
            }

            AudioDeviceOutputNode deviceOutputNode = deviceOutputNodeResult.DeviceOutputNode;
            System.Diagnostics.Debug.WriteLine("Device Output connection successfully created");


            // Create a device input node using the default audio input device
            CreateAudioDeviceInputNodeResult deviceInputNodeResult = await graph.CreateDeviceInputNodeAsync(MediaCategory.Other, graph.EncodingProperties, SelectedDevice);

            if (deviceInputNodeResult.Status != AudioDeviceNodeCreationStatus.Success)
            {
                // Cannot create device input node
                System.Diagnostics.Debug.WriteLine(String.Format("Audio Device Input unavailable because {0}", deviceInputNodeResult.Status.ToString()));

                return;
            }

            AudioDeviceInputNode deviceInputNode = deviceInputNodeResult.DeviceInputNode;
            System.Diagnostics.Debug.WriteLine("Device Input connection successfully created");


            frameOutputNode = graph.CreateFrameOutputNode();
            deviceInputNode.AddOutgoingConnection(frameOutputNode);

            AudioFrameInputNode frameInputNode = graph.CreateFrameInputNode();
            frameInputNode.AddOutgoingConnection(deviceOutputNode);
            //   frameInputNode.QuantumStarted += FrameInputNode_QuantumStarted;

            // Attach to QuantumStarted event in order to receive synchronous updates from audio graph (to capture incoming audio).
            graph.QuantumStarted += GraphOnQuantumProcessed;

How can I use the default output device in如何使用默认输出设备

CreateAudioDeviceInputNodeResult deviceInputNodeResult = await graph.CreateDeviceInputNodeAsync(MediaCategory.Other, graph.EncodingProperties, SelectedDevice);

To get the current default audio output (Render) device in one line:要在一行中获取当前的默认音频输出 (Render) 设备:

DeviceInformation defaultDevice = await DeviceInformation.CreateFromIdAsync(MediaDevice.GetDefaultAudioRenderId(AudioDeviceRole.Default));

You can also get the default Capture device and listen to changed events for each with the MediaDevice class.您还可以使用MediaDevice类获取默认捕获设备并侦听每个设备的更改事件。

It would seem that you can't use a Render device as an input node to record system audio ( see here )似乎您不能使用 Render 设备作为输入节点来录制系统音频( 请参阅此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM