23

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

4

1 回答 1

42

看看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();
    }
}
于 2013-09-15T12:14:40.500 回答