On Windows
import winsound
duration = 1000 # milliseconds
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 # seconds
freq = 440 # Hz
os.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 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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…