How to play a sound or tone when a program ends?

AFAIK R’s beep simply sends an \a to the terminal — see @anon94023334’s much simper solution for this above.

2 Likes

I’m pretty much good on this topic, jm’s “play_a_tune2” solution above worked; the only thing I can’t seem to do is set the filepath equal to a String variable, and then call it with play_a_tune2(variable); I have to call it with play_a_tune(<whole messy file path>). (But that’s not a big problem.)

Thanks everyone!

println("\007") doesn’t work for me on Ubuntu 18.04, but after:

sudo apt install beep
sudo modprobe pcspkr

the awesome power of beep is available, assuming that you have an old fashion motherboard speaker installed:

run(`beep -l 1000`)
1 Like

Most distros don’t enable the bell events on a desktop by default. Eg for PulseAudio something like PulseAudio - ArchWiki can be used to re-enable it.

On Linux, I would just call a command line player with a path.

There are Linux commands such as spd-say:

run(`spd-say 'Stay alert!'`)

Although using this is not advisable if you are afraid of robotic voices.

1 Like

Paul, Tamas, Zlatan, I am running Julia in atom in Windows 7 & Windows 10 on my 2 computers. I don’t know how to implement any of those last 3 suggestions in Windows.

I don’t use Windows so I can’t provide specific help, but I would just search for solutions playing audio from the command line on Windows, eg

https://stackoverflow.com/questions/1569765/how-to-play-audio-file-on-windows-from-command-line

I actually tried to say, that you can replace \$sound.Play\(\) by \$sound.PlayLooping\(\) as described in the link. It allows the file to be played in a loop.
The link is from the Powershell documentation from the here used SoundPlayer class. One can look it up for further and more complex usecases.

‘wavplay’ from WAV · Julia Packages worked fine for me.

using WAV
y, fs = wavread("foo.wav")

Anywhere in your program where you want to play the sound in the file foo.wav, just add the line.

wavplay(y, fs)

Also you can try Beep.jl (GitHub - arubhardwaj/Beep.jl: Notify me, Julia! I cannot remember after executing the script!!).

Linking related post.