C#录制声卡音频

我想录制声卡(输出)中的音频。 我在codeplex上找到了CSCore,但我找不到任何例子。 有谁知道如何使用库来录制声卡中的音频并将记录数据写入硬盘? 或者有人知道该库的一些教程吗?

看一下CSCore.SoundIn命名空间 。 WasapiLoopbackCapture类能够直接从任何输出设备进行录制。 但请记住, WasapiLoopbackCapture仅在Windows Vista之后可用。

编辑:此代码应该适合您。

using CSCore; using CSCore.SoundIn; using CSCore.Codecs.WAV; ... using (WasapiCapture capture = new WasapiLoopbackCapture()) { //if nessesary, you can choose a device here //to do so, simply set the device property of the capture to any MMDevice //to choose a device, take a look at the sample here: http://cscore.codeplex.com/ //initialize the selected device for recording capture.Initialize(); //create a wavewriter to write the data to using (WaveWriter w = new WaveWriter("dump.wav", capture.WaveFormat)) { //setup an eventhandler to receive the recorded data capture.DataAvailable += (s, e) => { //save the recorded audio w.Write(e.Data, e.Offset, e.ByteCount); }; //start recording capture.Start(); Console.ReadKey(); //stop recording capture.Stop(); } }