Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。












想改善这个问题吗?更新问题,以便将其作为on-topic用于堆栈溢出。

7年前关闭。



Improve this question




我想从声卡(输出)录制音频。我找到了CSCore on codeplex,但找不到任何示例。有谁知道如何使用该库来记录我的声卡中的音频并将记录数据写入硬盘驱动器?还是没有人知道该库的一些教程?

最佳答案

看看CSCore.SoundIn namespaceWasapiLoopbackCapture类能够直接从任何输出设备记录。但是请记住,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();
    }
}

关于c# - C#录制声卡中的音频,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18812224/

10-09 22:59