Skip to content

Commit

Permalink
feat: 聊天页,语音唤醒新增模式选择:长期唤醒/单次唤醒,新的单次唤醒意味着每次触发都需要携带唤醒词
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Aug 13, 2024
1 parent a5fc6b4 commit 2961798
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@
},
"wakeup_sleep": {
"enable": false,
"mode": "长期唤醒",
"wakeup_word": [
"管家",
"苏醒吧"
Expand Down
1 change: 1 addition & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@
},
"wakeup_sleep": {
"enable": false,
"mode": "长期唤醒",
"wakeup_word": [
"管家",
"苏醒吧"
Expand Down
65 changes: 45 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,44 @@ def check_talk_awake(content: str):

# 判断是否启动了 唤醒词功能
if config.get("talk", "wakeup_sleep", "enable"):
# 判断现在是否是唤醒状态
if is_talk_awake is False:
if config.get("talk", "wakeup_sleep", "mode") == "长期唤醒":
# 判断现在是否是唤醒状态
if is_talk_awake is False:
# 判断文本内容是否包含唤醒词
if common.find_substring_in_list(
content, config.get("talk", "wakeup_sleep", "wakeup_word")
):
is_talk_awake = True
logger.info("[聊天唤醒成功]")
return {
"ret": 0,
"is_talk_awake": is_talk_awake,
"first": True,
}
return {
"ret": -1,
"is_talk_awake": is_talk_awake,
"first": False,
}
else:
# 判断文本内容是否包含睡眠词
if common.find_substring_in_list(
content, config.get("talk", "wakeup_sleep", "sleep_word")
):
is_talk_awake = False
logger.info("[聊天睡眠成功]")
return {
"ret": 0,
"is_talk_awake": is_talk_awake,
"first": True,
}
return {
"ret": 0,
"is_talk_awake": is_talk_awake,
"first": False,
}
elif config.get("talk", "wakeup_sleep", "mode") == "单次唤醒":
# 无需判断当前是否是唤醒状态,因为默认都是状态清除
# 判断文本内容是否包含唤醒词
if common.find_substring_in_list(
content, config.get("talk", "wakeup_sleep", "wakeup_word")
Expand All @@ -422,30 +458,15 @@ def check_talk_awake(content: str):
return {
"ret": 0,
"is_talk_awake": is_talk_awake,
"first": True,
# 单次唤醒下 没有首次唤醒提示
"first": False,
}
return {
"ret": -1,
"is_talk_awake": is_talk_awake,
"first": False,
}
else:
# 判断文本内容是否包含睡眠词
if common.find_substring_in_list(
content, config.get("talk", "wakeup_sleep", "sleep_word")
):
is_talk_awake = False
logger.info("[聊天睡眠成功]")
return {
"ret": 0,
"is_talk_awake": is_talk_awake,
"first": True,
}
return {
"ret": 0,
"is_talk_awake": is_talk_awake,
"first": False,
}


return {"ret": 0, "is_talk_awake": True, "first": False}

Expand Down Expand Up @@ -477,6 +498,10 @@ def check_talk_awake(content: str):
my_handle.reread_handle(data)
else:
my_handle.process_data(data, "talk")

# 单次唤醒情况下,唤醒后关闭
if config.get("talk", "wakeup_sleep", "mode") == "单次唤醒":
is_talk_awake = False
else:
if check_resp["first"]:
resp_json = common.get_random_str_in_list_and_format(
Expand Down
6 changes: 6 additions & 0 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,7 @@ def common_textarea_handle(content):
config_data["talk"]["show_chat_log"] = switch_talk_show_chat_log.value

config_data["talk"]["wakeup_sleep"]["enable"] = switch_talk_wakeup_sleep_enable.value
config_data["talk"]["wakeup_sleep"]["mode"] = select_talk_wakeup_sleep_mode.value
config_data["talk"]["wakeup_sleep"]["wakeup_word"] = common_textarea_handle(textarea_talk_wakeup_sleep_wakeup_word.value)
config_data["talk"]["wakeup_sleep"]["sleep_word"] = common_textarea_handle(textarea_talk_wakeup_sleep_sleep_word.value)
config_data["talk"]["wakeup_sleep"]["wakeup_copywriting"] = common_textarea_handle(textarea_talk_wakeup_sleep_wakeup_copywriting.value)
Expand Down Expand Up @@ -5887,6 +5888,11 @@ def talk_chat_box_tuning():
with ui.expansion('语音唤醒与睡眠', icon="settings", value=True).classes('w-2/3'):
with ui.row():
switch_talk_wakeup_sleep_enable = ui.switch('启用', value=config.get("talk", "wakeup_sleep", "enable")).style(switch_internal_css)
select_talk_wakeup_sleep_mode = ui.select(
label='唤醒模式',
options={"长期唤醒": "长期唤醒", "单次唤醒": "单次唤醒"},
value=config.get("talk", "wakeup_sleep", "mode")
).style("width:100px").tooltip("长期唤醒:说完唤醒词后,会触发提示语,后期对话不需要唤醒词;单次唤醒:每次对话都需要携带唤醒词,否则默认保持睡眠,且不会触发提示语")
textarea_talk_wakeup_sleep_wakeup_word = ui.textarea(label='唤醒词', placeholder='如:管家 多个请换行分隔', value=textarea_data_change(config.get("talk", "wakeup_sleep", "wakeup_word"))).style("width:200px;")
textarea_talk_wakeup_sleep_sleep_word = ui.textarea(label='睡眠词', placeholder='如:关机 多个请换行分隔', value=textarea_data_change(config.get("talk", "wakeup_sleep", "sleep_word"))).style("width:200px;")
textarea_talk_wakeup_sleep_wakeup_copywriting = ui.textarea(label='唤醒提示语', placeholder='如:在的 多个请换行分隔', value=textarea_data_change(config.get("talk", "wakeup_sleep", "wakeup_copywriting"))).style("width:300px;")
Expand Down

0 comments on commit 2961798

Please sign in to comment.