You are not logged in.
Greetings !
I'm sick and tired of raising and lowering the volume every 10 seconds when someone starts a vacuum or drill next to me. I would like to write a script that does this for me, ideally based on alsa tools.
Would that be possible ?
I'm pretty sure there must be a way to set the volume from the command line.
What I'm wondering is this: is there a way, from the command line, to get a value indicating how much sound is the internal mic perceiving at a given time ?
Thanks you for any help !
Offline
It's 100% doable with CLI alsa tools.
>I'm pretty sure there must be a way to set the volume from the command line.
That's right, it's done with amixer. You probably know the ncurses-graphical alsamixer. amixer is a CLI tool. Something you need to know to avoid confusion : the volume percentage in amixer and alsamixer have different meanings (amixer in terms of power, alsamixer in terms of human perception). You have to pass the option -M to amixer to get the same percentages as in alsamixer.
amixer -M set Capture 50% Mic set to 50%
amixer -M set Capture 10%+ Now mic is at 60%
amixer -M set Capture 20%- now 40%.
Getting microphone volume in real time with alsa tools is trickier
arecord -D hw:0 -c 2 -d 0 -f S16_LE -vvv /dev/null | grep %-D hw:0 selects a device
-d 0 : interrupt after infinity seconds (don't stop recording)
-c 2 : number of channels
-f S16_LE : a specific sample format (irrelevant but use one available on your hardware)
-vvv : high verbosity (makes it print volume)
Volume is printed to stdout about every 10ms, you could direct the output to a file. Basically you're telling amixer to print volume level while recording, and sending the recorded data to /dev/null.
The problem is that it periodically prints a bunch of crap, that's why you pipe it to grep. See what happens without grep.
No noticeable CPU load btw.
Last edited by anon1054572 (2013-07-18 23:12:44)
Offline
I'm trying to do something similar, and while displaying the microphone volume on the CLI works,
writing the output to a file doesn't, the file stays empty.
The "bunch of crap" is however written to the file when I remove grep from the command.
The exact command I used (with or without the grep part):
arecord -D sysdefault -c 2 -d 0 -f S16_LE -vvv /dev/null | grep % > log.txtSeems really weird to me, am I missing something?
Edit: I found another solution on stackoverflow using SoX:
while true; do rec -n stat trim 0 .01 2>&1 | awk '/^Maximum amplitude/' | cut -d":" -f2 | sed 's/ //g'; doneLast edited by Rakksor (2013-09-08 13:40:30)
Offline