3

I have a Raspberry Pi (called Igor) in my room that plays music, and occasionally speaks a warning message. If I want to change its volume, or mute it, I need to ssh into it from my laptop and start alsamixer. This is a bit of a hassle and I'd like to use some keyboard shortcuts, or an onscreen control, just for changing Igor's volume.

I suppose I could cobble up a small server on the RPi that listens for network messages and adjusts the volume accordingly. From my laptop I could set up keyboard shortcuts that do something like

echo "+10%" | nc igor $portnumber

for 10% louder, and "-10%" for softer. Create my own API, so to say. But isn't there already something out there that does that? Does ALSA have an API for network access? Or does PulseAudio?

Just to make it clear, I don't want to stream the music itself to the RPi. Igor has its own sources of music.

2
  • 1
    Run amixer through ssh.
    – CL.
    May 10, 2017 at 7:42
  • @CL. That works! I will expand it to a full answer.
    – Jos
    May 10, 2017 at 8:23

1 Answer 1

0

@CL. gave me the idea of running a single command through ssh, triggered by a keyboard shortcut.

On the RPi, I have a script softer.sh like this:

#!/bin/bash
# Turn the volume down 10%
amixer -c0 set PCM -- $[$(amixer -c0 get PCM|grep -o [0-9]*%|sed 's/%//')-10]% > /dev/null 2>&1

This gets the current volume from amixer (which is a percentage), subtracts 10, sticks the "%" symbol to the end, and sets the volume to the result. Same for louder.sh which adds 10%.

On my laptop I set CTRL + F7 to execute:

ssh pi@igor softer.sh

and of course CTRL + F8 to

ssh pi@igor louder.sh
7
  • It works, but it's a bit laggy. Anyone has a faster solution?
    – Jos
    May 11, 2017 at 12:30
  • I guess it's slow because it has to make a new ssh connection every time, did you ever find a faster solution? Aug 31, 2019 at 9:26
  • No, and I haven't got around to writing a little netcat-based server that accepts commands over UDP, but one day, I will.
    – Jos
    Sep 2, 2019 at 7:16
  • Ah sorry, I forgot about this! In the end I wrote a nodejs http-server that runs the amixer commands. It seems to work pretty well, I can't perceive any lag. Happy to share if you're interested. Sep 2, 2019 at 14:38
  • @user3432422 yes, please! If you need an email address, please find my website through my profile.
    – Jos
    Sep 2, 2019 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .