音频USB同时扬声器和麦克风无法在Raspberry PI 2上运行。 [英] Audio USB Simultaneous Speaker and Microphone not working on Raspberry PI 2.

查看:254
本文介绍了音频USB同时扬声器和麦克风无法在Raspberry PI 2上运行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们的应用程序,我们需要在外部USB设备上输出不同扬声器音频流的同时读取麦克风音频流(我们使用的是Sabrent USB外置立体声声音适配器,型号为AU-EMAC,由Microsoft推荐
链接))。它无法完成。在我们的测试过程中,它甚至经常将Raspberry PI 2从以太网断开,迫使我们重新启动它。

For our application, we need to read a microphone audio stream at the same time that we are outputting a different speaker audio stream on an external USB device (we are using the Sabrent USB External Stereo Sound Adapter, Model AU-EMAC, recommended by Microsoft (Link)). It cannot be done. During our tests, it even often disconnected the Raspberry PI 2 from Ethernet, forcing us to restart it.

您可以通过调用Start轻松检查无法同时访问麦克风和扬声器()代码示例中的(),它只是在扬声器上输出麦克风流。它适用于任何桌面Windows 10,但不适用于Raspberry PI Windows
IOT。

You can easily check that microphone and speaker cannot be accessed at the same time by calling Start() in the following code sample, which simply outputs the microphone stream on the speaker. It works on any Desktop Windows 10, but not on Raspberry PI Windows IOT .

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Media.Audio;
using Windows.Media.Capture;
using Windows.Media.MediaProperties;
using Windows.Media.Render;

namespace TestIOTAudio
{
    [ComImport]
    [Guid("5B0D3235-4DBA-4D44-865E-8F1D0E4FD04D")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    unsafe interface IMemoryBufferByteAccess
    {
        void GetBuffer(out byte* buffer, out uint capacity);
    }

    class Audio
    {
        private AudioGraph graph;
        private AudioDeviceOutputNode speakerOutputNode;
        private AudioDeviceInputNode microphoneInputNode;

        public async void Start()
        {
            await ConnectSpeaker();
            graph.Start();
        }

        private async Task ConnectSpeaker()
        {
            AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Speech);
            settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency;
            settings.AudioRenderCategory = AudioRenderCategory.Speech;
            AudioEncodingProperties audioEncodingProperties = new AudioEncodingProperties()
            { SampleRate = 48000, BitsPerSample = 32, Bitrate = 48000 * 32, ChannelCount = 1, Subtype = "Float" };
            settings.EncodingProperties = audioEncodingProperties;
            DeviceInformationCollection deviceInformationCollection = await DeviceInformation.FindAllAsync(DeviceClass.AudioRender);
            DeviceInformation deviceInformation = null;
            foreach (DeviceInformation d in deviceInformationCollection)
            {
                if (d.Name != "Headphones (Raspberry Pi 2 audio)")
                    deviceInformation = d;
            }
            settings.PrimaryRenderDevice = deviceInformation;
            CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);

            if (result.Status != AudioGraphCreationStatus.Success)
            {
                // Cannot create graph
                return;
            }

            graph = result.Graph;

            // Create a device input node
            CreateAudioDeviceInputNodeResult deviceInputNodeResult =
                await graph.CreateDeviceInputNodeAsync(MediaCategory.Speech);
            if (deviceInputNodeResult.Status != AudioDeviceNodeCreationStatus.Success)
            {
                return;
            }

            microphoneInputNode = deviceInputNodeResult.DeviceInputNode;

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

            speakerOutputNode = deviceOutputNodeResult.DeviceOutputNode;

            microphoneInputNode.AddOutgoingConnection(speakerOutputNode);
        }
    }
}

我们甚至尝试使用两个音频图表,一个用于麦克风,另一个用于扬声器,第一个图的输出到第二个图的输入,但我们有相同的错误。

We even tried using two audio graphs, one for the microphone and the other one for the speaker, feeding the output of the first graph into the input of the second, but we have the same bug.

我的问题是:这是固定的,还是我们应该使用两个USB音频设备?我应该在哪里发布我的问题,以便Microsoft工程师能够看到并回答?

My question is: Will this be fixed, or should we use two USB audio devices? Where should I post my question so that Microsoft Engineers will see it and answer?

非常感谢!

推荐答案

尝试将其更改为

Try changing it to

CreateDeviceOutputNodeAsync(AudioRenderCategory.Media); 

并看到有效的eif。


这篇关于音频USB同时扬声器和麦克风无法在Raspberry PI 2上运行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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