python: Creating a ramen timer (pyttsx3, time)

Create a voice timer for cup ramen with python.

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.

table of contents

·code ·result

code

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")

result

スクリーンショット 2020-12-28 10.46.22.png 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

python: Creating a ramen timer (pyttsx3, time)
[Python] Creating a scraping tool Memo
Precautions when creating a Python generator
[Python] Chapter 03-01 turtle graphics (creating a turtle)
Creating a simple PowerPoint file with Python
Creating a python virtual environment on Windows
[Python] Creating a stock price drawdown chart
Python: Time Series Analysis: Building a SARIMA Model
First time python
Ubuntu18.04.05 Creating a python virtual environment in LTS
[Python3] A story stuck with time zone conversion
Procedure for creating a LineBot made with Python
python time measurement
A clever way to time processing in Python
A memo when creating a python environment with miniconda
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
A memo for creating a python environment by a beginner
[Grasshopper] When creating a data tree on Python script
Python: Creating a virtual environment (venv), starting and stopping
Notes on creating a python development environment on macOS Catalina
Problems when creating a csv-json conversion tool with python
Steps from installing Python 3 to creating a Django app
Created a Python library DateTimeRange that handles time ranges
Creating a list when the nomenclature is a fixed time
Python: Time Series Analysis
A * algorithm (Python edition)
[Python] Take a screenshot
[Day 9] Creating a model
Creating a Home screen
Function execution time (Python)
Create a Python module
4. Creating a structured program
python text aloud (pyttsx3)
A python lambda expression ...
Python time series question
Daemonize a Python process
Output python execution time
Time floor function (Python)
Create a Python environment
Creating a dataset loader
Python3> round (a --b, 7)
python get current time
Try creating a Deep Zoom file format .DZI in Python
Determine if a string is a time with a python regular expression
I made a package to filter time series with python
[Python] Create a date and time list for a specified period
Creating a Python script that supports the e-Stat API (ver.2)
[Python] What a programming inexperienced person did before creating a tool
Creating a GUI as easily as possible with python [tkinter edition]
A Python program that aggregates time usage from icalendar data