我想从我的声卡(输出)录制音频。我已经找到了CSCore on codeplex,但我找不到任何示例。谁知道如何使用音频库从我的声卡录制音频,并将录制的数据写入硬盘?或者有人知道关于这个库的一些教程?
发布于 2013-09-15 20:14:41
看一看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();
}
}https://stackoverflow.com/questions/18812224
复制相似问题