Hm I take it it's a longish sound (ogg or mp3 or such). Possibly use on mp3end / waveend / midiend (depending on the sound file type), check if $filename is the one used here and if so then do the agent stuff from that event.