本文介绍了从n音讯WaveIn记录输入,并输出到n音讯waveout的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲能够经由NAudio.WaveIn从麦克风设备获得输入,然后该精确输入经由NAudio.WaveOut输出设备输出

I want to be able to get input from a microphone device via NAudio.WaveIn, and then output that exact input to an output device via NAudio.WaveOut.

我将如何做到这一点。

推荐答案

下面是为我工作的代码:

Here is the code that worked for me:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.CoreAudioApi;

namespace WindowsFormsApplication1
{
    public partial class Form4 : Form
    {

        private BufferedWaveProvider bwp;

        WaveIn wi;
        WaveOut wo;
        public Form4()
        {
            InitializeComponent();
            wo = new WaveOut();
            wi = new WaveIn();

            wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);

            bwp = new BufferedWaveProvider(wi.WaveFormat);
            bwp.DiscardOnBufferOverflow = true;

            wo.Init(bwp);
            wi.StartRecording();
            wo.Play();

        }

        void wi_DataAvailable(object sender, WaveInEventArgs e)
        {
            bwp.AddSamples(e.Buffer, 0, e.BytesRecorded);

        }
    }
}

这篇关于从n音讯WaveIn记录输入,并输出到n音讯waveout的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 16:28