The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a cooking timer with voice alerts

Creating a cooking timer with voice alerts can be done using a programming language like Python, which has libraries for handling time and speech synthesis. Below is an example code using time for timing and pyttsx3 for voice alerts:

Prerequisites:

  1. Install the necessary libraries:

    • pyttsx3 for text-to-speech functionality.

    • time for timing functionality (this is built-in with Python).

You can install pyttsx3 using pip:

bash
pip install pyttsx3

Code:

python
import time import pyttsx3 # Initialize the pyttsx3 engine for voice engine = pyttsx3.init() # Function to set the timer def cooking_timer(seconds): print(f"Timer set for {seconds} seconds.") # Start the countdown while seconds > 0: mins, secs = divmod(seconds, 60) time_format = f"{mins:02d}:{secs:02d}" print(time_format, end="r") # Print countdown on the same line time.sleep(1) seconds -= 1 # Alert when the time is up print("nTime's up!") engine.say("Time's up! Your cooking timer has finished.") engine.runAndWait() # Main program if __name__ == "__main__": try: # Ask the user for the time in minutes minutes = int(input("Enter the cooking time in minutes: ")) seconds = minutes * 60 cooking_timer(seconds) except ValueError: print("Please enter a valid number!")

How it works:

  1. Time Input: The user is prompted to enter the cooking time in minutes.

  2. Countdown: The program counts down from the set time, displaying the remaining time in MM:SS format.

  3. Voice Alert: Once the timer reaches zero, a voice alert says, “Time’s up! Your cooking timer has finished.”

Steps to Run:

  1. Copy the code into a Python script file (e.g., cooking_timer.py).

  2. Run the script.

  3. Enter the cooking time in minutes when prompted.

  4. Wait for the timer to finish, and hear the voice alert!

Customization:

  • You can change the voice settings of the pyttsx3 engine (e.g., speed, pitch, or even the voice) by tweaking engine.setProperty() functions.

Let me know if you need any further customizations or if you’re interested in running it on a specific platform!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About