Terminal command to set audio volume?

286,286

Solution 1

Parts of this answer comes from Setting microphone input volume using the command line?, placed here for your convenience.

Increase volume by 5%

amixer -D pulse sset Master 5%+

Decrease volume by 5%

amixer -D pulse sset Master 5%-

Set volume to 50%

amixer -D pulse sset Master 50%

If you are using ALSA, amixer can be helpful for your script programming.

When dropping the amixer --help command in a terminal you will see something like this:

enter image description here

Depending on your soundcard, levels may be different than mine, but you can use alsamixer in the terminal in order to check which levels and which features in your sound card you can call in a command to set the volume as you wish.

enter image description here

In my example, with my principal sound card (I have 2: the embedded and a PCI audio card), levels are from 0 to 100, this way I can change the volume of a desired input/output in my soundcard by dropping in a terminal the next command:

amixer -c 0 set Front 50DB 
amixer -c 0 set Front 64DB 

In the first command, the result will set the Front panel output to 78% level and the second one will set the Front panel output to 100% level.

In order to gather information related to your mixer controls, drop the amixer command with no parameters and you will get a list. Or indicate which audio device you wish to see a list of controls with amixer -c X (where "X" is the number of your audio device).

BTW: Remember that DB values are calculated logarithmically and not linearly.

Remember that this command allow you to control parameters on whatever sound device you are currently using.

Good luck!

Solution 2

You can do it using PulseAudio itself (I won't recommend using ALSA because then you can't use the GUI to bring the volume up/down).

Using pactl: you can set the volumes for a specific device as follows:

pactl set-sink-volume @DEFAULT_SINK@ +10%

This makes the volume 10% up. If you want it 10% down:

pactl set-sink-volume @DEFAULT_SINK@ -10%

If you need the volume at 50%:

pactl set-sink-volume @DEFAULT_SINK@ 50%

If you need to rock the entire place:

pactl set-sink-volume @DEFAULT_SINK@ 150%

You can use percents or integers, but the integers are slow and may not be your thing.

pactl/pacmd (unlike amixer) allows to increase volume over 100% :-).

Solution 3

A late answer but could be useful for someone.


You can control the volume for the current sink using the following commands

  • Raise Volume: pactl set-sink-volume @DEFAULT_SINK@ +1000

  • Lower Volume: pactl set-sink-volume @DEFAULT_SINK@ -1000

  • Mute: pactl set-sink-mute @DEFAULT_SINK@ toggle

You can use the following values to control the volume:

Integer

  • Specific value: <number>
  • Increase: +<number>
  • Decrease: -<number>

Example:

pactl set-sink-volume @DEFAULT_SINK@ 50000 will set the volume around 76%

Linear Factor

  • Specific value: <number>.<number>
  • Increase: +<number>.<number>
  • Decrease: -<number>.<number>

Example:

pactl set-sink-volume @DEFAULT_SINK@ 0.44\ will set the volume around 76%

Percentaje

  • Specific value: <number>%
  • Increase: +<number>%
  • Decrease: -<number>%

Example:

pactl set-sink-volume @DEFAULT_SINK@ 76% will set the volume around 76%

Decibel Value

WARNING : don't experiment with decibel values while using headphones unless you know what you are doing, you could damage your earing

  • Specific value: <number>dB
  • Increase: +<number>dB
  • Decrease: -<number>dB

Example:

pactl set-sink-volume @DEFAULT_SINK@ 0.0dB will set the volume to 100%


Sources Arch Wiki, pactl man page

Solution 4

amixer set 'Master' 10%+ - to increase max sound 10%

amixer set 'Master' 10%- - to decrease max sound 10%

amixer set 'Master' 10% - to get 10% of the max sound

amixer set 'Master' 80% - to get 80% of the max sound

.. etc.

If you want to set the volume to other than 'Master', check the list by:

amixer scontrols


You may also want to check out alsamixer and pacmd

Share:
286,286

Related videos on Youtube

Marius
Author by

Marius

Updated on September 18, 2022

Comments

  • Marius
    Marius almost 2 years

    I have an external sound card which mostly works fine, except that when its first plugged in, or when I turn on my laptop, the volume gets set to 100%. That is, the overall system volume, as shown in the sound indicator.

    What I'm looking for is a terminal command that will set that volume to 50%, so that I can run it on login and not have to worry that the first audio I play is going to blare out at me if I forget to turn the volume down. What commands allow you to change that volume, i.e. the one in the sound indicator?

    I've poked around in gsettings and dbus, but have been unable to find anything that would let me set the system volume like that. I do know about alsamixer, but that's not the solution I'm looking for, since that doesn't allow me to change the volume using the sound indicator or my laptop's multimedia keys.

  • Smile4ever
    Smile4ever over 9 years
    If you're using headphones, try increasing the zero to one: pactl set-sink-volume 1 50%
  • Pooyan Khosravi
    Pooyan Khosravi over 8 years
    It's worth a note that if you don't have a "Master" controller or "Master" controller can't change actual output volume you are probably working with wrong sound card. F6 on alsamixer and --card n on amixer change sound card.
  • Geppettvs D'Constanzo
    Geppettvs D'Constanzo over 8 years
    That's a good point! @PooyanKhosravi, even when you can invoke the sound card you wish to automate from the command line by dropping the "-c X" (where "X" is the number of your sound card), it's good to know the information you provided. Thank you very much!
  • pevik
    pevik almost 8 years
    pactl (unlike amixer) allows to increase volume over 100% (seeing in pavucontrol) :-)
  • pevik
    pevik over 7 years
    If you want to share the same commands on different hosts with different sinks, you can use @DEFAULT_SINK@ as a sink instead of number 0. You set your default sink with pactl set-default-sink my-sink-name (list names with pactl list short sinks).
  • ideasman42
    ideasman42 almost 6 years
    Getting: Failed to get sink information: No such entity, how to troubleshoot this? - Edit, I needed to use a sink besides 0. The first number of pactl list short sinks can be used. This command works for example: pactl set-sink-volume $(pactl list short sinks | head -n1 | cut -f1) 50%
  • djboris
    djboris over 5 years
    +1 !! The only solution that worked for me instantly.
  • DDsix
    DDsix over 4 years
    The amixer command randomly messed up the balance (left/right) for my speakers/headphones, pactl with @DEFAULT_SINK@ works fine.
  • Geppettvs D'Constanzo
    Geppettvs D'Constanzo over 4 years
    If you are using Ubuntu 18.04 or newer, it seems it is another kind of an issue because of we are experiencing the same when using the same behaviour with pactl. And pavucontrol allow us to see how is it having effect via GUI.
  • sistematico
    sistematico about 4 years
    @exic awesome! Works with Arch Linux and i3-gaps...