2

I was wondering is there any way to record sound of a certain application? I've searched for a while but didn't found some useful information about this. So now I'm using NAudio library to record WASAPI loopback and microphone sound, mix them together and save to mp3 file using this code:

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);

Also I found CSCore library which seems to look like NAudio with some extra features, but a complete lack of documentation. May be CSCore have functionality which I need?

4

1 回答 1

3

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

有两种 hack 风格的方法可以实现这一目标:

  1. 从环回设备记录,数据将从所有应用程序混合输出,而不仅仅是特定的
  2. 在应用程序中挂钩音频 API 以拦截应用程序请求以将数据发送到音频输出设备并作为“中间主要”记录它或以其他方式复制到其他地方

第一个相对简单,另一个是特定于 API 和应用程序的 hack,长话短说很难做到。

也可以看看:

于 2014-04-03T18:06:22.557 回答