That sounds like a really interesting problem. You'd need microphones good enough, small enough, and cheap enough to hear the signal,
Signals processing/machine learning software robust enough to pick up a user-selected pattern and in a reasonable latency, and then a processor small enough and power efficient enough to process it all while again also being economical enough, and then have it last 8 hours.
"Completely blocking out" is out of reach, technologically; you'd need 80+ dB of attenuation, and the best anyone can do with things that fit around your head (earplugs, noise-canceling, etc.) is about 40, before you even start to touch the questions of selectivity and power usage. If you need 80 dB of attenuation your best bet is to contract an acoustics engineer to build a wall out of several layers of different materials.