Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a tool that will tell me, in less than half a second, if the microphone is picking up any sound above a certain threshold. (I plan to then mute the Master channel with another command line tool, like amixer.)

share|improve this question
up vote 5 down vote accepted

This solution will avoid writing repeatedly to disk, and even though it in worst case takes a second instead of the desired less than half a second, I found it to be fast enough after trying it. So, here are the two scripts I use:


while true; do
    arecord -d 1 /dev/shm/tmp_rec.wav ; sox -t .wav /dev/shm/tmp_rec.wav -n stat 2>\
    &1 | grep "Maximum amplitude" | cut -d ':' -f 2 | ./
    if [ $? -eq 0 ] ; then
         amixer set Master 0
         amixer set Master 80


#!/usr/bin/env python
import sys

number = 0.0

line = sys.stdin.readline()
thing = line.strip()
number = float(thing)

if number < 0.15:
    raise Exception,"Below threshold"

Hardly elegant, but it works.

Note: If you want a more gradual thing, add something like this:

   for i in `seq 0 80 | tac`; do
      amixer set Master $i

for muting and

   for i in `seq 0 80`; do
      amixer set Master $i

for unmuting.

share|improve this answer
A slightly more elegant solution, which supports half-second resolution and doesn't require a temporary file: while true; do amixer set Master $(rec -n stat trim 0 .5 2>&1 | awk '/^Maximum amplitude/ { print $3 < .15 ? 80 : 0 }'); done – nandhp Jun 29 '12 at 13:17
Python is a bit overkill,… result=$(AUDIODEV=hw:1 rec -n stat trim 0 .5 2>&1 | grep "Maximum amplitude" | grep -o "[0-9]\.[0-9]*$"); echo "$result > 0.01" | bc – kevinf Jun 15 at 5:55

There is a tool called pavumeter that lets you see the microphone level, Open capture interface of pavumeter,

Then adjust the capture sound level using pavucontrol, In pavucontrol, go to input devices, and adjust microphone sensitivity.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .