Application of technology to problems

On the common occurance of walking into an office or other shared restroom to be hit with nauseating stench:

How hard would it be to make bathroom fans variable speed and hook them up to an odor detector? Serious funk would cause the fans to crank up, while most of the time they could almost idle, or totter along at their regular there’s-someone-in-here speed. What do I have to do to make this happen?