Skip to content

Instantly share code, notes, and snippets.

@linusgke
Created May 2, 2023 14:17
Show Gist options
  • Save linusgke/e2e5c6e92e9c420d6757fc439001d78c to your computer and use it in GitHub Desktop.
Save linusgke/e2e5c6e92e9c420d6757fc439001d78c to your computer and use it in GitHub Desktop.
#!/bin/bash
# ========================
# || sound_detector.sh ||
# by elektr0nisch © 2023
# ========================
#
# This script constantly checks whether there are any active audio streams. (= sound is playing on the machine)
# Originally being used with an Raspberry Pi in an BT/DLNA/AirPlay/Spotify receiver setup.
playing=0
while true
do
if (cat /proc/asound/card*/pcm*/sub*/status | grep -q 'RUNNING')
then
if [[ $playing -eq 0 ]]; then
echo "start"
# Do something when audio is detected
playing=1
fi
else
if [[ $playing -eq 1 ]]; then
echo "stop"
# Do something when audio has stopped
playing=0
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment