借助datetime和pyttsx3在Python中创建闹钟

Modules used:

使用的模块:

To create this script, we will use 3 modules:

要创建此脚本,我们将使用3个模块:

  • datetime

    约会时间

  • time

    时间

  • pyttsx3

    pyttsx3

datetime module: datetime is an inbuilt python module which will help us to provide some function which will deal with the date and time, we will use this module just to get the actual standard time.

datetime模块 :datetime是一个内置的python模块,它将帮助我们提供一些处理日期和时间的功能,我们将使用该模块来获取实际的标准时间。

time module: time is an inbuilt python module that provides us with various time-related functions and we are using this module just to sleep the program for 1 second.

time模块 :time是一个内置的python模块,它为我们提供了各种与时间相关的功能,我们正在使用此模块将程序Hibernate1秒钟。

pyttsx3: pyttsx3 is a python module that will help us to convert the input text into speech.

pyttsx3 :pyttsx3是一个python模块,它将帮助我们将输入文本转换为语音。

We can install in 2 ways:

我们可以通过两种方式安装:

  • Using the command:

    使用命令:

    pip install pyttsx3
    
    
  • Pycharm users: Go to the project interpreter and install this module from there

    Pycharm用户:转到项目解释器并从那里安装此模块

Note: This alarming interface is based on 24 hours clock format.

注意:此警报界面基于24小时时钟格式。

How we will do this?

我们将如何做到这一点?

We have to use a loop for this interface.

我们必须为此接口使用循环。

We will use the datetime module to get the actual standard time.

我们将使用datetime模块获取实际的标准时间。

Now if the users time matched with the standard time then we have to alarm the user, for this, we will use the pyttsx3 module inside an if condition statement and we will apply the various function of pyttsx3 inside the if condition.

现在,如果用户时间与标准时间匹配,那么我们必须警告用户,为此,我们将在if条件语句中使用pyttsx3模块,并在if条件中应用pyttsx3的各种功能。

Now the function that we will in the script are:

现在,我们将在脚本中使用的功能是:

  • datetime.datetime.now(): This will give us the exact date and standard time.

    datetime.datetime.now() :这将为我们提供确切的日期和标准时间。

  • datetime.datetime.now().strftime("%H:%M"): Here we only work with time, to get the time we will use this function.

    datetime.datetime.now()。strftime(“%H:%M”) :在这里,我们仅使用时间,以获取使用此功能的时间。

  • time.sleep(1): we have to run a loop in every second so we will stop the functioning of the program.

    time.sleep(1) :我们必须每秒运行一次循环,以便我们停止程序的运行。

Regarding the pyttsx3:

关于pyttsx3

When the standard time matches with the users time then we have to alarm the user with the help of pyttsx3, the functions that we will use are:

当标准时间与用户时间匹配时,我们必须在pyttsx3的帮助下警告用户,我们将使用的功能是:

  • pyttsx3.init():This function will create a engine and all the other function

    pyttsx3.init() :此函数将创建一个引擎以及所有其他函数

  • engine.say(): This function will convert the text to speech.

    engine.say() :此函数会将文本转换为语音。

  • engine.runAndWait(): This will make the speech audible.

    engine.runAndWait() :这将使语音可听。

Program:

程序:

# import libraries(datetime,time,pyttsx3)
import time,pyttsx3
from datetime import datetime
print("Hello, welcome to my alarming interface...")
print("It is based on 24 hours clock format...")
Name = input("Enter your name: ")
# printing the current time 
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time is: ", current_time)
# Enter the time(Hours and minute)
Time=input("Enter the time (HH24:MM): ")
# starting the loop
while True:
# Getting the standard time with the
# help of datetime module
Standard_time=datetime.now().strftime("%H:%M")
# sleep the program for about 1 sec
time.sleep(1)
# if condition to check wether the input 
# time has matched or not
if Time==Standard_time:
count=0
while count<=10:
count=count+1
# creating a engine for voice mode
engine=pyttsx3.init()
# setting the voice
engine.say("Wake up"+Name)
engine.runAndWait()
print("Thankyou For using the Interface")
break

