qwerlol123? 6 months ago
parent e221cea7ba
commit 64588d63d4

@ -20,7 +20,7 @@ SECRET_KEY = 'bkNnbC37K3Ac6gI8kQ8phG1h5RIivMwj'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
audio_file = '../pythonProject6/myvoices.wav'
# Class for handling audio recording and saving
# 用于处理音频录制和保存
class Speak():
def save_wave_file(self, filepath, data):
wf = wave.open(filepath, 'wb')
@ -165,7 +165,6 @@ class ChatWindow:
self.save_to_database(user_input, response)
def start_voice_conversation(self):
# Implement voice conversation functionality
self.speak("开始语音对话,请说话...")
speak_instance = Speak()
speak_instance.my_record()
@ -201,14 +200,14 @@ class ChatWindow:
if 'result' in result:
return result['result'][0]
else:
return "Baidu speech recognition failed"
return "百度语音识别失败"
#使用mysql数据库来保存
def save_to_database(self, user_message, bot_response):
sql = "INSERT INTO chat_history (user_message, bot_response) VALUES (%s, %s)"
text = (user_message, bot_response)
self.connection.cursor().execute(sql, text)
self.connection.commit()
print("聊天记录保存与数据库中.")
self.update_chat("聊天记录保存与数据库中\n")
def view_chat_history(self):
self.chat_text.delete('1.0', END)
sql = "SELECT * FROM ai_chatter.chat_history"
@ -222,7 +221,7 @@ class ChatWindow:
for message in self.chat_history:
self.update_chat(message + "\n")
else:
self.update_chat("没有找到聊天记录\n")
self.update_chat("\n")
def delete_chat_history(self):
sql = "DELETE FROM chat_history"
@ -243,18 +242,16 @@ class ChatWindow:
#知识图谱模块
def fetch_knowledge_graph_info(self, query):
# Assuming you are using Google Knowledge Graph API
api_key = 'YOUR_API_KEY'
# 使用Google知识图谱API
api_key = ''
base_url = 'https://kgsearch.googleapis.com/v1/entities:search'
params = {
'query': query,
'key': api_key,
'limit': 1 # You can adjust the limit based on response requirements
'limit': 1
}
response = requests.get(base_url, params=params).json()
if 'itemListElement' in response:
item = response['itemListElement'][0]
if 'result' in item:

Loading…
Cancel
Save