diff --git a/README.md b/README.md index 5909c7d..57ca88e 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,12 @@ Remote Android  [Live2D](https://www.bilibili.com/video/BV1sx4y1d775/?vd_sou ## **三、升级日志** +**2023.08.16:** + ++ 优化UE反复重连系统资源占用太高的问题; ++ 自动控制是否启动面板播放; ++ 自动删除运行日志。 + **2023.08.09:** + 去除mp3格式警告信息; diff --git a/README_EN.md b/README_EN.md index accf097..b54611d 100644 --- a/README_EN.md +++ b/README_EN.md @@ -122,6 +122,12 @@ Message format: View [WebSocket.md](https://github.com/TheRamU/Fay/blob/main/Web ## **Upgrade Log** +**2023.08.16:** + +- Optimized the issue of high system resource consumption caused by UE repeatedly reconnecting; +- Automatically control whether to start panel playback; +- Automatically delete runtime logs. + **2023.08.09:** - Remove mp3 format warning message; diff --git a/core/wsa_server.py b/core/wsa_server.py index 1c7c1d4..f61fc2c 100644 --- a/core/wsa_server.py +++ b/core/wsa_server.py @@ -16,7 +16,6 @@ class MyServer: self.__port = port # 端口号 self.__listCmd = [] # 要发送的信息的列表 self.__server: Serve = None - self.__message_value = None # client返回消息的value self.__event_loop: AbstractEventLoop = None self.__running = True self.__pending = None @@ -28,39 +27,38 @@ class MyServer: # 接收处理 async def __consumer_handler(self, websocket, path): async for message in websocket: + await asyncio.sleep(0.01) await self.__consumer(message) - + + # 发送处理 async def __producer_handler(self, websocket, path): while self.__running: - await asyncio.sleep(0.000001) + await asyncio.sleep(0.01) message = await self.__producer() if message: await websocket.send(message) - - + async def __handler(self, websocket, path): self.isConnect = True util.log(1,"websocket连接上:{}".format(self.__port)) self.on_connect_handler() - consumer_task = asyncio.ensure_future(self.__consumer_handler(websocket, path)) - producer_task = asyncio.ensure_future(self.__producer_handler(websocket, path)) + consumer_task = asyncio.ensure_future(self.__consumer_handler(websocket, path))#接收 + producer_task = asyncio.ensure_future(self.__producer_handler(websocket, path))#发送 done, self.__pending = await asyncio.wait([consumer_task, producer_task], return_when=asyncio.FIRST_COMPLETED, ) for task in self.__pending: task.cancel() self.isConnect = False + self.__running = False util.log(1,"websocket连接断开:{}".format(self.__port)) - if self.__port == 10002: - web_server_instance = get_web_instance() - web_server_instance.add_cmd({"is_connect": False}) - + self.on_close_handler() + async def __consumer(self, message): self.on_revice_handler(message) async def __producer(self): if len(self.__listCmd) > 0: message = self.on_send_handler(self.__listCmd.pop(0)) - print(message) return message else: return None @@ -81,6 +79,10 @@ class MyServer: def on_send_handler(self, message): return message + #Edit by xszyou on 20230816:通过继承此类来实现服务端的断开后的处理逻辑 + @abstractmethod + def on_close_handler(self): + pass # 创建server def __connect(self): @@ -88,7 +90,7 @@ class MyServer: asyncio.set_event_loop(self.__event_loop) self.__isExecute = True if self.__server: - print('server already exist') + util.log(1, 'server already exist') return self.__server = websockets.serve(self.__handler, self.__host, self.__port) asyncio.get_event_loop().run_until_complete(self.__server) @@ -96,7 +98,7 @@ class MyServer: # 往要发送的命令列表中,添加命令 def add_cmd(self, content): - if not self.__running or (not self.isConnect and self.__port == 10002): + if not self.__running: return jsonObj = json.dumps(content) self.__listCmd.append(jsonObj) @@ -117,31 +119,13 @@ class MyServer: try: all_tasks = asyncio.all_tasks(self.__event_loop) for task in all_tasks: - # print(task.cancel()) while not task.cancel(): - print("无法关闭!") + util.log(1, "无法关闭!") self.__event_loop.stop() self.__event_loop.close() except BaseException as e: - print("Error: {}".format(e)) + util.log(1, "Error: {}".format(e)) -#数字人端server -class HumanServer(MyServer): - def __init__(self, host='0.0.0.0', port=10000): - super().__init__(host, port) - - def on_revice_handler(self, message): - pass - - def on_connect_handler(self): - web_server_instance = get_web_instance() - web_server_instance.add_cmd({"is_connect": True}) - - - def on_send_handler(self, message): - util.log(1, '向human发送 {}'.format(message)) - return message - #ui端server @@ -158,6 +142,34 @@ class WebServer(MyServer): def on_send_handler(self, message): return message + def on_close_handler(self): + pass + +#数字人端server +class HumanServer(MyServer): + def __init__(self, host='0.0.0.0', port=10000): + super().__init__(host, port) + + def on_revice_handler(self, message): + pass + + def on_connect_handler(self): + web_server_instance = get_web_instance() + web_server_instance.add_cmd({"is_connect": True}) + + + def on_send_handler(self, message): + util.log(1, '向human发送 {}'.format(message)) + if not self.isConnect: + return None + return message + + def on_close_handler(self): + web_server_instance = get_web_instance() + web_server_instance.add_cmd({"is_connect": False}) + + + #测试 class TestServer(MyServer): def __init__(self, host='0.0.0.0', port=10000): @@ -172,6 +184,8 @@ class TestServer(MyServer): def on_send_handler(self, message): return message + def on_close_handler(self): + pass diff --git a/gui/static/js/index.js b/gui/static/js/index.js index 6670efe..859132c 100644 --- a/gui/static/js/index.js +++ b/gui/static/js/index.js @@ -73,7 +73,8 @@ new Vue({ name: '2', content: 'Tab 2 content' }], - msg_list:[] + msg_list:[], + is_connect: false } }, @@ -212,6 +213,17 @@ new Vue({ if(panelReply != undefined){ _this.addMsg(panelReply) } + let is_connect = data.is_connect + if(is_connect != undefined){ + _this.is_connect = is_connect + if (is_connect){ + _this.play_sound_enabled = false + _this.postData() + }else{ + _this.play_sound_enabled = true + _this.postData() + } + } } }, getData() { diff --git a/gui/templates/index.html b/gui/templates/index.html index 19dc9cb..3883c38 100644 --- a/gui/templates/index.html +++ b/gui/templates/index.html @@ -84,9 +84,8 @@
  • 使用面板播放:

    - - +

    +


  • @@ -146,8 +145,9 @@ @click=postStartLive()>开启 保存配置
  • -
  • -

    注:启动后请选中场景客户端,让其前端运行,否则可能会卡顿,或者无声音。

    +
  • +

    数字人:已连接

    +

    数字人:未连接

  • diff --git a/main.py b/main.py index 27ef115..75118b4 100644 --- a/main.py +++ b/main.py @@ -30,10 +30,19 @@ def __clear_songs(): if file_name.endswith('.mp3'): os.remove('./songs/' + file_name) +def __clear_logs(): + if not os.path.exists("./logs"): + os.mkdir("./logs") + for file_name in os.listdir('./logs'): + if file_name.endswith('.log'): + os.remove('./logs/' + file_name) + + if __name__ == '__main__': __clear_samples() __clear_songs() + __clear_logs() config_util.load_config() dbstatus = os.path.exists("fay.db") if(dbstatus == False):