Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read out volume level of clients of pulseaudio in the console

I would like to read out the volume of the audio played at the moment for the several clients of pulseaudio.

The problem I like to solve is the following: I'm listening to music in xmms, then I put it on pause, to listen to a song a friend sent me on youtube. After an hour, I suddenly discover I am not listening to any music!

The (very basic) solution I was thinking of is a bash scripts which just checks the volume of all apps other than xmms every second, if any application is making sound, xmms is paused, if there is no sound, and xmms is silent, xmms is enabled. (I do want to be able to do this app-wise, for instance, pidgin should be ignored)

I could only find graphical tools to read out the volume, like pavucontrol, which displays it nicely. I really would not like to code all kinds of C programs to do such a simple thing, so:

  1. Am I thinking in the right direction, or is there a simpler solution
  2. If there isn't, how do I readout the current level of the volume for the seperate apps
like image 202
markijbema Avatar asked Feb 18 '11 21:02

markijbema


People also ask

How do I change the volume in PulseAudio?

The Input devices tab manager your sound inputs. To mute your microphone in pulseaudio toggle the button that looks like a speaker. To adjust input volume slide the slider to the right to increase volume or to the left to decrease volume.

What is Pactl command?

pactl can be used to issue control commands to the PulseAudio sound server. pactl only exposes a subset of the available operations. For the full set use the pacmd(1).

How do I change PulseAudio output?

In Pulseaudio Volume Control (pavucontrol), under the "Playback" tab, change the output of an application to <name>, and in the recording tab change the input of an application to "Monitor of <name>". Audio will now be outputted from one application into the other.

What is the difference between ALSA and PulseAudio?

Summarized: ALSA - dealing with the hardware, basically owning it. PulseAudio - a software proxy providing additional featues (mixing, equalizer) between your application and the ALSA/OSS subsystem.


1 Answers

Perhaps you can record one sample of audio from the output stream and see if it is (close to) 0. This pipeline gives you a single sample, in the form of a number between -32768 and 32767 (inclusive):

parec --raw --channels=1 --latency=2 2>/dev/null | od -N2 -td2 | head -n1 | cut -d' ' -f2- | tr -d ' '

You'll need to adjust the parec arguments, and possibly the PulseAudio configuration, to tap into the output stream and record from that.

like image 64
Thomas Avatar answered Sep 30 '22 11:09

Thomas