mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
修复 #1538
This commit is contained in:
@@ -68,23 +68,32 @@ async def checkWakeupWords(conn, text):
|
|||||||
|
|
||||||
# 获取当前音色
|
# 获取当前音色
|
||||||
voice = getattr(conn.tts, "voice", "default")
|
voice = getattr(conn.tts, "voice", "default")
|
||||||
|
if not voice:
|
||||||
|
voice = "default"
|
||||||
|
|
||||||
# 获取唤醒词回复配置
|
# 获取唤醒词回复配置
|
||||||
response = wakeup_words_config.get_wakeup_response(voice)
|
response = wakeup_words_config.get_wakeup_response(voice)
|
||||||
|
if not response or not response.get("file_path"):
|
||||||
|
response = {
|
||||||
|
"voice": "default",
|
||||||
|
"file_path": "config/assets/wakeup_words.wav",
|
||||||
|
"time": 0,
|
||||||
|
"text": "哈啰啊,我是小智啦,声音好听的台湾女孩一枚,超开心认识你耶,最近在忙啥,别忘了给我来点有趣的料哦,我超爱听八卦的啦",
|
||||||
|
}
|
||||||
|
|
||||||
# 播放唤醒词回复
|
# 播放唤醒词回复
|
||||||
conn.client_abort = False
|
conn.client_abort = False
|
||||||
opus_packets, _ = audio_to_data(response["file_path"])
|
opus_packets, _ = audio_to_data(response.get("file_path"))
|
||||||
|
|
||||||
conn.logger.bind(tag=TAG).info(f"播放唤醒词回复: {response['text']}")
|
conn.logger.bind(tag=TAG).info(f"播放唤醒词回复: {response.get('text')}")
|
||||||
await sendAudioMessage(conn, SentenceType.FIRST, opus_packets, response["text"])
|
await sendAudioMessage(conn, SentenceType.FIRST, opus_packets, response.get("text"))
|
||||||
await sendAudioMessage(conn, SentenceType.LAST, [], None)
|
await sendAudioMessage(conn, SentenceType.LAST, [], None)
|
||||||
|
|
||||||
# 补充对话
|
# 补充对话
|
||||||
conn.dialogue.put(Message(role="assistant", content=response["text"]))
|
conn.dialogue.put(Message(role="assistant", content=response.get("text")))
|
||||||
|
|
||||||
# 检查是否需要更新唤醒词回复
|
# 检查是否需要更新唤醒词回复
|
||||||
if time.time() - response["time"] > WAKEUP_CONFIG["refresh_time"]:
|
if time.time() - response.get("time", 0) > WAKEUP_CONFIG["refresh_time"]:
|
||||||
if not _wakeup_response_lock.locked():
|
if not _wakeup_response_lock.locked():
|
||||||
asyncio.create_task(wakeupWordsResponse(conn))
|
asyncio.create_task(wakeupWordsResponse(conn))
|
||||||
return True
|
return True
|
||||||
@@ -104,7 +113,7 @@ async def wakeupWordsResponse(conn):
|
|||||||
question = (
|
question = (
|
||||||
"此刻用户正在和你说```"
|
"此刻用户正在和你说```"
|
||||||
+ wakeup_word
|
+ wakeup_word
|
||||||
+ "```。\n请你根据以上用户的内容进行简短回复。要像一个人正常人一样说话,不要像机器人一样说话。\n"
|
+ "```。\n请你根据以上用户的内容进行20-30字回复。要符合系统设置的角色情感和态度,不要像机器人一样说话。\n"
|
||||||
+ "请勿对这条内容本身进行任何解释和回应,请勿返回表情符号,仅返回对用户的内容的回复。"
|
+ "请勿对这条内容本身进行任何解释和回应,请勿返回表情符号,仅返回对用户的内容的回复。"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -89,20 +89,14 @@ class WakeupWordsConfig:
|
|||||||
voice = hashlib.md5(voice.encode()).hexdigest()
|
voice = hashlib.md5(voice.encode()).hexdigest()
|
||||||
"""获取唤醒词回复配置"""
|
"""获取唤醒词回复配置"""
|
||||||
config = self._load_config()
|
config = self._load_config()
|
||||||
default_response = {
|
|
||||||
"voice": "default",
|
|
||||||
"file_path": "config/assets/wakeup_words.wav",
|
|
||||||
"time": 0,
|
|
||||||
"text": "哈啰啊,我是小智啦,声音好听的台湾女孩一枚,超开心认识你耶,最近在忙啥,别忘了给我来点有趣的料哦,我超爱听八卦的啦",
|
|
||||||
}
|
|
||||||
|
|
||||||
if not config or voice not in config:
|
if not config or voice not in config:
|
||||||
return default_response
|
return None
|
||||||
|
|
||||||
# 检查文件大小
|
# 检查文件大小
|
||||||
file_path = config[voice]["file_path"]
|
file_path = config[voice]["file_path"]
|
||||||
if not os.path.exists(file_path) or os.stat(file_path).st_size < (15 * 1024):
|
if not os.path.exists(file_path) or os.stat(file_path).st_size < (15 * 1024):
|
||||||
return default_response
|
return None
|
||||||
|
|
||||||
return config[voice]
|
return config[voice]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user