jrec2 can call hooks (invoke 3rd party software) upon detecting silence or audio. It include an optional random-playback control script that was used in an installation to record voice and if it detects silence plays back random snippets of previously recorded material.

pure-data might have been a wiser choice to maintain this; but besides the learning experience this c-code is very easy to deploy and keep-alive.