I tried to make a timer, here is my code
import time
timer = int(input("how long"))
s = 1
w = int(input("what is it"))
while s < w + 1:
print (s)
s = s + 1
time.sleep(10)
print ("your timer is done")
then sound loud beep`
I tried to make a timer, here is my code
import time
timer = int(input("how long"))
s = 1
w = int(input("what is it"))
while s < w + 1:
print (s)
s = s + 1
time.sleep(10)
print ("your timer is done")
then sound loud beep`
first install the library
pip3 install pyttsx3
then execute
python3 say_it_pyttsx3.py
cat say_it_pyttsx3.py
import pyttsx3 as pyttsx
what2Say = '\
your timer is done \
'
# Speaking engine
speakEngine = pyttsx.init()
speakEngine.say(what2Say)
speakEngine.runAndWait()
How to give out a beep depends greatly on your underlying system. You could try by simply print('\a')
which is supposed to do that.
Unfortunately, a lot of modern systems do not stick to that old rule. Then you could try to tweak your system to honor the "bell" character or you could try to give out a beep using a completely different method, e. g. by playing a small sound file.
How to do this again depends greatly on your operating system etc. You might want to tell us more about this.
On my Linux box, for instance, I use a commandline tool called play
(from package sox
) to play .wav
and .ogg
files, and mpg123
to play .mp3
files. From Python you can start them e. g. using this:
import subprocess
subprocess.call([
'play', '-q', '/usr/share/sounds/KDE-K3B-Finish-Success.ogg' ],
env={'AUDIODEV':'plughw:1,0'} )
This has similarly been answered here. In essence, you would need a third party library, but which you need depends on the type of sound you want to play, if you just want a basic beep or a supplied audio file, and multiple other factors, but they suggest Snack as a starting point. There is installation instructions on Snack's site and the linked answer suggests usage as simple as:
import snack
s = Sound()
s.read('sound.wav')
s.play()