C#记录来自声卡音频 [英] C# recording audio from soundcard
问题描述
我想记录从我的声卡(输出)音频。我发现在codePLEX CSCore但我找不到任何的例子。有谁知道如何使用该库记录来自我的声卡音频和写入记录数据到硬盘?或有没有人知道该库的几个教程?
I want to record audio from my soundcard(output). I've found CSCore on codeplex but I could not find any examples. Does anyone know how to use the library to record audio from my soundcard and write the record data onto the harddrive? Or does anyone know a few tutorials on that library?
推荐答案
看看的的 CSCore.SoundIn命名空间。在<一个href=\"http://cscore.$c$cplex.com/SourceControl/latest#CSCore/SoundIn/WasapiLoopbackCapture.cs\">WasapiLoopbackCapture类是能够直接从任何输出设备来记录。但请记住,WasapiLoopbackCapture仅因为Windows Vista中。
Take a look at the CSCore.SoundIn namespace. The WasapiLoopbackCapture class is able to record directly from any output device. But keep in mind that WasapiLoopbackCapture is only available since Windows Vista.
编辑:这code应该为你工作。
This code should work for you.
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#记录来自声卡音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!