pa_mic.sh 470 B

123456789101112131415161718
  1. #!/bin/bash
  2. #from https://unix.stackexchange.com/questions/685390/detecting-sound-silence-on-a-sox-pipe
  3. # Get your PulseAudio source monitor (edit regex to suit you)
  4. pulse_monitor=$(pactl list short sources | awk '$1 = /alsa.*monitor/ {print $2}')
  5. function wait_for_audio() {
  6. parec --rate 1000 -d $pulse_monitor 2>/dev/null \
  7. | LC_ALL=C fgrep -qm 1 .
  8. }
  9. while [ true ]; do
  10. wait_for_audio
  11. echo "Sound Detected starting @ $(date)" >> $log
  12. sleep 2
  13. exit
  14. done