How to read the volume level of pulseaudio clients in the console

I would like to read the volume of sound currently playing for several pulseaudio clients.

The problem I want to solve is this: I listen to xmms music, then pause it to listen to the song my friend on youtube sent me. An hour later, I suddenly discovered that I was not listening to music!

The (most basic) solution I was thinking of is bash scripts that check the volume of all non xmms applications every second if any application makes sound, xmms pauses if there is no sound, and xmms is turned off, xmms is turned on . (I want to be able to do this in different ways, for example, pidgin should be ignored)

I could only find graphical tools for reading the volume, like pavucontrol, which displays it well. I really would not want to code all kinds of C programs to do such a simple thing, therefore:

  • I think in the right direction or is there a simpler solution
  • If this does not happen, how can I find out the current volume level for individual applications
+4
source share
3 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 one 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 will need to adjust the arguments to parec and, possibly, the configuration of PulseAudio, click on the output stream and write from it.

+6
source

pactl list resets the list ... well, it seems like almost everything. With the mplayer -ao pulse instance running, I get the following among the output:

 Sink Input #2 Driver: protocol-native.c Owner Module: 8 Client: 10 Sink: 0 Sample Specification: s16le 2ch 44100Hz Channel Map: front-left,front-right Mute: no Volume: 0: 100% 1: 100% 0: 0.00 dB 1: 0.00 dB balance 0.00 ... Properties: media.name = "audio stream" application.name = "MPlayer" native-protocol.peer = "UNIX socket client" .... application.process.binary = "mplayer" ... 

It does not give you the current monitor levels (the volume of the sound currently being played), but maybe this is enough?

+2
source

I would not even read volumes. I would write a module that contains a receiver that determines the volume of applications connected to it and can perform actions based on this, as well as a virtual application that you can route to an existing receiver for possible sound output.

0
source

Source: https://habr.com/ru/post/1340389/


All Articles