[pulseaudio-discuss] How do I read my microphone's source levels from the cmdline?

Tanu Kaskinen tanuk at iki.fi
Sun Sep 11 09:48:08 UTC 2016

On Sun, 2016-09-11 at 12:32 +0300, Tanu Kaskinen wrote:
> On Sun, 2016-09-11 at 15:31 +0800, Kai Hendry wrote:
> > 
> > In pavucontrol I can see the levels of my microphone;
> > http://s.natalian.org/2016-09-11/levels.mp4
> > 
> > That reading I hope is all I need for my noise monitoring system.
> > 
> > How do I get values of my levels from some cli tool like pamix or pactl?
> > 
> > I know I could do this with gstreamer, but I find it very hairy.
> > https://www.youtube.com/edit?video_id=PHKpVJ0rSRw
> We don't provide ready-made tools for that. Pavucontrol captures the
> audio like any other audio recording application (except it uses very
> low sample rate and requests a special "peaks" resampler that inverts
> negative sample values to positive). There's no "get one sample now"
> feature in pulseaudio, you have to set up a recording stream in one way
> or another.

I should add: a "get one sample now" feature wouldn't be useful anyway,
because the audio signal will all the time swing between negative and
positive values. The louder the sound is, the greater the magnitude of
those swings is. Getting just one sample does not get you a
reprsentative view of the loudness level, because nothing guarantees
that you get the sample from a moment when the sound wave is at its
peak. You need to observe a chunk of consecutive samples, and analyze
the wave. The simplest approach is to just take the sample with the
biggest value in the observed chunk (that's what pavucontrol does).


More information about the pulseaudio-discuss mailing list