Output:

输出:

Hello, welcome to my alarming interface...
It is based on 24 hours clock format...
Enter your name: Abhinav
Current Time is:  00:33:38
Enter the time (HH24:MM): 00:35

This is the way we can create an Alarming clock script in python.

这是我们可以在python中创建Alarming Clock脚本的方法。

翻译自: https://www.includehelp.com/python/alarm-clock-in-python-with-the-help-of-datetime-and-pyttsx3.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545875.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ie6 javascript js 缺少标识符总结(转载)

转载http://blog.csdn.net/qingyundys/article/details/6218280 ie6 javascript js 缺少标识符总结1. ie6下&#xff0c;javascript代码中&#xff0c;不能出现保留字符。解决办法就是避免直接使用JS的保留字符。2. IE和Firefox不兼容的地方.属性之间是要用","分隔的…

Unsigned 陷阱

unsigned是整形的一种类型&#xff0c;表示无符号&#xff0c;一般用于unsigned int和unsigned char&#xff0c;如果没有理解unsigned的意义将会在做题中掉入陷阱&#xff0c;下面通过介绍几个例子来说明&#xff1a; 1、 int main() {unsigned int i;for (i 10;i > 0;…

URL 去重的 6 种方案!(附详细代码)

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;URL 去重在我们日常工作中和面试中很常遇到&#xff0c;比如这些&#xff1a;可以看出&#xff0c;包括阿里&#xff0c;网易…

深入了解INF

大家都知道&#xff0c;在“我的电脑”里有数也数不清的INF文件&#xff0c;但是却很少有人知道&#xff0c;INF文件是干什么用的。充其量&#xff0c;也仅仅停留在INF文件能够解开锁定的注册表这一感性的认识上&#xff0c;那么到底什么是INF文件&#xff0c;INF文件又能干些什…

Java字符串indexOf(int ch,int fromIndex)方法,带示例

