9

Is it possible to record Window's output sounds programmatically in C#? A bit like recording something from the "what you hear" or "stereo output" feature (without having to select them)?

MusiGenesis
  • 72,855
  • 39
  • 185
  • 327

3 Answers3

7

This is called loopback recording, and it is possible in Windows. If you have a soundcard that supports loopback (I just checked on my low-end Toshiba laptop, and it doesn't) you can record straight from the loopback device using the waveInOpen etc. API, which is easy to use in C#. Note: recording audio in this way necessarily entails a reduction in quality, since the audio signal is converted to analog for output and then re-digitized to support the loopback interface.

If you don't have a soundcard, WASAPI will let you do this. I suppose WASAPI can be used with C#, but it looks painful.

MusiGenesis
  • 72,855
  • 39
  • 185
  • 327
  • 1
    Is this the one? http://www.pinvoke.net/default.aspx/winmm/waveinopen.html?diff=y – Chris Pfohl Feb 10 '11 at 04:03
  • 1
    http://winmm.codeplex.com/ is an excellent C# wrapper of the `winmm.dll` API functionality. – MusiGenesis Feb 10 '11 at 04:10
  • I should clarify my answer here by saying that the `waveInOpenEtc.` API is a royal $@&$!#& to use in C#, unless you find a good code sample that wraps it up for you, like the above. – MusiGenesis Feb 11 '11 at 03:13
  • 3
    There is a **working** example here. http://stackoverflow.com/questions/18812224/c-sharp-recording-audio-from-soundcard – Florian Apr 05 '14 at 09:33
6

Also checkout the NAudio library.

PS. C++ but relevant http://blogs.msdn.com/b/matthew_van_eerde/archive/2008/12/16/sample-wasapi-loopback-capture-record-what-you-hear.aspx?PageIndex=2

kervin
  • 11,482
  • 5
  • 41
  • 58
  • 2
    In NAudio, there is a `WasapiCapture` class, that can be used for capturing using WASAPI loopback. – svick Aug 23 '11 at 11:57
  • 1
    There has recently been added a `WasapiLoopbackCapture` class that simplifies this process. As of Aug 2012 it is not included in the v1.5 release, I had to download the sources and compile to use it. – Paccc Aug 29 '12 at 02:25
  • 1
    see http://stackoverflow.com/questions/18812224/c-sharp-recording-audio-from-soundcard for a **working** solution – Florian Jun 26 '14 at 08:17
3

I'm a bit tardy to the party, but CSCore has a pretty great library for managing windows audio events in C#.

This in particular looks like what you're wanting. http://filoe.github.io/cscore/sharpDox/1.2.0-release/#type/WasapiLoopbackCapture

Josh
  • 31
  • 3