In 2012, I was trying to find a simple command that can play a sound at certain frequency, but I couldn’t find any which did that and only that. Three years has almost passed on, it’s 2015, and I finally found it. wave does exactly what I wanted, although it does not actually play the audio itself, only generating, therefore you need some helpful program to play the sound, such as aplay.

I’ve also made a video for it on my YouTube channel, you can hear the sounds.

For example, the following command plays C4 (261.63 Hz) and E4 (329.63 Hz) for 0.1 seconds on my system:

% wave -s 4800 261.63 329.63 |
aplay -f FLOAT_LE -r 48000 -c 1 -q

As you can see, wave can generate more one frequency of sine wave.

The default sampling rate is at 48k Hz, and it plays 48000 samples, which is equivalent to 1 seconds. You can also change the amplitude of the wave. The detail options are:

-a, --amplitude
takes an integer for the amplitude of the wave. defaults to 1.
-s, --samples
how many samples do we need? defaults to 48000. (one second).
-r, --rate
at what rate are we to sample? defaults to 48kHz.
-f, --file
do we want input from a file? if so, which one?

You can even generate from music notes directly with help of an M4 music.m4f, for example:

% echo 0.1 1 C4 E4 | m4 -R music.m4f -Q -
0.1 1 261.63 329.63

% echo 0.1 1 C4 E4 | m4 -R music.m4f -Q - |
awk '{$1 = $1*48000; print $0}'
4800 1 261.63 329.63

You can pipe it to wave command and it will play. There is a chopsticks.txt, which you can play:

% m4 -R music.m4f -Q chopsticks.txt |
awk '{$1 = $1*48000; print $0}' |
wave |
aplay -f FLOAT_LE -r 48000 -c 1 -q

One and a half years ago, I wrote a Bash function, beeps, it would somewhat emulate notification using dzen and audio files. The sound is now played using the following code:

for i in {1..5}; do
wave -s 4800 -a 0.75 $((100 * i))
wave -s 4800 -a 0.75 $((200 * i))
} | aplay -f FLOAT_LE -r 48000 -c 1 -q
sleep 0.1
done &

wave was born on 2013-07-07, in C99 and GNU m4 for music.m4f, by Erick Eduardo Ochoa Lopez, licensed under the MIT License.