Python(PyS60)实现简单语音整点报时
作者:softworm 发布时间:2023-07-06 03:05:23
标签:python,语音,整点报时
本文实例为大家分享了python语音整点报时的具体代码,供大家参考,具体内容如下
主要的技术特殊点在于PyS60的定时器最多只能定2147秒。在手机上直接写的。
import e32
import audio
import time
import appuifw
import sys
import os.path
import marshal
def say(oclock):
"""say the time in English"""
c = oclock
if c > 12:
c -= 12
cs = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'][c]
audio.say("it's " + cs + " o'clock.")
def say_current():
global Sayflags
t = time.localtime()
# say according to configuration
if Sayflags[int(t[3])] == 1:
say(t[3])
def on_oclock():
"""when an o'clock arrived"""
say_current()
start_timer()
def start_timer():
"""start a timer that will be reached at next o'clock"""
global Timer
lt = time.localtime()
d = 60 * (59 - lt[4]) + 61 - lt[5]
if d>2147:
Timer.after(2147, lambda : Timer.after(d-2147, on_oclock))
else:
Timer.after(d, on_oclock)
def clock_names():
return [u'0:00', u'1:00', u'2:00', u'3:00', u'4:00', u'5:00', u'6:00', u'7:00', u'8:00', u'9:00', u'10:00', u'11:00', u'12:00', u'13:00', u'14:00', u'15:00', u'16:00', u'17:00', u'18:00', u'19:00', u'20:00', u'21:00', u'22:00', u'23:00']
def list_handler():
"""set flag and refresh the listbox"""
global Lb
global Sayflags
c = Lb.current()
Sayflags[c] = 1 - Sayflags[c]
Lb.set_list(list_content(), c)
def list_content():
global Sayflags
icons = [appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif", 16506, 16507), appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif", 16504, 16505)] # unchecked, unchecked
return map(lambda s, f: tuple([s, icons[f]]), clock_names(), Sayflags)
def exit_handler():
global Lock
global Timer
global Standalone
Timer.cancel()
save_cfg()
if not Standalone:
Lock.signal()
else:
appuifw.app.set_exit()
def save_cfg():
global Sayflags
try:
f = open(Configfile, 'wb')
marshal.dump(Sayflags, f)
f.close()
except:
pass
def load_cfg():
global Sayflags
try:
f = open(Configfile, 'rb')
Sayflags = marshal.load(f)
f.close()
except:
pass
# Testing code
def test():
say_current()
#on_oclock()
#for n in range(1,13):
# say(n)
#test()
def main():
global Standalone
appuifw.app.title = u'Audio Clock'
appuifw.app.exit_key_handler = exit_handler
appuifw.app.body = Lb
if time.localtime()[4] == 0:
say_current()
start_timer()
if not Standalone:
Lock.wait()
Standalone = True
Timer = e32.Ao_timer()
Lock = e32.Ao_lock()
Configfile = os.path.abspath(os.path.dirname(sys.argv[0])) + '\\audioclock.cfg'
Sayflags = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1] #24 clocks' flags
load_cfg()
Lb = appuifw.Listbox(list_content(), list_handler)
main()
来源:https://blog.csdn.net/softworm/article/details/7727339


猜你喜欢
- 1. 问题描述:同目录下,当多个文件之间有相互依赖的关系的时候,import无法识别自己写的模块,PyCharm中提示No Module.2
- 在SQL中,很多威力都来自于将几个表或查询中的信息联接起来,并将结果显示为单个逻辑记录集的能力。在这种联接中包括INNER、LEFT、RIG
- 这周心血来潮,翻看了现在比较流行的几个JS脚本框架的底层代码,虽然是走马观花,但也受益良多,感叹先人们的伟大……感叹是为了缓解严肃的气氛并引
- 1. 简介本文将介绍 Go 语言中的 sync.Cond 并发原语,包括 sync.Cond的基本使用方法、实现原理、使用注意事项以及常见的
- 简单邮件传输协议(SMTP)是一种协议,用于在邮件服务器之间发送电子邮件和路由电子邮件。Python提供smtplib模块,该模块定义了一个
- 用 xlrd 模块读取 Excelxlrd 安装cmd 中输入pip install xlrd 即可安装 xlrd 模块若失败请自行百度”p
- 二维码作为一种信息传递的工具,在当今社会发挥了重要作用。从手机用户登录到手机支付,生活的各个角落都能看到二维码的存在。那你知道二维码是怎么解
- 本文导读:删除表中的数据的方法有delete,truncate, 其中TRUNCATE TABLE用于删除表中的所有行,而不记录单个行删除操
- 1.安装好JDK下载并安装好jdk-12.0.1_windows-x64_bin.exe,配置环境变量:新建系统变量JAVA_HOME,值为
- 一、UDP编程1.客户端Client:发起访问的一方。2.服务器端3.server段编程(1)建立socket,socket是负责具体通信的
- Python偏函数Python偏函数和我们之前所学习的函数传参中的缺省参数有些类似,但是在实际应用中还是有所区别的,下面通过模拟一个场景一步
- 概述基于Swoole的websocket服务,计划整合3篇进行技术整理,该服务主要有2个核心业务,用户消息服务(消息计数统计)和 客服IM消
- 本文实例讲述了Python列表推导式、字典推导式与集合推导式用法。分享给大家供大家参考,具体如下:推导式comprehensions(又称解
- 昨天用ucweb看到了goos发的一篇帖子:谁说Float菜单不可以水平居中,进去看了看,觉得方法有点繁琐了,用到了负边距,position
- 前言配置火狐浏览器对应的selenium驱动一、火狐浏览器驱动下载下载地址根据对应的系统环境下载相应的压缩包(这里下载的是Windows系统
- 本文实例讲述了Python实现按特定格式对文件进行读写的方法。分享给大家供大家参考,具体如下:#! /usr/bin/env python#
- 【人工智能项目】混合高斯模型运动目标检测本次工作主要对视频中运动中的人或物的边缘背景进行检测。那么走起来瓷!!!原视频高斯算法提取工作imp
- 译注:开发人员如何从无休止的需求、项目进度中摆脱烦躁的心态,这是每个人都值得思考的话题。无意间看见了这篇文章,恐于太长遂将其精简翻译,错误之
- 说明1:关于QWebEngineViewpyqt5 已经抛弃 QtWebKit和QtWebKitWidgets,而使用最新的QtWebEng
- SQL Server 2000安装问题集锦1、先把SQL Server卸载(卸载不掉也没有关系,继续下面的操作)2、把Microsoft S