def main(self, tok): bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() e = email() mail_host = 'smtp.qq.com' #这里默认qq邮箱,可以更改 mail_user = '' #邮箱账户 mail_pass = '' #邮箱密码 mail_port = '465' #与邮箱服务商相通 sender = '*****@*****.**' receivers = [] bt.tts('欢迎使用小蓝邮件助手,请问您有什么需要吗', tok) speaker.speak() speaker.ding() r.record() speaker.dong() commands = bs.stt('./voice.wav', tok) command = e.command_choose(commands, tok) if command == 'send': e.send(mail_host, mail_user, mail_pass, mail_port, sender, tok) else: bt.tts('对不起,我们还暂时不支持该功能', tok) speaker.speak()
def main(tok): bt = baidu_tts() host = 'https://api.seniverse.com/v3/weather/now.json?key=' key = 'sxyi6ehxblxkqeto' APIURL = key + '&location=ip&language=zh-Hans&unit=c' url = host + APIURL r = requests.get(url) json = r.json() print json weather = json['results'][0]['now']['text'] temperature = json['results'][0]['now']['temperature'] ran = random.randint(0, 4) if ran == 0: saytext = "今天," + weather + ",温度是," + temperature + ",摄氏度" elif ran == 1: saytext = "你猜啊!算了,告诉你吧:今天" + weather + ",温度大概是" + temperature + "摄氏度" elif ran == 2: saytext = "我生气了,不想告诉你。但是看在你这么可爱的份上,告诉你咯:今天" + weather + ",温度" + temperature + "摄氏度" elif ran == 3: saytext = "我是你的可爱小蓝,天气这就来:今天" + weather + ",温度" + temperature + "摄氏度" else: saytext = "今天" + weather + ",温度" + temperature + "摄氏度,天气天天都有,但如果我没有就恐怖了" bt.tts(saytext, tok) speaker.speak()
def study(self, tok): bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() h = hass() url = 'http://hassio.local' port = '8123' passwd = 'y20050801' headers = {'x-ha-access': passwd, 'content-type': 'application/json'} say = '该功能暂未开发完毕,sorry' bt.tts(say, tok) speaker.speak()
def start(text, token): """ 启动 :param text: 文本 :param token: token :return: """ r = recorder() bt = baidu_tts() bs = baidu_stt(1, 'a', 2, '{') song_list = ["冲鸭冲鸭.mp3", "招财进宝.mp3", "毒液前来.mp3", "跟着我一起.mp3"] ycy = "杨超越,1998年7月31日出生于江苏省盐城市,中国内地流行乐女歌手,女子演唱组合CH2、火箭少女101成员。 2017年,加入女子演唱组合CH2,从而正式出道,并签约了多家游戏平台,为高校电竞比赛做内容推广;同年,随CH2相继推出了《启航》、《听雪恋歌》等单曲。2018年,参加腾讯视频女团青春成长节目《创造101》,最终获得第3名,并加入女子演唱组合火箭少女101;8月18日,随火箭少女101推出组合首张EP专辑《撞》;9月23日,推出首支个人单曲《跟着我一起》;11月15日,推出第2支个人单曲《冲鸭冲鸭》;11月27日,推出第3支个人单曲《招财进宝》;12月15日,获得“影响中国”年度人物荣誉盛典年度演艺人物奖。2019年,她被评选为LikeTCCAsia亚太区最美100张面孔第3位、中国区最美100张面孔第1位呢!" bt.tts(ycy, token) speaker.speak() bt.tts("我这里还有杨超越姐姐唱的歌哦~要不要听一听呢?", token) speaker.speak() speaker.ding() r.record() speaker.dong() text = bs.stt("./voice.wav", token) if "不" in text: bt.tts("哦,那好吧~再见啦", token) speaker.speak() else: bt.tts("那你想要听什么呢?不知道的话,可以说随机哦~", token) speaker.speak() speaker.ding() r.record() speaker.dong() text = bs.stt("./voice.wav", token) if "随机" in text: speaker.play(song_list[random.randint(0, 4)]) else: kugou_request(text)
def sensor(self, getstatethings, tok): bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() h = hass() url = 'http://hassio.local' port = '8123' passwd = 'y20050801' headers = {'x-ha-access': passwd, 'content-type': 'application/json'} e_id = e_id() getstatesthings = unicode(getstatethings, "utf-8", "ignore") getstatesthings_eid = e_id[getstatesthings] getstatesthings_l = getstatesthings_eid.encode('utf-8') service = '/api/states' + getstatesthings_l r = requests.get(url + ':' + port + service, headers=headers) json = r.json() if cortolback.status_code == 200 or cortolback.status_code == 201: state = json['state'] if state == 'on': say = '此设备为开启状态' bt.tts(say, tok) speaker.speak() elif state == 'off': say = '此设备为关闭状态' bt.tts(say, tok) speaker.speak() elif state == 'below_horizon': say = '太阳已经下山了' bt.tts(say, tok) speaker.speak() else: if state.isdigit() == True: say = '数据是' + state bt.tts(say, tok) speaker.speak() else: sayback = '执行错误' bt.tts(sayback, tok) speaker.speak()
def main(tok): url = 'http://v.juhe.cn/joke/content/list.php' key = '21e780488098fa8b77394405421d8ae1' bt = baidu_tts() bs = baidu_stt(1, 'a', 2, '{') chose = random.randint(0, 9) r = requests.get(url + "key=" + key + "&page=10&pagesize=10&sort=asc&time=" + str(int(time.time()))) json = r.json() if chose == 0: saytext = json['result']["data"][0]['content'] elif chose == 1: saytext = json['result']["data"][1]['content'] elif chose == 2: saytext = json['result']["data"][2]['content'] elif chose == 3: saytext = json['result']["data"][3]['content'] elif chose == 4: saytext = json['result']["data"][4]['content'] elif chose == 5: saytext = json['result']["data"][5]['content'] elif chose == 6: saytext = json['result']["data"][6]['content'] elif chose == 7: saytext = json['result']["data"][7]['content'] elif chose == 8: saytext = json['result']["data"][8]['content'] elif chose == 9: saytext = json['result']["data"][9]['content'] else: saytext = json['result']["data"][0]['content'] bt.tts(saytext, tok) speaker.speak()
def send(self, mail_host, mail_user, mail_pass, mail_port, sender, tok): bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() e = email() receivers = [] bt.tts('请问您要给谁发送邮件呢?格式为,邮箱数字加邮箱服务商,如,一五二六七八九,QQ邮箱', tok) speaker.speak() speaker.ding() r.tsrecord() speaker.dong() receivers[0] = bs.stt('./voice.wav', tok) bt.tts('请问您要发送什么内容?', tok) speaker.speak() speaker.ding() r.tsrecord() speaker.dong() messages = bs.stt('./voice.wav', tok) message = MIMEText(messages, 'plain', 'utf-8') message['From'] = Header("小蓝邮件代发", 'utf-8') message['To'] = Header("You", 'utf-8') subject = '小蓝邮件代发' message['Subject'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, mail_port) smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) bt.tts('邮件发送成功', tok) speaker.speak() except smtplib.SMTPException: bt.tts('无法发送邮件', tok) speaker.speak()
def start(self, tok): #判断 bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() h = hass() welcome = '欢迎使用小蓝专用智能家居控制系统!请在,滴,一声之后说出指令' bt.tts(welcome, tok) speaker.speak() speaker.ding() r.record() speaker.dong() text = bs.stt('./voice.wav', tok) while text == None: sorry = '对不起,我没有听清楚,请重复一遍' bt.tts(sorry, tok) speaker.speak() speaker.ding() r.record() speaker.speak() text = bs.stt('./voice.wav', tok) if text != None: break texts = str.encode(encoding='UTF-8', errors='strict') if '打开' in text: cortolthings = texts[6:-2] cortolmode = 'turn_on' h.cortol(cortolthings, cortolmode, tok) elif '关闭' in text: cortolthings = texts[6:-2] cortolmode = 'turn_off' h.cortol(cortolthings, cortolmode, tok) elif '查看' in text: if '传感器' in text: getstatethings = texts[6:-5] getmode = 'sensor' h.sensor(getstatethings, tok) if '红外' in text: if '学习' in text: h.study(tok) else: h.usuallycortol(text, tok)
def main(tok): r = recorder() bt = baidu_tts() url = 'https://snowboy.kitt.ai/api/v1/train/' apikey = '78ee816d9bfc8fb0e01341d4408e3f23fbbc9b03' askf = '第一次训练录音开始,请在滴一声之后说出,blueberry' asks = '第二次训练录音开始,请在滴一声之后说出,blueberry' askt = '第三次训练录音开始,请在滴一声之后说出,blueberry' bt.tts(askf, tok) speaker.speak() speaker.ding() r.train_f_record() speaker.dong() bt.tts(asks, tok) speaker.speak() speaker.ding() r.train_s_record() speaker.dong() bt.tts(askt, tok) speaker.speak() speaker.ding() r.train_t_record() speaker.dong() wav1 = "/home/pi/old_xiaolan/old_xiaolan/train_f.wav" wav2 = "/home/pi/old_xiaolan/old_xiaolan/train_s.wav" wav3 = "/home/pi/old_xiaolan/old_xiaolan/train_t.wav" out = "/home/pi/old_xiaolan/old_xiaolan/snowboy/blueberry.pmdl" data = { "name": hotword_name, "language": language, "age_group": age_group, "gender": gender, "microphone": microphone, "token": token, "voice_samples": [{ "wave": get_wave(wav1) }, { "wave": get_wave(wav2) }, { "wave": get_wave(wav3) }] } response = requests.post(endpoint, json=data) if response.ok: with open(out, "w") as outfile: outfile.write(response.content) print "Saved model to '%s'." % out trueback = "Saved model to '%s'." % out bt.tts(tureback, tok) speaker.speak() else: print "Request failed." print response.text
def cortol(self, cortolthings, cortolmode, tok): #智能家居中的灯、开关控制于此(支持一句话插件) bt = baidu_tts() bs = baidu_stt(1, 2, 3, 4) r = recorder() h = hass() url = 'http://hassio.local' port = '8123' passwd = 'y20050801' headers = {'x-ha-access': passwd, 'content-type': 'application/json'} domains = h.service() e_id = h.e_id() cortolthings = unicode(cortolthings, "utf-8", "ignore") try: if cortolmode == 'turn_on': if e_id[cortolthings] != None: if 'switch' in e_id[cortolthings]: color_name = 'a' service = '/api/services/switch/turn_on' elif 'light' in e_id[cortolthings]: ask = '请问要设置什么颜色,可以忽略' bt.tts(ask, tok) speaker.speak() speaker.ding() r.record() speaker.dong() color_name_f = bs.stt('./voice.wav', tok) if color_name_f != None: color_name = h.chosecolor(color_name_f) else: color_name = 'a' service = '/api/services/light/turn_on' elif 'automation' in e_id[cortolthings]: color_name = 'a' service = '/api/services/automation/turn_on' elif cortolmode == 'turn_off': if e_id[cortolthings] != None: if 'switch' in e_id[cortolthings]: color_name = 'a' service = '/api/services/switch/turn_off' elif 'light' in e_id[cortolthings]: color_name = 'a' service = '/api/services/light/turn_off' elif 'automation' in e_id[cortolthings]: color_name = 'a' service = '/api/services/automation/turn_off' except KeyError: sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样' bt.tts(sorry, tok) speaker.speak() except TypeError: sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样' bt.tts(sorry, tok) speaker.speak() except ValueError: sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样' bt.tts(sorry, tok) speaker.speak() else: pass try: cortole_id = e_id[cortolthings] if color_name == 'a': dataf = {"entity_id": cortole_id.encode('utf-8')} data = json.dumps(dataf) else: dataf = { "color_name": color_name, "entity_id": cortole_id.encode('utf-8') } data = json.dumps(dataf) except KeyError: sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样' bt.tts(sorry, tok) speaker.speak() except TypeError: sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样' bt.tts(sorry, tok) speaker.speak() except ValueError: sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样' bt.tts(sorry, tok) speaker.speak() else: print data cortolback = requests.post(url + ':' + port + service, headers=headers, data=data) if cortolback.status_code == 200 or cortolback.status_code == 201: sayback = '执行成功' bt.tts(sayback, tok) speaker.speak() else: sayback = '执行错误' bt.tts(sayback, tok) speaker.speak()
cursor.execute(sql) conn.commit() #主控包含传感器、蜂鸣器 class sth(object): sensor = Adafruit_DHT.DHT11 @property def sensor(self): return self.sensor def __init__(self): #初始化mode os.system('gpio -g mode %s out' % gpio.pdht11.value) os.system('gpio -g mode %s out' % gpio.pmq2.value) os.system('gpio -g mode %s out' % gpio.pbuzzer.value) #蜂鸣器 def buzzer(self): os.system('gpio -g write %s 1' % gpio.pbuzzer.value) time.sleep(0.5) os.system('gpio -g write %s 0' % gpio.pbuzzer.value) #读取dth11温度 def readDth(self): bt = baidu_tts() bs = baidu_stt(1, 'a', '{', 3) humidity,temperature = Adafruit_DHT.read_retry(self.sensor,gpio.pdht11.value) if humidity is not None and temperature is not None: saytext = '湿度是,' + humidity + '温度是' + temperature tok = bt.get_token() bt.tts(saytext, tok) speaker.speak()
def main(tok): APPKEY = 'b8fff66168feb233d5cdb2f7931750f3' url = 'http://v.juhe.cn/toutiao/index?type=' r = recorder() bt = baidu_tts() bs = baidu_stt(1, 'a', 2, '{') newsserviceasktext = '请问您要听什么新闻?' bt.tts(newsserviceasktext, tok) speaker.speak() speaker.ding() r.record() speaker.dong() text = bs.stt('./voice.wav', tok) chose = random.randint(0, 9) if '国内新闻' in text: newsservice = 'chinanews' elif '国际新闻' in text: newsservice = 'nationnews' elif '科技新闻' in text: newsservice = 'kejinews' elif '体育新闻' in text: newsservice = 'tiyunews' else: newsservice = 't' if newsservice == 'chinanews': newstype = 'guonei' r = requests.post(url + newstype + '&key=' + APPKEY) json = r.json() if chose == 0: saytext = json['result']['data'][0]['title'] elif chose == 1: saytext = json['result']['data'][1]['title'] elif chose == 2: saytext = json['result']['data'][2]['title'] elif chose == 3: saytext = json['result']['data'][3]['title'] elif chose == 4: saytext = json['result']['data'][4]['title'] elif chose == 5: saytext = json['result']['data'][5]['title'] elif chose == 6: saytext = json['result']['data'][6]['title'] elif chose == 7: saytext = json['result']['data'][7]['title'] elif chose == 8: saytext = json['result']['data'][8]['title'] elif chose == 9: saytext = json['result']['data'][9]['title'] else: saytext = json['result']['data'][0]['title'] bt.tts(saytext, tok) speaker.speak() elif newsservice == 'nationnews': newstype = 'guoji' r = requests.post(url + newstype + '&key=' + APPKEY) json = r.json() if chose == 0: saytext = json['result']['data'][0]['title'] elif chose == 1: saytext = json['result']['data'][1]['title'] elif chose == 2: saytext = json['result']['data'][2]['title'] elif chose == 3: saytext = json['result']['data'][3]['title'] elif chose == 4: saytext = json['result']['data'][4]['title'] elif chose == 5: saytext = json['result']['data'][5]['title'] elif chose == 6: saytext = json['result']['data'][6]['title'] elif chose == 7: saytext = json['result']['data'][7]['title'] elif chose == 8: saytext = json['result']['data'][8]['title'] elif chose == 9: saytext = json['result']['data'][9]['title'] else: saytext = json['result']['data'][0]['title'] bt.tts(saytext, tok) speaker.speak() elif newsservice == 'kejinews': newstype = 'keji' r = requests.post(url + newstype + '&key=' + APPKEY) json = r.json() if chose == 0: saytext = json['result']['data'][0]['title'] elif chose == 1: saytext = json['result']['data'][1]['title'] elif chose == 2: saytext = json['result']['data'][2]['title'] elif chose == 3: saytext = json['result']['data'][3]['title'] elif chose == 4: saytext = json['result']['data'][4]['title'] elif chose == 5: saytext = json['result']['data'][5]['title'] elif chose == 6: saytext = json['result']['data'][6]['title'] elif chose == 7: saytext = json['result']['data'][7]['title'] elif chose == 8: saytext = json['result']['data'][8]['title'] elif chose == 9: saytext = json['result']['data'][9]['title'] else: saytext = json['result']['data'][0]['title'] elif newsservice == 'tiyunews': newstype = 'tiyu' r = requests.post(url + newstype + '&key=' + APPKEY) json = r.json() if chose == 0: saytext = json['result']['data'][0]['title'] elif chose == 1: saytext = json['result']['data'][1]['title'] elif chose == 2: saytext = json['result']['data'][2]['title'] elif chose == 3: saytext = json['result']['data'][3]['title'] elif chose == 4: saytext = json['result']['data'][4]['title'] elif chose == 5: saytext = json['result']['data'][5]['title'] elif chose == 6: saytext = json['result']['data'][6]['title'] elif chose == 7: saytext = json['result']['data'][7]['title'] elif chose == 8: saytext = json['result']['data'][8]['title'] elif chose == 9: saytext = json['result']['data'][9]['title'] else: saytext = json['result']['data'][0]['title'] else: newstype = 'top' r = requests.post(url + newstype + '&key=' + APPKEY) json = r.json() if chose == 0: saytext = json['result'][0]['title'] elif chose == 1: saytext = json['result'][1]['title'] elif chose == 2: saytext = json['result'][2]['title'] elif chose == 3: saytext = json['result'][3]['title'] elif chose == 4: saytext = json['result'][4]['title'] elif chose == 5: saytext = json['result'][5]['title'] elif chose == 6: saytext = json['result'][6]['title'] elif chose == 7: saytext = json['result'][7]['title'] elif chose == 8: saytext = json['result'][8]['title'] elif chose == 9: saytext = json['result'][9]['title'] else: saytext = json['result'][0]['title'] bt.tts(saytext, tok) speaker.speak()