I've found a solution that doesn't work by me:
audio - Monitoring the microphone level with a command line tool in Linux - Super User https://superuser.com/questions/306701/monitoring-the-microphone-level-with-a-command-line-tool-in-linux
The problem is that they are using Maximum amplitude to detect sound. However its value is always the same by me, no matter whether the recorded audio contains only silence or some sounds. For example:
10 sec of silence (Can be downloaded here: http://denis-aristov.ucoz.com/en/test-mic-silence.wav ):
$ arecord -f S16_LE -D hw:2,0 -d 10 /tmp/test-mic-silence.wav
$ sox -t .wav /tmp/test-mic-silence.wav -n stat
Samples read: 80000
Length (seconds): 10.000000
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -1.000000
Midline amplitude: -0.000015
Mean norm: 0.202792
Mean amplitude: 0.009146
RMS amplitude: 0.349978
Maximum delta: 0.913849
Minimum delta: 0.000000
Mean delta: 0.001061
RMS delta: 0.005564
Rough frequency: 20
Volume adjustment: 1.000
10 sec with some sounds (Can be downloaded here: http://denis-aristov.ucoz.com/en/test-mic-sounds.wav ):
$ arecord -f S16_LE -D hw:2,0 -d 10 /tmp/test-mic-sounds.wav
$ sox -t .wav /tmp/test-mic-sounds.wav -n stat
Samples read: 80000
Length (seconds): 10.000000
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -1.000000
Midline amplitude: -0.000015
Mean norm: 0.185012
Mean amplitude: 0.010225
RMS amplitude: 0.334286
Maximum delta: 1.999969
Minimum delta: 0.000000
Mean delta: 0.006213
RMS delta: 0.057844
Rough frequency: 220
Volume adjustment: 1.000
What is the difference? What values to use for sound detection? Or do I have to set something up because something works wrong?
I've just used another computer (a notebook with a built-in microphone). I've recorded two WMA files (with and without sounds) using Windows "Sound Recorder". Converted them to WAV files using audacity and got the following outputs. Maximum amplitudes differ this time:
With sounds:
$ sox -t .wav /tmp/mic-sounds.wav -n stat
Samples read: 581632
Length (seconds): 6.594467
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -1.000000
Midline amplitude: -0.000015
Mean norm: 0.013987
Mean amplitude: 0.000062
RMS amplitude: 0.065573
Maximum delta: 1.999969
Minimum delta: 0.000000
Mean delta: 0.011242
RMS delta: 0.047009
Rough frequency: 5031
Volume adjustment: 1.000
Without sounds:
$ sox -t .wav /tmp/mic-silence.wav -n stat
Samples read: 372736
Length (seconds): 4.226032
Scaled by: 2147483647.0
Maximum amplitude: 0.029022
Minimum amplitude: -0.029114
Midline amplitude: -0.000046
Mean norm: 0.005082
Mean amplitude: -0.000053
RMS amplitude: 0.006480
Maximum delta: 0.030487
Minimum delta: 0.000000
Mean delta: 0.005815
RMS delta: 0.007285
Rough frequency: 7891
Volume adjustment: 34.348
May it be an indication that there are some problems with the microphone on another computer?