sonda-audio 1007 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. #defaults
  3. instance="$(hostname)"
  4. remote='https://push.example.net'
  5. freq=87900000
  6. station=ror
  7. user=
  8. password=
  9. # override defaults with sonda.conf
  10. # important: set $user and $password (to push metrics)
  11. conffile="$(dirname "$0")/sonda.conf"
  12. test -f "$conffile" && source "$conffile"
  13. auth="-u ${user}:${password}"
  14. curl="curl $auth"
  15. snrduration=10
  16. shortfreq=$(bc <<< "scale=1; $freq/1000000")
  17. mkdir -p "/tmp/samples/$station"
  18. export AUDIODEV=default:CARD=SB
  19. timeout $snrduration sox -q -c 1 -t alsa -d -t ogg - | sponge "/tmp/samples/${station}.ogg"
  20. sox /tmp/samples/$station.ogg -n stats 2>&1 |
  21. grep -vw -e Bit-depth -e NaN | grep -E '[0-9]$' |
  22. sed -e 's/\([^ ]\) *\([-0-9]\)/\1=\2/;s/ */ /;s/^/radio_sox_/'| \
  23. tr ' ' _|tr -d '():' | \
  24. tr = ' ' | \
  25. $curl --data-binary @- "$remote/metrics/job/radio/instance/$instance/freq/$shortfreq/modulation/fm/station/$station"
  26. cp "/tmp/samples/${station}.ogg" "/tmp/samples/$station/$(date '+%F_%T').ogg"
  27. find /tmp/samples/ -mtime +2 -delete