|
|
@ -3,14 +3,17 @@ import tkinter as tk
|
|
|
|
import threading
|
|
|
|
import threading
|
|
|
|
import speech_recognition as sr
|
|
|
|
import speech_recognition as sr
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化语音播报对象
|
|
|
|
# Initialize speech synthesis object
|
|
|
|
talker = pyttsx3.init()
|
|
|
|
talker = pyttsx3.init()
|
|
|
|
#登陆界面
|
|
|
|
|
|
|
|
# 用户账号和密码
|
|
|
|
# Initialize speech recognition object
|
|
|
|
|
|
|
|
recognizer = sr.Recognizer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Login credentials
|
|
|
|
userName = "admin"
|
|
|
|
userName = "admin"
|
|
|
|
userPass = "123"
|
|
|
|
userPass = "123"
|
|
|
|
|
|
|
|
|
|
|
|
# 创建对话页面
|
|
|
|
# Create chat window
|
|
|
|
def chat_window():
|
|
|
|
def chat_window():
|
|
|
|
chat_window = tk.Tk()
|
|
|
|
chat_window = tk.Tk()
|
|
|
|
chat_window.title("对话")
|
|
|
|
chat_window.title("对话")
|
|
|
@ -35,17 +38,6 @@ def chat_window():
|
|
|
|
talker.say(answer)
|
|
|
|
talker.say(answer)
|
|
|
|
talker.runAndWait()
|
|
|
|
talker.runAndWait()
|
|
|
|
|
|
|
|
|
|
|
|
chat_text = tk.Text(chat_window)
|
|
|
|
|
|
|
|
chat_text.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_entry = tk.Entry(chat_window)
|
|
|
|
|
|
|
|
input_entry.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send_button = tk.Button(chat_window, text="发送", command=chat)
|
|
|
|
|
|
|
|
send_button.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat_window.mainloop()
|
|
|
|
|
|
|
|
#语音识别功能(使用百度云语音识别)
|
|
|
|
|
|
|
|
def voice_recognition():
|
|
|
|
def voice_recognition():
|
|
|
|
with sr.Microphone() as source:
|
|
|
|
with sr.Microphone() as source:
|
|
|
|
print("请说话...")
|
|
|
|
print("请说话...")
|
|
|
@ -53,7 +45,7 @@ def voice_recognition():
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
print("识别中...")
|
|
|
|
print("识别中...")
|
|
|
|
question = recognizer.recognize_baidu(audio, app_id='73927317', api_key='3jGcj5fLma64CtB3tTEuLcei', secret_key='qm8gPCF7DSKpqatx5ZQ8e4OvNLmgdYcG')
|
|
|
|
question = recognizer.recognize_google(audio, language="zh-CN")
|
|
|
|
print("你说: " + question)
|
|
|
|
print("你说: " + question)
|
|
|
|
answer = question.strip("吗??" + "!")
|
|
|
|
answer = question.strip("吗??" + "!")
|
|
|
|
if question == "不聊了拜拜":
|
|
|
|
if question == "不聊了拜拜":
|
|
|
@ -67,8 +59,20 @@ def voice_recognition():
|
|
|
|
talker_thread.start()
|
|
|
|
talker_thread.start()
|
|
|
|
except sr.UnknownValueError:
|
|
|
|
except sr.UnknownValueError:
|
|
|
|
print("抱歉, 未能识别,请重试")
|
|
|
|
print("抱歉, 未能识别,请重试")
|
|
|
|
except sr.RequestError:
|
|
|
|
|
|
|
|
print("抱歉, 无法连接到服务器")
|
|
|
|
chat_text = tk.Text(chat_window)
|
|
|
|
|
|
|
|
chat_text.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_entry = tk.Entry(chat_window)
|
|
|
|
|
|
|
|
input_entry.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send_button = tk.Button(chat_window, text="发送", command=chat)
|
|
|
|
|
|
|
|
send_button.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
voice_button = tk.Button(chat_window, text="语音识别", command=voice_recognition)
|
|
|
|
|
|
|
|
voice_button.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat_window.mainloop()
|
|
|
|
# 创建登录窗口
|
|
|
|
# 创建登录窗口
|
|
|
|
def login_window():
|
|
|
|
def login_window():
|
|
|
|
login_window = tk.Tk()
|
|
|
|
login_window = tk.Tk()
|
|
|
|