Paul Alexander
Paul Alexander

Reputation: 2748

c#/.NET - Recording the current audio being played

Is there any way in c#/.net of recording the current audio being played? I've searched a lot on the internet but the only result I could find is recording using a microphone.

I dont want to record using microphone input, I want to record what is being played on the computer when I click a record button.

Thanks

Upvotes: 0

Views: 312

Answers (2)

Roman Ryltsov
Roman Ryltsov

Reputation: 69724

You have two options here:

  1. Hardware loopback device - virtual "Stereo Mix" audio device, which acts as a regular audio capture device and in the same time produces a copy of mixed audio feed played through default audio output device of the system. Since such device shows up as real audio input device, you can use standard APIs, libraries and even exitsing applications to record from such device.

  2. Programmatic access to a virtual loopback device as if it was microphone-like device. API on the background will duplicate played audio content and make it available for reading back as it plays. The good news is that you can access the mixed audio feed for device of your interest.

Both options are described in detail in Loopback Recording article on MSDN and available via standard audio APIs, specifically WASAPI.

For C# development you are likely to use a wrapper like NAudio.

For option 1 you will find quite a few questions on StackOverflow, and for the other option the keyword is AUDCLNT_STREAMFLAGS_LOOPBACK.

Upvotes: 1

Scornwell
Scornwell

Reputation: 605

The only way to be able to receive data from another application is if the developer provides an access point, normally through some SDK, API, or other means. Without this, there is no way for your application code to receive the bytes from the other application.

The reason a microphone works is because it is receiving the sound output bytes from the application and sending those soundwave bytes back into your PC to render and output the sound. Since you have access to these bytes from the microphone you are able to capture the sound.

See if there is an API or an SDK from the developer of the application you are trying to get sound from.

Upvotes: 0

Related Questions