Sign
Sign

Reputation: 21

Record sound of a certain application

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?

Upvotes: 2

Views: 3495

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69724

There is no "legal" API available to record application output in terms of being designed to address exactly the task in question.

There are two hack-style approaches to achieve the goal:

  1. To record from loopback device, and the data will be mixed output from all application, not just specific one
  2. To hook audio APIs within the application in order to intercept application requests to send data to audio output device and being a "main in the middle" record it or otherwise copy elsewhere

The first is relatively simple to do, the other one is a hack specific to API and application and to cut long story short is hard to do.

See also:

Upvotes: 3

Related Questions