I always judged the passage of time of cup ramen with my senses. I can eat it without any problems, but I made it as a study of programming because it was a big deal.
·code ·result
code
#Import required modules,Call pyttsx3
#pyttsx3 :Read aloud
#time :measurement of time
import pyttsx3
import time
engine = pyttsx3.init()
#start is the preparation start time (such as opening the lid)
#Setting to add hot water 20 seconds after start
#Voice announcement to add hot water after 20 seconds
start = time.time()
while True:
oyu_in = time.time()
if oyu_in-start >= 20:
print("Please add hot water")
engine.say('Please add hot water')
engine.runAndWait()
#Time to add hot water
oyu_wait = time.time()
break
#Waiting time after adding hot water
#Ramen is set when it is completed in 180 seconds (3 minutes)
#Voice announcement that you can eat after 180 seconds
while True:
#Time elapsed since the hot water was added
oyu_end = time.time()
if oyu_end-oyu_wait >= 180:
print("Can be eaten")
engine.say('Can be eaten')
engine.runAndWait()
break
#Voice announcement when there are 30 seconds left
elif oyu_end-oyu_wait == 150:
print(int(oyu_end-oyu_wait),"Seconds have passed")
engine.say('30 seconds left')
engine.runAndWait()
continue
#Displays the elapsed time in 10 second increments
elif (oyu_wait-oyu_end)%10 == 0:
print(int(oyu_end-oyu_wait),"Seconds have passed")
There were times when the elapsed time was not displayed at intervals of 30 seconds or 10 seconds due to problems such as PC processing. However, since 180 seconds have passed since [180> =], a voice announcement will always be issued.
Recommended Posts