Python(PyS60)實(shí)現(xiàn)簡(jiǎn)單語(yǔ)音整點(diǎn)報(bào)時(shí)
本文實(shí)例為大家分享了python語(yǔ)音整點(diǎn)報(bào)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下
主要的技術(shù)特殊點(diǎn)在于PyS60的定時(shí)器最多只能定2147秒。在手機(jī)上直接寫(xiě)的。
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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python3實(shí)現(xiàn)語(yǔ)音轉(zhuǎn)文字(語(yǔ)音識(shí)別)和文字轉(zhuǎn)語(yǔ)音(語(yǔ)音合成)
- python語(yǔ)音識(shí)別指南終極版(有這一篇足矣)
- 使用Python和百度語(yǔ)音識(shí)別生成視頻字幕的實(shí)現(xiàn)
- 基于python實(shí)現(xiàn)語(yǔ)音錄入識(shí)別代碼實(shí)例
- Python譜減法語(yǔ)音降噪實(shí)例
- python實(shí)現(xiàn)智能語(yǔ)音天氣預(yù)報(bào)
- python文字轉(zhuǎn)語(yǔ)音實(shí)現(xiàn)過(guò)程解析
- 使用python實(shí)現(xiàn)語(yǔ)音文件的特征提取方法
- 分析語(yǔ)音數(shù)據(jù)增強(qiáng)及python實(shí)現(xiàn)
相關(guān)文章
python正則實(shí)現(xiàn)計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了python正則實(shí)現(xiàn)計(jì)算器功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
python實(shí)現(xiàn)同級(jí)目錄調(diào)用的示例詳解
同級(jí)目錄指的是位于同一級(jí)別的文件夾,這些文件夾具有相同的層級(jí)結(jié)構(gòu),它們相互平行,沒(méi)有一個(gè)被包含在另一個(gè)之中,本文將給大家介紹python實(shí)現(xiàn)同級(jí)目錄調(diào)用的示例,需要的朋友可以參考下2024-06-06
python中__init__方法知識(shí)點(diǎn)詳解
Python中常會(huì)看到在很多類(lèi)中都有一個(gè)__init__函數(shù),該函數(shù)有什么作用,又該如何使用呢,下面這篇文章主要給大家介紹了關(guān)于python中__init__知識(shí)點(diǎn)的相關(guān)資料,需要的朋友可以參考下2023-04-04
django 快速啟動(dòng)數(shù)據(jù)庫(kù)客戶(hù)端程序的方法示例
這篇文章主要介紹了django 快速啟動(dòng)數(shù)據(jù)庫(kù)客戶(hù)端程序的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python GUI編程之tkinter 關(guān)于 ttkbootstrap 的使用
ttkbootstrap 是一個(gè)基于 tkinter 的界面美化庫(kù),使用這個(gè)工具可以開(kāi)發(fā)出類(lèi)似前端 bootstrap 風(fēng)格的 tkinter 桌面程序,這篇文章主要介紹了Python GUI編程之tkinter 關(guān)于 ttkbootstrap 的使用詳解,需要的朋友可以參考下2022-03-03