字符串indexOf(int ch&#xff0c;int fromIndex)方法 (String indexOf(int ch, int fromIndex) Method) indexOf(int ch, int fromIndex) is a String method in Java and it is used to get the index of a specified character in the string from given fromIndex. That me…

阿里巴巴为什么禁止使用Apache Beanutils进行属性复制?

作者 l Hollis来源 l Hollis&#xff08;ID&#xff1a;hollischuang&#xff09;在日常开发中&#xff0c;我们经常需要给对象进行赋值&#xff0c;通常会调用其set/get方法&#xff0c;有些时候&#xff0c;如果我们要转换的两个对象之间属性大致相同&#xff0c;会考虑使用属…

台达A2-M伺服

地址: P3.00 从站地址0x01~0x7F【1~127】 P3.01 通讯速度UZYX【0403】 X:0【4800】1【9600】2【19200】3【38400】4【57600】5【115200】Z:0【125Kbit/s】1【250】2【500】3【750】4【1Mbit/s】 P3.02 通讯格式6【8N2】7【8E1】8【8O1】 P3.03 1通讯错误刹停…

关于数组首地址a、a+1、a[0]、a[0]+1、*a、*a、a+0的解析

有一个数组&#xff1a; int a[4]{1,2,3,4};例如&#xff0c;sizeof(a),很明显它的结果是16&#xff0c;这个a就表示的是整个数组的大小&#xff0c;那么有 a1: 表示数组a的第二个元素即a[1]的地址 a0&#xff1a; a[0]的地址 &a[0]: a[0]的地址 &a[0…

Intent, Bundle, ListView的简单使用

Intent, Bundle, ListView的使用 无参数的Activity跳转&#xff1a; intent.setClass(MainActivity.this, InformationActivity.class); startActivity(intent);当前Activity A 向下一个Activity B跳转并传递数据&#xff1a; Bundle bundle new Bundle(); bundle.putString(…

vb随机显示图片

根目录下建一个文件夹PIC&#xff0c;在PIC下存放5张图片&#xff0c;名称分虽是1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5然后添加一个timer1控件&#xff0c;一个image1控件&#xff0c;它的interval设5000&#xff08;即5秒&#xff09;写如下代码Private Sub…

正则数字字母下划线至少两种_8085微处理器中至少两个8位数字

正则数字字母下划线至少两种Problem statement: 问题陈述&#xff1a; To find minimum of two 8bit numberusing 8085 microprocessor. 使用8085微处理器查找最少两个8位数字。 Algorithm: 算法&#xff1a; Load the accumulator with the first data. 向累加器加载第一个…

字符串操作的12个小技巧!

字符串可以说是 Java 中最具有代表性的类了&#xff0c;似乎没有之一哈&#xff0c;这就好像直播界的李佳琪&#xff0c;脱口秀中的李诞&#xff0c;一等一的大哥地位。不得不承认&#xff0c;最近吐槽大会刷多了&#xff0c;脑子里全是那些段子&#xff0c;写文章都有点不由自…

关于二维数组取地址加以或减一解引用问题

int main() { int aa[2][5] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int *ptr1 (int *)(&aa 1); int *ptr2 (int *)(*(aa 1)); printf("%d,%d", *(ptr1 - 1), *(ptr2 - 1));system("pause");return 0; }很显然aa是一个二维数组&#xff0c;很多…

rand和srand的用法

首先我们要对rand&#xff06;srand有个总体的看法:srand初始化随机种子,rand产生随机数&#xff0c;下面将详细说明。rand&#xff08;产生随机数&#xff09;表头文件: #include定义函数 :int rand(void)函数说明 :因为rand的内部实现是用线性同余法做的&#xff0c;他不是真…

repeating 路由_CSS中带有示例的repeating-linear-gradient()函数

repeating 路由Introduction: 介绍&#xff1a; So far, we have learned so many functions but learning never gets enough, therefore as a good developer, we must learn as many functions as we can and know their behavior with the help of practical implementati…

万字详解|手撕 9大排序算法!

0. 前言大家好&#xff0c;我是多选参数的程序锅&#xff0c;一个正在捣鼓操作系统、学数据结构和算法以及 Java 的失业人员。数据结构和算法我已经学了有一段日子了&#xff0c;最近也开始在刷 LeetCode 上面的题目了&#xff0c;但是自己感觉在算法上还是 0 &#xff0c;还得…

INF文件修改注册表

INF是一个用于安装驱动程序的文件&#xff0c;是文本格式的。里面记录着驱动程序的所有相关资料&#xff0c;随便打开一个INF文件度可看到很多奇奇怪怪的东西&#xff0c;其实这一点也不奇怪&#xff0c;因为每一项都有特定的含义&#xff0c;比如从VERSION一项就可以看出支持的…

.Net判断一个对象是否为数值类型探讨总结(高营养含量,含最终代码及跑分)...

前一篇发出来后引发了积极的探讨&#xff0c;起到了抛砖引玉效果&#xff0c;感谢大家参与。 吐槽一下&#xff1a;这个问题比其看起来要难得多得多啊。 大家的讨论最终还是没有一个完全正确的答案&#xff0c;不过我根据讨论结果总结了一个差不多算是最终版的代码&#xff0c;…

ai怎么约束每个字的大小_人工智能的约束满意问题

ai怎么约束每个字的大小Constraint Satisfactory problems, as the name suggests are the problems which have some constraints which need to be satisfied while solving any problem. In simpler words, we can say that while solving any problem or changing any stat…

一个多月的时间,终于把这件事做完了!

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;关注我的小伙伴都知道&#xff0c;前段时间磊哥搞了一个免费的模拟面试&#xff0c;但因为工作和&#xff08;面试&#xff…