How to know when a sound in a given frequency starts and ends? I need to detect two sounds (913 Hz and 1370 Hz), knowing the time in which each starts and ends.

At this time, I am using a band pass filter (butter), and this is the result:



Here is the first time this sound occurs:



The red line is where the sound is supposed to end (276 ms).

So how can I detect that the first time the tone occurs it starts at 0 ms and ends at 276 ms?
I would recommend reading about onset detection. It's about music signals but nevertheless a few ideas might be extracted from it.

From a more general point of view, what I would do is a frame-based analysis of the signal and define some kind of energy threshold/noise floor with which I could determine if there is activity or not.