1

I'm trying to check if any sound is coming out of my audio device from cli particularly. I've tried

cat /proc/asound/card*/pcm*/sub0/status

to get the status of the audio but however even when there's no sound playing I get results like this

owner_pid   : 2784
trigger_time: 12480.406201499
tstamp      : 14574.205418430
delay       : 1248
avail       : 86421
avail_max   : 86421
-----
hw_ptr      : 100504320
appl_ptr    : 100505280

I'm probably looking at this in the wrong but my end goal is to execute a command if no sound is playing for considerable amount of time.

shriek
  • 175
  • That file does not show if you're playing through a wrong output, or if some mixer control is wrong. – CL. Sep 11 '18 at 16:41
  • Okay, I think I might have found an answer to my problem. It actually does show the aforementioned information when the "window" is active even though the audio was paused. As soon as you make the window inactive it goes back to "closed" status. – shriek Sep 12 '18 at 03:19

1 Answers1

1

Hah! After 3 years I searched for this same question and didn't even realize that I had landed on my very own question.
Well, at-least for my future self here's the solution and some other notes.

cat /proc/asound/card*/pcm0p/sub0/status | grep -i running || <audio_not_running_cmd.sh>

The above command will run <audio_not_running_cmd.sh> if it fails to find any audio device that are not running.
Note: If you have PulsoAudio Volume window open then it will show "RUNNING" all the time. Try closing that window and the status should show closed after 4-5 seconds.

So with the above result you can just plop that script in your crontab and periodically check if your audio device is sleeping.

shriek
  • 175