Created
May 2, 2023 14:17
-
-
Save linusgke/e2e5c6e92e9c420d6757fc439001d78c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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