17

This will be useful to know before I start just in case the volume is turned to the maximum by default.

Also, more importantly, will the maximum volume be high enough to cause immediate hearing damage to children who use a Raspberry Pi with headphones? My daughter's first instinct may not be to remove the headphones if the noise was extremely loud, yet she is likely to be able to turn the volume up to maximum.

Assume that the headphones are a common bud type, which I suspect would be the type that gives the loudest sound for the least power output.

  • 2
    This would be OS dependent. What OS are you using? – user46 Jun 13 '12 at 3:19
  • It's all theoretical at the moment, as I don't have my device yet! – Highly Irregular Jun 13 '12 at 3:20
  • @dunsmoreb, assume Debian Squeeze, which is recommended on the raspberrypi.org downloads page – Highly Irregular Jun 13 '12 at 3:27
16

You can also set the volume with the command-line amixer tool

e.g.

amixer cset numid=1 -- -2000

Note: amixer and alsamixer are part of the alsa-utils package. You may need to install this first.

9

I expect the pi will use ALSA in which case you probably want the command alsamixer from the command line, or maybe there will be a GUI mixer control app.

You should be able to put a command to alsamixer or edit your ALSA config files to lower the default volume at boot time if needed.

4

According to this page there is a "sound mixer application in your applications menu", though I haven't found too many references to this, so I think what I'm about to say will be as good an alternative.

There is a very useful aumix tool which provides a visual terminal view (see image), though it won't be what kids are used with standard PCs!

There's some info on it here, here is the author's site, and there is always about.com

Most important options:

  • -v - main volume
  • -b - bass
  • -c - CD
  • -m - microphone
  • -t - treble
  • -q - print all levels

You can set them to a number (eg. -v 88) increment/decrement (eg. -b +10), or use R/P for Record/Play on the mic/CD (eg -c P).

image
(source: cyberciti.biz)

  • Answers should stand on their own - this relies on links, which could rot. – Alex Chamberlain Jun 18 '12 at 17:30
  • @Alex, good point, I've updated it a bit. – ACarter Jun 18 '12 at 17:41
2

I'm a little late to answer, but my solution only involves two simple command issued from the console (one to turn the volume up, one to turn the volume down). It require only a little setup, and the use of aliases.

Make sure you are in the user folder:

$ cd ~/

Create the file .bash_aliases (this will be where I keep all the aliases I make so they aren't lost when I reboot my Raspberry Pi):

$ sudo nano .bash_aliases

In the text editor, add the aliases:

# Increase volume by 5%
alias volup='sudo amixer set PCM -- $[$(amixer get PCM|grep -o [0-9]*%|sed 's/%//')+5]%'
# Decrease volume by 5%
alias voldown='sudo amixer set PCM -- $[$(amixer get PCM|grep -o [0-9]*%|sed 's/%//')-5]%'

Exit and save: Ctrl+X, Y, Enter

Reboot:

$ sudo reboot

Log in and test the commands:

$ volup
Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback 400 [100%] [4.00dB] [on]
$ voldown
Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback -131 [95%] [-1.31dB] [on]

Note: This solution has only been tested on Raspbian systems only (the OS that the OP assumed they would use).

1

Here's a solution for Raspian with amixer output for both channels Left and Right for the Master control:

Volume up by 5:

amixer set Master -- $[$(amixer get Master|grep "Front Left"|grep -o [0-9]*%|sed 's/%//')+5]%

Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 32768 [50%] [on]
  Front Right: Playback 32768 [50%] [on]

Volume down by 5:

amixer set Master -- $[$(amixer get Master|grep "Front Left"|grep -o [0-9]*%|sed 's/%//')-5]%

Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 29492 [45%] [on]
  Front Right: Playback 29492 [45%] [on]
1

alsamixer comes out-of-the-box and has a text-mode "GUI" which works over ssh.

You can use up/down arrows to control volume, as well as numbers from 0 to 10, which means you can turn your mobile into a fancy "remote volume control", where tapping 1 would be the lowest volume, and 9 the highest.

control raspberrypi volume from mobile phone

Number keypad mode is available (on android) in gboard, swype, swiftkey, etc. Also many keyboards/roms have the option to show arrow keys.

Use any ssh client of your choice, eg, termux, juicessh (android), or termius (ios/android).

Moreover, if you use termux with the termux-widget (€2.09 on google play, or free if you install via f-droid, since the app is open-source), then you can launch alsamixer by tapping in the desktop widget.

To make the shortcut appear in the widget, create an executable bash script under ~/.shortcuts/pi-volume.sh with the following content:

# use your pi's IP or the alias configured in ~/.ssh/config
ssh -t pi@192.168.0.123 alsamixer

The -t switch is important here as it allocates a TTY.

Now you don't need to type anything in the terminal on your mobile, just tap the script name in the widget.

(I have no affiliation with termux; I am just a user of the app.)

0

I propose a physical device that will allow for immediate access to volume if an when your software controlled volume isn't immediately accessible. I was hoping to find one with a volume limiting switch to avoid immediate max volume.

https://www.amazon.com/Koss-VC20-Volume-Control/dp/B00001P4XH/ref=pd_bxgy_23_img_2?_encoding=UTF8&pd_rd_i=B00001P4XH&pd_rd_r=EZMT1MQE6KSWWSB23X7Q&pd_rd_w=1BTbN&pd_rd_wg=KV24v&psc=1&refRID=EZMT1MQE6KSWWSB23X7Q

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.