Testing if audio devices / sound cards are currently playing?
If you're using PulseAudio (Gnome-based Linux distributions tend to use PulseAudio, you can check if one is running with ps -C pulseaudio
) and you want to know whether some applications are sending any data to any "sink", you could do:
pacmd list-sink-inputs | grep -c 'state: RUNNING'
Still with PulseAudio, if you want to check whether your sound output is muted, there might be simpler but you can get the "mute" status of the default "sink" using:
pacmd dump | awk '
$1 == "set-sink-mute" {m[$2] = $3}
$1 == "set-default-sink" {s = $2}
END {print m[s]}'
If I understand you right, here an example:
Silence:
fuser /dev/snd/timer && echo "Something is playing" || echo "There's silence"
There's silence
I turn on audacious:
fuser /dev/snd/timer && echo "Something is playing" || echo "There's silence"
/dev/snd/timer: 47663
Something is playing
For OSS chande /dev/snd/timer
to /dev/dsp
.
This is a very dependent method.