树莓派python报时脚本

发布时间:2021-06-27 14:19:38 阅读:1238次

早上喜欢睡懒觉,用手机定时总是不小心关了,

于是用树莓派折腾

可以放歌,准点报表,设置crontab每5分钟报时一次

以下为脚本

  1 #_*_ coding:UTF-8 _*_
  2 from aip import AipSpeech
  3 import pyaudio
  4 import wave
  5 import os
  6 import time
  7 APP_ID = '11062810'
  8 API_KEY = 'dBE***9Ec'
  9 SECRET_KEY = 'bWj***U4r'
 10 #datetime = time.strftime("%Y%m%d%H%M%S", time.localtime())
 11 #print datetime
 12 hour = time.strftime("%H", time.localtime())
 13 hour = int(hour)
 14 if hour>12:
 15  hour=hour-12
 16 minute = time.strftime("%M", time.localtime())
 17 min = minute+"分"
 18 if int(minute) == 30:
 19   min = "半"
 20 if minute == '00':
 21   min = "整"
 22 content = str(hour)+"点"+min
 23 print content
 24 #exit(0)
 25 check = os.path.exists(content+".mp3")
 26 if check == False:
 27   client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
 28   result  = client.synthesis(content, 'zh', 1, {
 29       'vol': 5,
 30   })
 31   # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
 32   if not isinstance(result, dict):
 33       with open("/tmp/"+content+'.mp3', 'wb') as f:
 34           f.write(result)
 35   os.system('mpg123 /mnt/shell/highway.mp3')
 36   os.system('mpg123 /tmp/'+content+'.mp3')
 37 else:
 38   print "ok"
 39   os.system('mpg123 /mnt/shell/highway.mp3')
 40 #  os.system('mpg123 /tmp/'+content+'.mp3')

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:树莓派python报时脚本 出自老鄢博客 | 欢迎分享