STFU, Rhythmbox!
Ubuntu’s default music player for Gnome is Rhythmbox, in case you weren’t aware. It’s a decent enough player, though I’m told it fails at large collections, but I’m not here to plug it or rag on it.
One of its niftier features is software mixing. In other words, it can adjust the volume of the playing audio without adjusting the actual hardware volume levels for the soundcard.
This is cool for two reasons. First, there’s a CLI to get and set the player volume. It’s not very script-friendly, but it’s workable. Second, you can play something else at full volume while playing an mp3 at reduced volume.
For example, if your email client can execute a command when mail comes in, you can turn down the volume on the mp3, play a notification wav at full volume, and then turn the volume back up on the mp3. Mine happens to read a brief summary through the eSpeak speech synthesizer.
This program will turn the volume down on Rhythmbox, leaving the hardware volumes untouched and storing the volume for use by the second script.
#!/bin/sh # # rhythmbox-stfu.sh # # Turn down the volume on Rhythmbox, storing the previous # volume in $TMPDIR/rhythmbox-saved-volume. # export XAUTHORITY=$HOME/.Xauthority DISPLAY=:0 vol=`rhythmbox-client --no-start --print-volume | cut -d' ' -f4 | sed 's/\.$//' 2>/dev/null` if test "x$vol" = "x"; then exit 0 # Rhythmbox isn't running fi echo $vol > ${TMPDIR:-/tmp}/rhythmbox-saved-volume rhythmbox-client --set-volume 0.1 sleep 1
After running that, you can feed whatever else you want through the sound system at full volume, with the mp3 playing at about 10% volume, after which you can run this script to restore it:
#!/bin/sh export XAUTHORITY=$HOME/.Xauthority DISPLAY=:0 rhythmbox-client \ --no-start \ --set-volume `cat ${TMPDIR:=/tmp}/rhythmbox-saved-volume` rm -f $TMPDIR/rhythmbox-saved-volume
Pretty easy, huh? Now we just hook it into a wrapper for a speech synthesizer:
#!/bin/sh if test "x$1" != "x"; then echo "$@" | sh $0 exit $? fi tmpfile=`tempfile -p speech` rhythmbox-stfu while read text; do echo "$text" | espeak -w $tmpfile aplay -q $tmpfile rm -f $tmpfile done rhythmbox-ok
And there you go. Volume goes down while the computer speaks, comes back up when it’s done.

thus trade browsers serious 1990 study