Beat me. Was gonna say shot spotter already does that.
Don't know if that could be adapted - maybe.
The sensors and code that recognizes a gunshot could be tweaked, but rather than GPS coordinates (which would be useless inside a school building, marginally useful on a large campus) the system could perhaps identify the closest room or corridor where the shot was loudest (the Shot Spotter works on DB of the signal to range it).
Definitely doable - but definitely make it a different sound than the fire alarm so they know to secure their rooms rather than congregate in the hallways.
On second thought, that's probably as realistic as one could ask for.