Is it possible to capture the speaker output in Android?

This would be for the purpose of determining, when listening to the microphone input, which sounds were generated from other apps and which originated from the user.

This is essentially to create an acoustic cancellation filter on the output of other apps, so their sounds don't interfere with the microphone input.