python实现语音机器人
眾所周知,人工智能是未來的趨勢
作為一個牛X的程序員,當然得?蹭蹭熱度?趕上潮流啦
那……就展示一下我在編程課上學到的智能語音機器人吧
算了,再附送一個《完整》的QQ代碼吧!
(前提是你關注了我)
? ? ? ? ? ? 不
? ? ? ? ? ? ? ? ? 怎
? ? ? ? ? ? ? ? ? ? ? ? 么
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 華
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 麗
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?的
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 分
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 隔
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 線
好了,現在你……應該點了關注了吧
那我們繼續↓
我們一段一段解析:
import requests import easygui import time import random這里就是導入庫↑
? ? API_KEY="XXX" API_SECRET="XXX" easygui.msgbox("歡迎來到木子的QQ!","木子的QQ","愉快地進入","1.gif")#記得要放個1.gif person=None??先初始化爬蟲語音助手的賬號,再做個啟動頁面↑
while 1:from easygui import*password=multpasswordbox(msg="請輸入賬號及密碼"+chr(10)+"(區分大小寫)",title="木子的QQ",fields=["用戶名","密碼"],values=["admin","123456789"])if password[0]=="123"or"456"or"789":#驗證賬號if password[1]=="XXXXX": #驗證密碼if password[0]=="1234567890":#驗證身份(1)easygui.msgbox("歡迎您,XX!","木子的QQ","進入QQ")person="XX"breakelif password[0]=="1234567890":#驗證身份(2)easygui.msgbox("歡迎您,XX!","木子的QQ","進入QQ")person="XX"breakelif password[0]=="1234567890":#驗證身份(3)easygui.msgbox("歡迎您,開發者!","木子的QQ","進入QQ")person="XX"breakelse:easygui.msgbox("賬號或密碼錯誤(a02)","木子的QQ")#密碼錯誤else:easygui.msgbox("賬號或密碼錯誤(a01)","木子的QQ")#賬號錯誤做一個登錄的GUI界面↑
easygui.msgbox("正在進入QQ......","木子的QQ","LOADING...") time.sleep(random.randint(0, 3)) easygui.msgbox("成功進入QQ!","木子的QQ","進入") loop()然后做一個正在進入的界面,再運行“loop”(即主頁界面)↑
def loop():#重復QQ窗口age=easygui.choicebox("“XX”的好友列表"+chr(10)+"昵稱:無聊的木子",choices=["家人","同學","路人","智能機器人"])#進入目錄if age=="家人":family()elif age=="同學":classmate()elif age=="路人":passerby()elif age=="智能機器人":robot()else:easygui.msgbox("拜拜了"+chr(10)+"(;′??Д??`)","木子的QQ","離開")exit()然后是主界面(選擇聊天)↑
def family():#進入“家庭”的目錄a=easygui.choicebox("“家人”中的目錄",choices=["爸爸","媽媽","無聊的木子","EXIT"])if a=="EXIT":loop()elif a=="爸爸"or a=="媽媽"or a=="無聊的木子":chat=""newchat=easygui.textbox("(聊天記錄已清空)","和"+a+"的聊天")while True:if newchat:chat=chat+"\n"+person+":"+newchatnewchat=easygui.textbox(chat,"和"+a+"的聊天")else:loop()else:loop()def classmate():#進入“同學”的目錄a=easygui.choicebox("“同學”中的目錄",choices=["張三","李四","王二麻子","EXIT"])if a=="EXIT":loop()elif a=="張三"or a=="李四"or a=="王二麻子":chat=""newchat=easygui.textbox("(聊天記錄已清空)","和"+a+"的聊天")while True:if newchat:chat=chat+"\n"+person+":"+newchatnewchat=easygui.textbox(chat,"和"+a+"的聊天")else:loop()else:loop()def passerby():#進入“路人”的目錄a=easygui.choicebox("“路人”中的目錄",choices=["路人甲","路人乙","路過的機器人(智能AI)","EXIT"])if a=="EXIT":loop()elif a=="路人甲"or a=="路人乙":chat=""newchat=easygui.textbox("(聊天記錄已清空)","和"+a+"的聊天")while True:if newchat:chat=chat+"\n"+person+":"+newchatnewchat=easygui.textbox(chat,"和"+a+"的聊天")else:loop()else:loop()這里就是一些簡單的聊天窗口↑
最重要的來了——
他來了他來了……
就是爬蟲聊天機器人(圖靈機器人)
? def robot():easygui.msgbox("Remember:please keep the network connected."+chr(10)+"Otherwise, the voice assistant can't be used","木子的QQ","network is OK")newchat=" "chat="(聊天記錄已清空)"API_KEY=""#記得填啊,你以為我會給你嗎API_SECRET=""while True:if newchat:url=('http://i.itpk.cn/api.php?question='+newchat+"&api_key="+API_KEY+"&api_secret="+API_SECRET)file=requests.get(url)#獲取網頁代碼文件data=file.text#把代碼轉換成文字chat=chat+"\n"+person+":"+newchat+"\n"+"機器人:"+data#說話 else:loop()newchat=easygui.textbox(chat,"和智能機器人的聊天")?這一段可是
混沌未分天地亂,茫茫渺渺無人見。
自從盤古破鴻蒙,開辟從茲清濁辨。
覆載群生仰至仁,發明萬物皆成善。
欲知造化會元功,須看西游釋厄傳。
…………………………
哈哈也不是啦,就是簡單的爬蟲而已嘛
但是你要給我點贊轉發加關注
源碼如下:(我可是貢獻了自己的最大力量了,給個評論不過分吧)
? ? def robot():easygui.msgbox("Remember:please keep the network connected."+chr(10)+"Otherwise, the voice assistant can't be used","木子的QQ","network is OK")newchat=" "chat="(聊天記錄已清空)"API_KEY=""API_SECRET=""#不填就會報錯while True:if newchat:url=('http://i.itpk.cn/api.php?question='+newchat+"&api_key="+API_KEY+"&api_secret="+API_SECRET)file=requests.get(url)#獲取網頁代碼文件data=file.text#把代碼轉換成文字chat=chat+"\n"+person+":"+newchat+"\n"+"機器人:"+data#說話 else:loop()newchat=easygui.textbox(chat,"和智能機器人的聊天")def family():#進入“家庭”的目錄a=easygui.choicebox("“家人”中的目錄",choices=["爸爸","媽媽","弟弟","EXIT"])if a=="EXIT":loop()elif a=="XX"or a=="XX"or a=="XX":chat=""newchat=easygui.textbox("(聊天記錄已清空)","和"+a+"的聊天")while True:if newchat:chat=chat+"\n"+person+":"+newchatnewchat=easygui.textbox(chat,"和"+a+"的聊天")else:loop()else:loop()def classmate():#進入“同學”的目錄a=easygui.choicebox("“同學”中的目錄",choices=["張三","李四","王二麻子","EXIT"])if a=="EXIT":loop()elif a=="張三"or a=="李四"or a=="王二麻子":chat=""newchat=easygui.textbox("(聊天記錄已清空)","和"+a+"的聊天")while True:if newchat:chat=chat+"\n"+person+":"+newchatnewchat=easygui.textbox(chat,"和"+a+"的聊天")else:loop()else:loop()def passerby():#進入“路人”的目錄a=easygui.choicebox("“路人”中的目錄",choices=["路人甲","路人乙","路過的機器人(智能AI)","EXIT"])if a=="EXIT":loop()elif a=="路人甲"or a=="路人乙":chat=""newchat=easygui.textbox("(聊天記錄已清空)","和"+a+"的聊天")while True:if newchat:chat=chat+"\n"+person+":"+newchatnewchat=easygui.textbox(chat,"和"+a+"的聊天")else:loop()else:loop()def loop():#重復QQ窗口age=easygui.choicebox("“XX”的好友列表"+chr(10)+"昵稱:無聊的木子",choices=["家人","同學","路人","智能機器人"])#進入“XX”的目錄if age=="家人":family()elif age=="同學":classmate()elif age=="路人":passerby()elif age=="智能機器人":robot()else:easygui.msgbox("拜拜了"+chr(10)+"(;′??Д??`)","木子的QQ","離開")exit()import requests import easygui import time import random API_KEY="xxx"#你以為我會送你賬號密碼嗎? API_SECRET="XXX" easygui.msgbox("歡迎來到木子的QQ!","木子的QQ","愉快地進入","1.gif") easygui.msgbox("請先關注“無聊的木子”!博主等著呢") person=None while 1:from easygui import*password=multpasswordbox(msg="請輸入賬號及密碼"+chr(10)+"(區分大小寫)",title="李睿QQ",fields=["用戶名","密碼"],values=["admin","123456789"])if password[0]=="1234567"or"1234567890"or"12345678":#驗證賬號if password[1]=="XXXXXXXX": #驗證密碼if password[0]=="1234567890":#驗證身份(1)easygui.msgbox("歡迎您,XX!","木子的QQ","進入QQ")person="XX"breakelif password[0]=="1234567890":#驗證身份(2)easygui.msgbox("歡迎您,XX!","木子的QQ","進入QQ")person="XX"breakelif password[0]=="1234567890":#驗證身份(3)easygui.msgbox("歡迎您,開發者!","木子的QQ","進入QQ")person="XX"breakelse:easygui.msgbox("賬號或密碼錯誤(a02)","木子的QQ")#密碼錯誤else:easygui.msgbox("賬號或密碼錯誤(a01)","木子的QQ")#賬號錯誤 easygui.msgbox("正在進入QQ......","木子的QQ","LOADING...") time.sleep(random.randint(0, 3)) easygui.msgbox("成功進入QQ!","木子的QQ","進入") loop()??好吧,拿(留)走(下)不(評)謝(論)
謝謝!
(要圖靈的點贊收藏私信)
總結
以上是生活随笔為你收集整理的python实现语音机器人的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 启动mq命令 linux,RocketM
- 下一篇: matlab 使用uci数据集,如何使用