Skip to content

Instantly share code, notes, and snippets.

@megastef
Created April 3, 2018 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megastef/dd90ece3b12e16548f4137aa521020c9 to your computer and use it in GitHub Desktop.
Save megastef/dd90ece3b12e16548f4137aa521020c9 to your computer and use it in GitHub Desktop.
SOX, record sound, output sox stats decibel value as JSON
# Script to putput dB level from microphone
# output:
# {"db": -87.03}
# {"db": -86.87}
# ...
while [ 1 ]
do
sox -b 32 -e unsigned-integer -r 96k -c 2 -d --clobber --buffer $((96000*2*10)) /tmp/soxrecording.wav trim 0 1 2> /dev/null
sox /tmp/soxrecording.wav -n stats 2>&1 >/dev/null | grep "RMS lev dB" | awk '{print "{\"db\": " $4 "}"}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment