mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
在hello文件中随机选择唤醒回复语
This commit is contained in:
parent
af6c8ab935
commit
f08093e2c4
3 changed files with 10 additions and 1 deletions
BIN
main/xiaozhi-server/config/assets/hello/你好啊.mp3
Normal file
BIN
main/xiaozhi-server/config/assets/hello/你好啊.mp3
Normal file
Binary file not shown.
|
|
@ -44,11 +44,20 @@ async def checkWakeupWords(conn, text):
|
||||||
|
|
||||||
|
|
||||||
def getWakeupWordFile(file_name):
|
def getWakeupWordFile(file_name):
|
||||||
|
# 检查用户自定义唤醒词音频
|
||||||
for file in os.listdir(WAKEUP_CONFIG["dir"]):
|
for file in os.listdir(WAKEUP_CONFIG["dir"]):
|
||||||
if "my_"+file_name in file:
|
if "my_"+file_name in file:
|
||||||
return f"config/assets/{file}"
|
return f"config/assets/{file}"
|
||||||
|
|
||||||
"""查找config/assets/目录下名称为wakeup_words的文件"""
|
# 从hello目录随机选择一个文件
|
||||||
|
hello_dir = os.path.join(WAKEUP_CONFIG["dir"], "hello")
|
||||||
|
if os.path.exists(hello_dir) and os.path.isdir(hello_dir):
|
||||||
|
hello_files = os.listdir(hello_dir)
|
||||||
|
if hello_files:
|
||||||
|
random_file = random.choice(hello_files)
|
||||||
|
return os.path.join(hello_dir, random_file)
|
||||||
|
|
||||||
|
# 如果hello目录不存在或为空,使用原有逻辑
|
||||||
for file in os.listdir(WAKEUP_CONFIG["dir"]):
|
for file in os.listdir(WAKEUP_CONFIG["dir"]):
|
||||||
if file_name in file:
|
if file_name in file:
|
||||||
return f"config/assets/{file}"
|
return f"config/assets/{file}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue