This node Tk-applause-meter made me think about getting a sound-level direct from /dev/dsp, instead of relying on on an external application. This snippet just shows the basic idea.
#!/usr/bin/perl use Audio::DSP; #alsamixer must be setup right, AC'97 capture adjusts sensitivity, #just turn it up to 100 for this to work as intended ($buf, $chan, $fmt, $rate) = (4096, 1, 16 , 8000); $dsp = new Audio::DSP(buffer => $buf, channels => $chan, format => $fmt, rate => $rate); $dsp->init() || die $dsp->errstr(); my $samples = 1500; my $num_tot = 0; my $div_tot = 0; # Record x samples of sound for (1..$samples) { #read 16 bits of raw data my $data = $dsp->dread(16) || die $dsp->errstr(); my $num = unpack( 'v', $data ); #filter out baseline noise if($num > 65000){next}else{ print "$num\n"; $num_tot += $num; $div_tot += 32768; #gives a good average } } $dsp->close(); print "\n\nAverage ",sprintf('%0.2f',$num_tot/$div_tot),"\n";