qwerlol123? 6 months ago
parent 50c50504e2
commit 5caac9d3a0

@ -3,14 +3,17 @@ import tkinter as tk
import threading
import speech_recognition as sr
# 初始化语音播报对象
# Initialize speech synthesis object
talker = pyttsx3.init()
#登陆界面
# 用户账号和密码
# Initialize speech recognition object
recognizer = sr.Recognizer()
# Login credentials
userName = "admin"
userPass = "123"
# 创建对话页面
# Create chat window
def chat_window():
chat_window = tk.Tk()
chat_window.title("对话")
@ -35,17 +38,6 @@ def chat_window():
talker.say(answer)
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():
with sr.Microphone() as source:
print("请说话...")
@ -53,7 +45,7 @@ def voice_recognition():
try:
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)
answer = question.strip("吗??" + "!")
if question == "不聊了拜拜":
@ -67,8 +59,20 @@ def voice_recognition():
talker_thread.start()
except sr.UnknownValueError:
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():
login_window = tk.Tk()

Loading…
Cancel
Save