Control music while sleeping


Sometimes I play music at night to help me get to sleep (because I'm so wicked), but if the music is too loud, I've noticed it can lead to poor-quality sleep. I've also noticed that, as you fall asleep, your sensitivity to sound increases. This program allows you to gradually decrease the volume of a music player running on Linux until it reaches a threshold. At that point, it rapidly drops the volume to zero, pauses the music, and puts the computer to sleep (by which point, you should hopefully already be asleep too). Optionally, you can make the machine wake up at a specific time, when the music is restarted, and the volume is gradually increased back to 100%.

For example, this command takes 1 hour and 40 minutes to diminish the volume and send the computer to sleep, and then wakes it up again at 7:30 in the morning:

soundasleep 1:40 -w 7:30

If you don't specify -w, the machine will go to sleep, but not automatically wake up.

-b base specifies the base threshold, in the range 0 to 100. 45 is the default.

-p dest specifies the DBus destination identifying the player. The default is org.mpris.MediaPlayer2.rhythmbox. You should be able to find the destination for your player by starting it, and then running:

dbus-send --session --dest=org.freedesktop.DBus \
  --type=method_call --print-reply /org/freedesktop/DBus \
  org.freedesktop.DBus.ListNames | grep -i mpris

The program is a short BASH script that makes use of dbus-send to control the player, and pm-suspend and rtcwake to suspend the computer and wake it up again. The script will normally ask you to provide your password, as soon as you invoke it, so that it can invoke pm-suspend or rtcwake later on.

Sorry, this software is currently not publicly available, for… reasons.