That goal cannot be met, at least not under Windows. The audio systems used by most applications do not have loopback capabilities. I discussed a third party driver at https://www.mathworks.com/matlabcentral/answers/386734-how-do-i-get-sound-data-from-a-speaker#answer_309137
The way that would work is that you would have to tell the application to send audio to what looks like a device it, but is the loopback driver instead. You would then open the loopback driver as an input device.