Sound alarm when code finishes

I am in a situation where my code takes extremely long to run and I don't want to be staring at it all the time but want to know when it is done.

How can I make the (Python) code sort of sound an "alarm" when it is done? I was contemplating making it play a .wav file when it reaches the end of the code...

Is this even a feasible idea? If so, how could I do it?

On Windows

    import winsound
    duration = 1000  # millisecond
    freq = 440  # Hz
    winsound.Beep(freq, duration)

Where freq is the frequency in Hz and the duration is in milliseconds.

On Linux (and Mac)

    import os
    duration = 1  # second
    freq = 440  # Hz
    os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % (duration, freq))

In order to use this example, you must install sox.

On Debian/Ubuntu/LinuxMint you need to run in your terminal:

    sudo apt install sox

Here is the macports way of doing that...run this is your terminal:

    sudo port install sox

Speech on Mac

And something really cool if you're using a mac in terminal, maybe can do the same in windows, but I only know for sure for mac, this will tell you it's done:

    import os
    os.system('say "your program has finished"')

Speech on Linux

    import os
    os.system('spd-say "your program has finished"')

You need to install the speech-dispatcher package in Ubuntu (or the corresponding package on other distributions):

    sudo apt install speech-dispatcher

From: stackoverflow.com/q/16573051

Back to homepage or read more recommendations: