5

Is there a way to detect if any sound is playing (using a bash script)?

(I'm on Ubuntu 11.10 using pulseaudio.)

I plan on using it in an indicator to visually remind me sound is playing while the mute is on.

dgo.a
  • 891

1 Answers1

7

Using pulse-audio: You can try pactl list to see what pulse audio is doing with the sound hardware. I'm leaving the specifics of pulling out the status to you. For e.g.: This command would list the Sink and Source states.

pactl list | grep State

Using procfs for ALSA (Caveat: these proc entries might go away in the future): This snippet runs through the pcm playback devices in ALSA proc heirarchy.

if grep -q RUNNING /proc/asound/card*/*p/*/status 2>&1; then
   echo "Playing"
else
   echo "Idle"
fi
Anil
  • 648