录制某个应用程序的声音

时间:2014-04-03 17:57:18

标签: c# audio record naudio wasapi

我想知道有没有办法记录某个应用程序的声音?我搜索了一段时间,但没有找到一些有用的信息。所以现在我正在使用NAudio库来录制WASAPI环回和麦克风声音,将它们混合在一起并使用以下代码保存到mp3文件:

Silence = new WaveOut();
Silence.Init(new SignalGenerator() { Gain = 0 });
Silence.Play();

SoundOut = new WasapiLoopbackCapture();
SoundOut.DataAvailable += SoundOut_DataAvailable;
SoundOut.StartRecording();

SoundOutBuffer = new BufferedWaveProvider(SoundOut.WaveFormat);

SoundIn = new WaveIn();
SoundIn.WaveFormat = SoundOut.WaveFormat;
SoundIn.DataAvailable += SoundIn_DataAvailable;
SoundIn.StartRecording();

SoundInBuffer = new BufferedWaveProvider(SoundIn.WaveFormat);

List<ISampleProvider> Sources = new List<ISampleProvider>
{
    SoundOutBuffer.ToSampleProvider(),
    SoundInBuffer.ToSampleProvider()
};

Mixer = new MixingSampleProvider(Sources);
Sampler = new SampleToWaveProvider16(Mixer);
MP3Writer = new LameMP3FileWriter("File.mp3", Mixer.WaveFormat, 128);

此外,我发现CSCore库似乎看起来像NAudio有一些额外的功能,但完全没有文档。可能是CSCore有我需要的功能吗?

1 个答案:

答案 0 :(得分:2)

没有“合法”API可用于记录应用程序输出,旨在完全解决相关任务。

实现目标有两种黑客方式:

  1. 要从loopback设备录制,数据将是所有应用程序的混合输出,而不仅仅是特定的
  2. 挂钩应用程序中的音频API,以拦截应用程序请求以将数据发送到音频输出设备,并作为“中间主要”记录它或以其他方式复制到别处
  3. 第一个是相对简单的,另一个是针对API和应用程序的黑客攻击,并且很难做长篇短文很难做到。

    另见:

相关问题