Audio analysis in sonic pi

Hello everyone! I am working on a track in sonic pi and for part of it I want something to happen when the amplitude of the total sound output of Sonic Pi sound passes a certain threshold. I was wondering if there was any way to do this. In addition, I was wondering what other types of sound analysis can be done in Sonic Pi? For example, is there a way to perform a spectral analysis on a sound?