Python(PyS60)实现简单语音整点报时
本文实例为大家分享了python语音整点报时的具体代码,供大家参考,具体内容如下
主要的技术特殊点在于PyS60的定时器最多只能定2147秒。在手机上直接写的。
importe32 importaudio importtime importappuifw importsys importos.path importmarshal defsay(oclock): """saythetimeinEnglish""" c=oclock ifc>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.") defsay_current(): globalSayflags t=time.localtime() #sayaccordingtoconfiguration ifSayflags[int(t[3])]==1: say(t[3]) defon_oclock(): """whenano'clockarrived""" say_current() start_timer() defstart_timer(): """startatimerthatwillbereachedatnexto'clock""" globalTimer lt=time.localtime() d=60*(59-lt[4])+61-lt[5] ifd>2147: Timer.after(2147,lambda:Timer.after(d-2147,on_oclock)) else: Timer.after(d,on_oclock) defclock_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'] deflist_handler(): """setflagandrefreshthelistbox""" globalLb globalSayflags c=Lb.current() Sayflags[c]=1-Sayflags[c] Lb.set_list(list_content(),c) deflist_content(): globalSayflags icons=[appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif",16506,16507),appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif",16504,16505)]#unchecked,unchecked returnmap(lambdas,f:tuple([s,icons[f]]),clock_names(),Sayflags) defexit_handler(): globalLock globalTimer globalStandalone Timer.cancel() save_cfg() ifnotStandalone: Lock.signal() else: appuifw.app.set_exit() defsave_cfg(): globalSayflags try: f=open(Configfile,'wb') marshal.dump(Sayflags,f) f.close() except: pass defload_cfg(): globalSayflags try: f=open(Configfile,'rb') Sayflags=marshal.load(f) f.close() except: pass #Testingcode deftest(): say_current() #on_oclock() #forninrange(1,13): #say(n) #test() defmain(): globalStandalone appuifw.app.title=u'AudioClock' appuifw.app.exit_key_handler=exit_handler appuifw.app.body=Lb iftime.localtime()[4]==0: say_current() start_timer() ifnotStandalone: 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]#24clocks'flags load_cfg() Lb=appuifw.Listbox(list_content(),list_handler) main()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。