Skip to content

Commit

Permalink
unity新增密码配置;着手开发异常报警功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Nov 17, 2023
1 parent 83b140f commit 0600026
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,6 @@ data/data.db

webui2.py

data/本地问答库-ikaros.json
data/本地问答库-ikaros.json

config copy.json
32 changes: 32 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,38 @@
"to_lang": "zh"
}
},
"abnormal_alarm": {
"platform": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"llm": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"tts": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"svc": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"visual_body": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"other": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
}
},
"webui": {
"theme": {
"choose": "蓝粉渐变",
Expand Down
32 changes: 32 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,38 @@
"to_lang": "zh"
}
},
"abnormal_alarm": {
"platform": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"llm": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"tts": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"svc": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"visual_body": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"other": {
"enable": true,
"type": "local_audio",
"local_audio_path": "data/异常报警"
}
},
"webui": {
"theme": {
"choose": "蓝粉渐变",
Expand Down
12 changes: 12 additions & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ def audio_synthesis(self, message):
"content": message["content"]
}

# 是否开启了音频播放,如果没开,则不会传文件路径给播放队列
if self.config.get("play_audio", "enable"):
self.voice_tmp_path_queue.put(data_json)
return
# 异常报警
elif message['type'] == "abnormal_alarm":
# 拼接json数据,存入队列
data_json = {
"voice_path": message['content'],
"content": message["content"]
}

# 是否开启了音频播放,如果没开,则不会传文件路径给播放队列
if self.config.get("play_audio", "enable"):
self.voice_tmp_path_queue.put(data_json)
Expand Down
9 changes: 7 additions & 2 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def move_file(self, source_path, destination_path, rename=None, format="wav"):
return destination_path


# 从文件路径中提取出带有扩展名的文件名
def extract_filename(self, file_path, with_extension=False):
"""从文件路径中提取出带有扩展名的文件名
Expand All @@ -446,8 +447,9 @@ def get_folder_names(self, path):
return folder_names


# 返回指定文件夹内所有文件的文件绝对路径(包括文件扩展名)
def get_all_file_paths(self, folder_path):
"""返回指定文件夹内所有文件的文件绝对路径包括文件扩展名
"""返回指定文件夹内所有文件的文件绝对路径包括文件扩展名
Args:
folder_path (str): 文件夹路径
Expand Down Expand Up @@ -783,4 +785,7 @@ def send_to_web_captions_printer(self, api_ip_port, data):
except Exception as e:
logging.error('web字幕打印机请求失败!请确认配置是否正确或者服务端是否运行!')
logging.error(traceback.format_exc())
return False
return False



66 changes: 66 additions & 0 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ class My_handle():
audio = None
my_translate = None

abnormal_alarm_data = {
"platform": {
"error_count": 0
},
"llm": {
"error_count": 0
},
"tts": {
"error_count": 0
},
"svc": {
"error_count": 0
},
"visual_body": {
"error_count": 0
},
"other": {
"error_count": 0
}
}

def __init__(self, config_path):
logging.info("初始化My_handle...")

Expand Down Expand Up @@ -325,6 +346,7 @@ def audio_synthesis_handle(self, data_json):
entrance 用户入场
follow 用户关注
idle_time_task 闲时任务
abnormal_alarm 异常报警
"""
# 如果虚拟身体-Unity,则发送数据到中转站
Expand All @@ -334,6 +356,8 @@ def audio_synthesis_handle(self, data_json):
# 删除 'config' 对应的键值对
data_json.pop('config')

data_json["password"] = My_handle.config.get("unity", "password")

resp_json = My_handle.common.send_request(My_handle.config.get("unity", "api_ip_port"), "POST", data_json)
if resp_json:
if resp_json["code"] == 200:
Expand Down Expand Up @@ -2192,3 +2216,45 @@ def get_interval(self, timer_flag):

# 默认间隔为0.1秒
return intervals.get(timer_flag, 0.1)


"""
异常报警
"""
def abnormal_alarm_handle(self, type):
"""异常报警
Args:
type (str): 报警类型
Returns:
bool: True/False
"""

try:
if not My_handle.config.get("abnormal_alarm", type, "enable"):
return True

if My_handle.config.get("abnormal_alarm", type, "type") == "local_audio":
path_list = My_handle.common.get_all_file_paths(My_handle.config.get("abnormal_alarm", type, "path"))

# 随机选择列表中的一个元素
audio_path = random.choice(path_list)

message = {
"type": "abnormal_alarm",
"tts_type": My_handle.audio_synthesis_type,
"data": My_handle.config.get(My_handle.audio_synthesis_type),
"config": self.filter_config,
"user_name": "系统",
"content": My_handle.common.extract_filename(audio_path)
}

self.audio_synthesis_handle(message)
except Exception as e:
logging.error(traceback.format_exc())

return False

return True

4 changes: 3 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def common_textarea_handle(content):

# config_data["unity"]["enable"] = switch_unity_enable.value
config_data["unity"]["api_ip_port"] = input_unity_api_ip_port.value
config_data["unity"]["password"] = input_unity_password.value

"""
文案
Expand Down Expand Up @@ -1601,7 +1602,8 @@ def common_textarea_handle(content):
with ui.row():
# switch_unity_enable = ui.switch('启用', value=config.get("unity", "enable"))
input_unity_api_ip_port = ui.input(label='API地址', value=config.get("unity", "api_ip_port"), placeholder='对接Unity应用使用的HTTP中转站监听的ip和端口')

input_unity_password = ui.input(label='密码', value=config.get("unity", "password"), placeholder='对接Unity应用使用的HTTP中转站的密码')

with ui.tab_panel(copywriting_page).style(tab_panel_css):
with ui.row():
switch_copywriting_auto_play = ui.switch('自动播放', value=config.get("copywriting", "auto_play"))
Expand Down

0 comments on commit 0600026

Please sign in to comment.