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?

Sign
  • 21
  • 1
  • 3
  • CSCore has an implementation of the AudioSessions API. But unfortunately, Windows does not provide any APIs to capture the sound of a certain application. – Florian Apr 06 '14 at 12:30

1 Answers1

3

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:

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • re: #1 -- I wonder if you can "hack" an application to use Default Communication Device vs Default Sound Device as a way to separate the audio of the application from the rest (and if that'd be any easier than #2) -- or "I really wish Windows would allow you to specify the audio device for an application" :D – bdimag Apr 03 '14 at 19:23
  • 1
    This would be #2 rather than #1. There are different audio APIs, any hooking basically starts with checking what API the target app is using and then hooking this API exactly. There is #3 actually, which is a fully featured virtual audio device, but it is an overkill even compared to #2, the cleanest however method. – Roman R. Apr 03 '14 at 19:30