-
Notifications
You must be signed in to change notification settings - Fork 0
/
voice_weather.py
43 lines (30 loc) · 1.04 KB
/
voice_weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# coding: utf-8
import os
import sys
import json
import datetime
reload(sys)
sys.setdefaultencoding('utf-8')
home_air_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'home_air.json')
weather_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'weather.json')
hadata = {}
wdata = {}
data = {}
try:
with open(home_air_file, 'r') as in_file:
hadata = json.load(in_file)
except IOError:
pass
try:
with open(weather_file, 'r') as in_file:
wdata = json.load(in_file)
except IOError:
pass
data = dict(hadata,**wdata)
time_now = datetime.datetime.now()
time_string = time_now.strftime('%H:%M')
text= '现在'+time_string+',当前室内温度{temp}度,室内湿度{humidity}度.明天{tomorrow_weather},最高温度{tomorrow_temp_hig}度,最低温度{tomorrow_temp_low}度'.format(**data)
url = u'http://tts.baidu.com/text2audio?idx=1&tex={0}&cuid=baidu_speech_' \
u'demo&cod=2&lan=zh&ctp=1&pdt=1&spd=4&per=4&vol=5&pit=5'.format(text)
os.system('mplayer "%s"' % url)