简体   繁体   English

如何将系统麦克风音频流传输到连接的设备麦克风音频流

[英]How transfer system mic audio stream to attached device mic audio stream

I am trying to attach USB device used for tele calling which have pnp sound controller for mic and speaker. 我正在尝试连接用于电话通话的USB设备,该设备具有用于麦克风和扬声器的pnp声音控制器。 Now i have two speaker and two mic for input output as shown in image below. 现在,我有两个扬声器和两个麦克风用于输入输出,如下图所示。 <code>扬声器</ code> 麦克风 . Now my motive is to transfer audio stream from system mic to usb mic and from usb speaker to system speaker. 现在,我的动机是将音频流从系统麦克风传输到USB麦克风,再从USB扬声器传输到系统扬声器。

I tried to solve this issue with virtual cable software but with this i need to depend on third party. 我尝试使用虚拟电缆软件解决此问题,但与此同时,我需要依赖第三方。 What can be the possible solution that can attained using c#. 使用c#可以获得的可能解决方案是什么。

I don't have knowledge about this, so don't know how to start. 我对此一无所知,所以不知道如何开始。 After googling i found 谷歌搜索后,我发现

  1. CS Core CS核心
  2. N Audio N音频

Can help me i don't know how. 可以帮助我,我不知道如何。

 public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        List<NAudio.Wave.WaveInCapabilities> sources = new List<NAudio.Wave.WaveInCapabilities>();

        for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
        {
            sources.Add(NAudio.Wave.WaveIn.GetCapabilities(i));
        }

        sourceList.Items.Clear();

        foreach (var source in sources)
        {
            ListViewItem item = new ListViewItem(source.ProductName);
            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, source.Channels.ToString()));
            sourceList.Items.Add(item);
        }
    }

    NAudio.Wave.WaveIn sourceStream,sourceStream1 = null;
    NAudio.Wave.DirectSoundOut waveOut = null;

    private void button2_Click(object sender, EventArgs e)
    {
        if (sourceList.SelectedItems.Count == 0) return;

        int deviceNumber = sourceList.SelectedItems[0].Index;

        sourceStream = new NAudio.Wave.WaveIn();
        sourceStream.DeviceNumber = 0;
        sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);



        NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream1);
        sourceStream.
        waveOut = new NAudio.Wave.DirectSoundOut();
        waveOut.Init(waveIn);

        sourceStream1.StartRecording();
        waveOut.Play();
    }

    private void button3_Click(object sender, EventArgs e)
    {
        if (waveOut != null)
        {
            waveOut.Stop();
            waveOut.Dispose();
            waveOut = null;
        }
        if (sourceStream != null)
        {
            sourceStream.StopRecording();
            sourceStream.Dispose();
            sourceStream = null;
        }
    }

    private void button4_Click(object sender, EventArgs e)
    {
        button3_Click(sender, e);
        this.Close();
    }
}

Using this code i can send mic audio to speaker but how can i implement my task using this. 使用此代码,我可以将麦克风音频发送到扬声器,但是如何使用此代码来执行任务。

Actually there is no way to do this without writing any custom driver. 实际上,没有编写任何自定义驱动程序就无法做到这一点。 You can not render audio data to a input device. 您无法将音频数据渲染到输入设备。 Input devices are meant to read data from. 输入设备用于读取数据。 Output devices (speakers) are meant to write data to. 输出设备(扬声器)用于向其中写入数据。

There are programs like virtual audio cable, which are using custom drivers to bypass these limitations. 诸如虚拟音频电缆之类的程序正在使用自定义驱动程序来绕过这些限制。

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

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