Python(PyS60)实现简单语音整点报时
作者:softworm 时间:2023-07-06 03:05:23
本文实例为大家分享了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
标签:python,语音,整点报时
0
投稿
猜你喜欢
按钮的反馈
2009-01-01 20:06:00
python 字典常用方法超详细梳理总结
2023-06-29 05:48:40
vue具名插槽的基本使用实例
2024-04-27 15:51:16
Python中使用语句导入模块或包的机制研究
2023-02-21 15:06:40
详解MySQL中concat函数的用法(连接字符串)
2024-01-18 09:30:56
MAC版修改MySQL初始密码的方法
2024-01-19 03:19:56
Mysql5.7中使用group concat函数数据被截断的问题完美解决方法
2024-01-18 02:00:39
Python 对象序列化与反序列化之pickle json详细解析
2021-09-06 23:44:06
AI:如何训练机器学习的模型
2023-01-16 13:18:49
一次现场mysql重复记录数据的排查处理实战记录
2024-01-17 11:42:28
浅谈如何使用webpack构建多页面应用
2024-04-16 09:27:13
解决安装pycharm后不能执行python脚本的问题
2023-07-25 06:51:04
浅谈JavaScript函数参数的可修改性问题
2024-05-02 17:20:29
python sklearn包——混淆矩阵、分类报告等自动生成方式
2022-05-29 12:19:27
Python Numpy 自然数填充数组的实现
2023-12-18 16:51:37
《JavaScript DOM 编程艺术》读书笔记之JavaScript 简史
2024-04-10 16:13:23
python操作日期和时间的方法
2021-08-29 18:32:59
Pygame Transform图像变形的实现示例
2022-03-04 03:39:29
joomla组件开发入门教程
2024-05-05 09:18:46
Django 权限认证(根据不同的用户,设置不同的显示和访问权限)
2023-09-18 04:07:30