How to check if any audio is currently playing via Terminal? Sometimes I turn up the audio on my MacBook, but then forget to turn it back down. Is there a terminal command I could use to detect if audio is currently playing (sound coming from the speakers)?

I need something similar to How to detect that the sound is currently playing in Linux? or Testing if audio devices / sound cards are currently playing?, except that neither of those work as they are for Linux.
I actually happened to find the answer recently, and I'll post it here for anyone who might need it:

if [[ "$(pmset -g | grep ' sleep')" == *"coreaudiod"* ]]; then echo audio is playing; else echo no audio playing; fi


I discovered the pmset method from this post, but I added some things to it.