Unless your correction system can respond in real-time, you've accidentally created an audio-frequency bistatic radar :P
Masking with a static noise source can also help.
Fingerprinting a song introduces latency because the song has to play long enough to get an adequate sample for the fingerprint.
What would the headphones do before a match is established?
B. Space Domain
Canceling requires a waveform 180 degrees out of phase. It needs to be about the same size as the song. If you stream that waveform, there’s latency and mechanical rights issues. If it is stored locally, you need space for all-the-songs.
C. Music is bigger than Texas
Remixes, covers, recordings of live performances add complexity to fingerprinting and increase the size of the phased wave database.
Good luck.
The README explains the method: once the contaminating song is identified, it syncs up the recordings in time with a correlation analysis, adjusts for frequency-dependent gain effects, then subtracts the undesired content.
Warning: I'm not an audio engineer, the output sound quality is NOT good! This was just a toy project in my early days of learning to code. I assume there are much better ways to approach this that would yield significantly better results.
[1] https://github.com/mitchellpkt/tracksubtract