diff --git a/jiqiren.py b/jiqiren.py new file mode 100644 index 0000000..6a1fd29 --- /dev/null +++ b/jiqiren.py @@ -0,0 +1,201 @@ +import random + +import pyttsx3 +import requests +import yuyin as yy +import urllib +import renlian as rl +import wenshidu as wsd +import mensuo as ms +import MySQL as m +import time +import lighting as l +string_01 = ['01。','02。','03。','04。','05。','06。','07。','08。','09。','10。','11。','12。','13。','14。'] + +class RobotSay(): + + def __init__(self): + # 初始化语音 + self.engine = pyttsx3.init() # 初始化语音库 + + # 设置语速 + self.rate = self.engine.getProperty('rate') + self.engine.setProperty('rate', self.rate - 20) + self.engine.setProperty('voice', 'zh+f2') + + def say(self, msg): + # 输出语音 + self.engine.say(msg) # 合成语音 + self.engine.runAndWait() + + +robotSay = RobotSay() + + + +def talkWithRobot(msg): + url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg={}'.format(urllib.parse.quote(msg)) + html = requests.get(url) + return html.json()["content"] + + +robotSay = RobotSay() +# speak = Speak() +# readTalk = ReadWav() + +def Say(): +# while True: + + '''speak.my_record() #录音 + text = readTalk.predict()['result'][0] #调用百度AI接口, 将录音转化为文本信息 + ''' + yy.record() + text = yy.asr_updata() + # if("退出" in text): + # break + + print("本人说:", text) #输出文本信息 + reply(text) + + return text + +''' + response_dialogue = talkWithRobot(text) #调用青云客机器人回答文本信息并返回 + print("青云客说:", response_dialogue) #输出回答文本信息 + + robotSay.say(response_dialogue) #播放回答信息 + + return text +''' +def Key(msg): + response_dialogue = msg + print("小溪说:", response_dialogue) # 输出回答文本信息 + robotSay.say(response_dialogue) # 播放回答信息 + +def check_record(id, function): + num = m.check_select("max(number)")[0][0]+1 + t = time.strftime('%Y-%m-%d %H:%M:%S') + name = m.rl_Nselect("name", id)[0][0] + m.check_insert(str(num), id, name, function, t) + + + +def reply(msg): + text = msg + if('' == text): + time.sleep(0.5) + # Key('正在实现功能') + + elif ("人脸识别" in text or "人脸检测" in text): + Key("正在进行人脸识别。。。") + rl.f_scan_face() + + elif ("录入" in text): + num = m.rl_select("count(id)") + if(num == 0): + Key("正在进行初次人脸录入。。。") + rl.f_rec_face() + else: + id = rl.check_face() + if id != 0: + check_record(id, "录入人脸信息") + Key("正在进行人脸录入。。。") + rl.f_rec_face() + else: + Key("正在退出人脸录入。。。") + + elif("修改人员" in text): + Key("请说出自己的用户编号") #如果是一位数请说0X,如果是两位及以上正常说即可 + id = yy.record_text() + # print(id) + if ('不知道' in id): + Key("进行人脸检测确认用户。") + id = rl.check_face() + if (id != 0): + check_record(id, "修改人员信息") + rl.rl_message_update(id) + elif(id not in string_01): #############优化 + Key("不存在该用户") + else: + id = id[1: len(id) - 1] + result = m.rl_select("id") + results = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''] ###############优化 + for i in range(0, len(result)): + results[i] = result[i][0] + # print(results) + if (int(id) in results): + check_record(id, "修改人员信息") + rl.rl_message_update(id) + else: + Key("不存在该用户") + + elif("查看人员" in text): + id = rl.check_face() + if (id != 0): + check_record(id, "查看人员信息") + results = m.rl_select("*") + for i in range(0, len(results)): + print(results[i]) + Key("已将信息打印出来。请查看!") + time.sleep(5) + else: + Key("未识别到人脸信息,将随机说出一个具有权限的用户") + + a = random.randint(1,m.rl_select("count(id)")[0][0]) + name = m.rl_Nselect("name", str(a)) + Key(name[0][0]) + + elif("删除人员" in text): + id = rl.check_face() + if (id != 0): + check_record(id, "删除人员信息") + Key("即将对"+id+"号用户的信息进行删除") + m.rl_delete(id) + Key("删除成功") + + elif("权限" in text or "记录" in text): + id = rl.check_face() + if (id != 0 ): + check_record(id, "查看权限操作记录") + results = m.check_select("*") + for i in range(0 , len(results)): + print(results[i]) + Key("已将记录打印出来。请查看!") + time.sleep(5) + + elif( "视频监控" in text): + Key("即将进入视频监控。") + rl.manual_video() + + elif("自动监控" in text): + Key("即将进入自动监控。") + id = rl.auto_video() + print("本次监控编号为:"+id) + + elif("温湿度" in text): + Key("正在检测温湿度。") + wsd.wsd() + + elif('开门' in text or '打开门锁' in text): + # check = rl.check_face() + # if check == 1: + # Key("正在打开门锁。。。") + # ms.km() + id = rl.check_face() + if(id != 0): + check_record(id, "门锁控制") + Key("正在打开门锁。") + ms.lock_control() + + elif("打开" in text and "灯光" in text): + l.L_control_open(text) + + elif("关闭" in text and "灯光" in text): + l.L_control_close(text) + + + elif ("退出" in text): + Key("正在退出程序。") + + else: + Key(talkWithRobot(text)) \ No newline at end of file