Question

I'm making an alarm clock and wanted to start at basically no volume and increase the sound per 2 seconds up one 'notch'/value until a certain predefined point where it won't increase anymore.

As of right now I'm using mplayer (it's a radio station, so I'm running mplayer http://66.225.205.192:80), but I don't care what I use (VLC, etc.))

My full code is

while true; do
  mplayer http://66.225.205.192:80
  sleep 1
done
Était-ce utile?

La solution

Googling for 'mplayer alarm clock' actually yields a lot of pages dealing with this problem and solutions that you can actually use right away, but let's give it a try anyway.

#!/bin/bash

{
    for ((volume = 0; volume <= 100; volume += 5)); do
        /usr/bin/aumix -v${volume} -w100 >/dev/null
        sleep 2
    done
} &

mplayer http://66.225.205.192:80
echo "good morning! :-)"

You need to install aumix, which is used here to change the volume (but you could use something else, of course). The block between { } gets run in the background. The aumix command sets the PCM volume to 100% and gradually adjusts the main volume in 5 percent increments every two seconds, once it hits 100% the loop finishes and the background job exits.

I have never used aumix, and you might want to read its man page in case it does not work as expected (this is untested).

mplayer runs in the foreground until you quit it, upon which it makes coffee for you greets you with a warm welcome.

Does that get you started?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top