I also don't know that you really need that last level of topic unless you are going to put something else in there too.
Personally, I wouldn't want to put a loop inside a loop, better to call a function from the main loop that tests and resets a ms variable, only trigger the processing if the elapsed time is > a threshold.
Now you can test for sound on every loop and once it is high enough, start recording your ms timer variable. On each loop where the sound is still high, continue to update the timer variable until you exceed the threshold. Then send the msg and reset the timer. If the sound level goes low, reset.
Also personally, I would want sound levels to be triggered over a longer period but of course that means that you need to allow for small periods of quiet that you would expect from a barking dog while it takes a breath. A 50ms sound could be triggered by all sorts of things. A repeated intermittent sound over, lets say, a minute, would be more likely to be a barking dog.