我正在尝试使用 NAudio 在 C# 中录制音频。在查看了 NAudio Chat Demo 之后,我使用了那里的一些代码进行记录。
这是代码:
using System;
using NAudio.Wave;
public class FOO
{
static WaveIn s_WaveIn;
static void Main(string[] args)
{
init();
while (true) /* Yeah, this is bad, but just for testing.... */
System.Threading.Thread.Sleep(3000);
}
public static void init()
{
s_WaveIn = new WaveIn();
s_WaveIn.WaveFormat = new WaveFormat(44100, 2);
s_WaveIn.BufferMilliseconds = 1000;
s_WaveIn.DataAvailable += new EventHandler<WaveInEventArgs>(SendCaptureSamples);
s_WaveIn.StartRecording();
}
static void SendCaptureSamples(object sender, WaveInEventArgs e)
{
Console.WriteLine("Bytes recorded: {0}", e.BytesRecorded);
}
}
但是,没有调用 eventHandler。我正在使用 .NET 版本“v2.0.50727”并将其编译为:
csc file_name.cs /reference:Naudio.dll /platform:x86