Sound alarm when code finishes
On Windows
import winsoundduration = 1000 # millisecondsfreq = 440 # Hzwinsound.Beep(freq, duration)
Where freq is the frequency in Hz and the duration is in milliseconds.
On Linux and Mac
import osduration = 1 # secondsfreq = 440 # Hzos.system('play -nq -t alsa synth {} sine {}'.format(duration, freq))
In order to use this example, you must install sox
.
On Debian / Ubuntu / Linux Mint, run this in your terminal:
sudo apt install sox
On Mac, run this in your terminal (using macports):
sudo port install sox
Speech on Mac
import osos.system('say "your program has finished"')
Speech on Linux
import osos.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
This one seems to work on both Windows and Linux* (from this question):
def beep(): print("\a")beep()
In Windows, can put at the end:
import winsoundwinsound.Beep(500, 1000)where 500 is the frequency in Herz 1000 is the duration in miliseconds
To work on Linux, you may need to do the following (from QO's comment):
- in a terminal, type 'cd /etc/modprobe.d' then 'gksudo gedit blacklist.conf'
- comment the line that says 'blacklist pcspkr', then reboot
- check also that the terminal preferences has the 'Terminal Bell' checked.