I've done this before. Here's my blog article from 2011 with code examples: http://www.macetech.com/blog/node/111
On Windows and Linux, you can try to set Stereo Mix as your recording device in the audio settings. On Mac, I have used Soundflower to do the same thing...you can set it as an output device, and then it lets you also select it as a recording device while monitoring the audio stream to the system audio device (same thing Stereo Mix does on Windows).