This library allows capturing audio from a particular process on Windows or the reverse - capturing all system audio except for a specific process in C# applications.
It wraps the Windows API for Application Loopback Capture based on the example code from this repository: https://github.com/microsoft/Windows-classic-samples
The API is designed to be pretty simple to use and C#/.NET idiomatic, hiding the details of the native code.
constintCHANNELS=2;constintSAMPLE_RATE=48000;constintPROCESS_ID=0;// Replace with the ID of the process tree you want to capture (or exclude)// Create new capture. You need one for each process you want to capture (in case you want to have multiple in parallel)varcapture=newApplicationLoopbackCapture(CHANNELS,SAMPLE_RATE);capture.NewDataAvailable+=Capture_NewDataAvailable;capture.CaptureStopped+=Capture_CaptureStopped;// Start the capture. You can also pass it instance of Process class as well.// If you want to exclude the process audio and capture everything else give it ExcludeProcessTree insteadcapture.StartCapture(PROCESS_ID,CaptureMode.IncludeProcessTree);Console.WriteLine("Capturing... Press Enter to stop");Console.ReadLine();// The capture isn't guaranteed to stop immediatelly. The method is awaitable for that reason in case you need to waitawaitcapture.StopCapture();// You are free to call Dispose without waiting on StopCapture, it will schedule disposal of native resources when capture stops automaticallycapture.Dispose();voidCapture_NewDataAvailable(ReadoSpan<float>data){// Do something with the audio data// The audio samples will be interleaved}voidCapture_CaptureStopped(){// This is optional if you need to do something on when it stops}