原文 http://stackoverflow.com/questions/18812224/c-sharp-recording-audio-from-soundcard
我想从我的声卡(输出)录制音频.我找到了 CSCore on codeplex,但我找不到任何例子.有没有人知道如何使用图书馆从我的声卡记录音频,并将记录数据写入硬盘?还是有人知道该图书馆的几个教程? 看看 CSCore.SoundIn namespace. 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(); } }