Pulseaudio - adjust master volume from command line

Use this forum for questions related to graphics, sound or desktop environments.

Pulseaudio - adjust master volume from command line

Postby dbbolton » October 25th, 2011, 12:07 am

I am looking for a way to utilize the multimedia keys on my laptop. Specifically I want to bind a key to raise, lower, or mute the master volume (I'm using pulseaudio). I want something like

Code: Select all
amixer -c 0 set PCM 2dB+

which works with ALSA.
<nadir> i am the king of wobbly windows

RDU since 2007
User avatar
dbbolton
 
Posts: 231
Joined: February 12th, 2011, 9:32 pm

Re: Pulseaudio - adjust master volume from command line

Postby sgosnell » October 25th, 2011, 1:40 am

About 15 seconds with Google got me this how-to.
sgosnell
 
Posts: 27
Joined: July 30th, 2011, 3:45 pm

Re: Pulseaudio - adjust master volume from command line

Postby dbbolton » October 25th, 2011, 1:56 am

sgosnell wrote:About 15 seconds with Google got me this how-to.


Thanks for the link. I don't think it will do anything since I don't have a .volume file. The followup post that included a modified script to generate the necessary file, but it just arbitrarily printed the value '65536' into it. So if that's not the current volume, then you can't actually adjust the volume over the whole range.

If you mean to imply that I didn't search before posting, that's not the case. I searched for "pulseaudio command line" and which turned up essentially nothing other than references to pactl and pacmd. I checked their man pages and they didn't seem suitable-- I searched for /vol and there was no match.
<nadir> i am the king of wobbly windows

RDU since 2007
User avatar
dbbolton
 
Posts: 231
Joined: February 12th, 2011, 9:32 pm

Re: Pulseaudio - adjust master volume from command line

Postby sgosnell » October 25th, 2011, 2:26 am

Searching requires using useful terms. I think you don't really want to use the command line, you want to use hardware keys. I used 'pulseaudio volume control' and found that and other sources. Try that and see if you find more information.
sgosnell
 
Posts: 27
Joined: July 30th, 2011, 3:45 pm

Re: Pulseaudio - adjust master volume from command line

Postby dbbolton » October 25th, 2011, 3:33 am

sgosnell wrote:I think you don't really want to use the command line, you want to use hardware keys.

I want to use hardware keys to execute a shell command that will adjust the volume.
<nadir> i am the king of wobbly windows

RDU since 2007
User avatar
dbbolton
 
Posts: 231
Joined: February 12th, 2011, 9:32 pm

Re: Pulseaudio - adjust master volume from command line

Postby sgosnell » October 25th, 2011, 3:43 am

Better to have the hardware keys control the volume directly. In any case, your search returned no useful information. Try other terms.
sgosnell
 
Posts: 27
Joined: July 30th, 2011, 3:45 pm

Re: Pulseaudio - adjust master volume from command line

Postby mojoman » October 25th, 2011, 6:27 am

Like you I've done the same thing with alsa, aumix and multimedia keys. Never tried it with pulseaudio though but I'm assuming what you need is the cli commands? Could this be of use?

http://www.pulseaudio.org/wiki/CLI
Seriously, Stable is for senior citizens and Sid is for kids. Be a man and run Testing.
User avatar
mojoman
 
Posts: 427
Joined: February 9th, 2011, 12:33 pm
Location: In the neck of the wood

Re: Pulseaudio - adjust master volume from command line

Postby dbbolton » October 25th, 2011, 6:09 pm

sgosnell wrote:Better to have the hardware keys control the volume directly.

And how would that be accomplished? Even the solution in the page you suggested accomplished it through a shell script.

mojoman wrote:Like you I've done the same thing with alsa, aumix and multimedia keys. Never tried it with pulseaudio though but I'm assuming what you need is the cli commands? Could this be of use?

http://www.pulseaudio.org/wiki/CLI


The page is timing out. I will have to try it out later.

My guess is it's probably about pactl and pacmd. The script used pactl to adjust the volume in increments, but the problem is that you need to know what the current volume is in order to do it over the entire range. I tried looking through the output of pactl list but couldn't find it. I suppose I could just set the volume to an arbitrary value using the command and then I would know where to start.
<nadir> i am the king of wobbly windows

RDU since 2007
User avatar
dbbolton
 
Posts: 231
Joined: February 12th, 2011, 9:32 pm

Re: Pulseaudio - adjust master volume from command line

Postby ZitZ » October 25th, 2011, 11:31 pm

alright, I have exactly what you want working on my laptop using only pulseaudio so I think I can help. I don't remember where I got this script from, but I guess a repost at a different spot on the internets won't hurt and will help make this information easier to find.

Code: Select all
#!/bin/bash
#device="alsa_output.pci-0000_00_14.2.analog-stereo"
device="alsa_output.pci-0000_00_1b.0.analog-stereo"
case "$1" in
   "up")    # increase volume by 1000
      pacmd dump | awk --non-decimal-data '$1~/set-sink-volume/{if ($2~/'${device}'/) {if ($3+1000 > 65535) {system ("pactl "$1" '${device}' "65535)} else {system ("pactl "$1" '${device}' "$3+1000)}}}'
      ;;
   "down")  # decrease volume by 1000
      pacmd dump | awk --non-decimal-data '$1~/set-sink-volume/{if ($2~/'${device}'/) {if ($3-1000 < 0) {system ("pactl "$1" '${device}' "0)} else {system ("pactl "$1" '${device}' "$3-1000)}}}'
      ;;
   "mute")  # toggle mute
      pacmd dump|awk --non-decimal-data '$1~/set-sink-mute/{if ($2~/'${device}'/) {system ("pactl "$1" '${device}' "($3=="yes"?"no":"yes"))}}'
      ;;
esac


So put that file into your path and call it something like "volumeincrease" or whatever you want. Obviously, you will need awk installed and pacmd but these are both standard with debian and pulseaudio I believe. Atleast, I've never had to install either on debian.

The other potential problem I can forsee is that you will have to change the device variable in that script to the appropriate device on your machine if it is not the same as mine. I don't remember how to do this from the command line off the top of my head, but it can be found in the pulseaudio manager (paman) application I think it is called, if you chose to install that.

Then all that is left to do is make the script executable and then open up whatever application you are choosing to use to setup your keybindings. I personally use compiz. I bind the mute, volume up, and volume down keys with the following commands.

Mute: /usr/bin/volumeincrease mute
Volume Up: /usr/bin/volumeincrease up
Volume Down: /usr/bin/volumeincrease down

Okay, I hope my explanation works for you. :)
User avatar
ZitZ
 
Posts: 34
Joined: February 19th, 2011, 2:37 am

Re: Pulseaudio - adjust master volume from command line

Postby dbbolton » October 26th, 2011, 12:06 am

Zitz - thanks for the response. I will test it out along with the other one.

I decided, for the time being, to use kmix. I already installed k3b so installing kmix only took up about 2MiB of disk space. It uses more memory, but the nice thing is that it works with my media keys without any tweaking and it shows an OSD when adjusting the volume. Since I have plenty of RAM on my laptop this is probably the best option. I think using the script will be ideal for my lower-memory machines.
<nadir> i am the king of wobbly windows

RDU since 2007
User avatar
dbbolton
 
Posts: 231
Joined: February 12th, 2011, 9:32 pm

Next

Return to Desktop & Multimedia

Who is online

Users browsing this forum: No registered users and 1 guest

x