我希望能够通过NAudio.WaveIn从麦克风设备获取输入,然后通过NAudio.WaveOut将准确的输入输出到输出设备。
我该怎么做呢?
发布于 2011-06-25 15:43:00
以下是为我工作的代码:
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);
}
}
}发布于 2011-04-18 14:11:49
最好的方法是使用BufferedWaveProvider作为WaveOut的输入。然后在WaveIn的DataAvailable回调中,将记录的数据提供给BufferedWaveProvider
void DataAvailable(object sender, WaveInEventArgs args)
{
bufferedWaveProvider.AddSamples(args.Buffer, 0, args.BytesRecorded);
}您需要注意,默认的缓冲区大小将导致明显的延迟,因此,如果您希望获得较低的延迟,您可能需要尝试一下缓冲区大小,看看您可以获得多低的延迟。
https://stackoverflow.com/questions/5694326
复制相似问题