Reputation: 21
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
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:
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