4cfad5ae0f
- 全新ui - 全面优化websocket逻辑,提高数字人和ui连接的稳定性及资源开销 - 全面优化唤醒逻辑,提供稳定的普通唤醒模式和前置词唤醒模式 - 优化拾音质量,支持多声道麦克风拾音 - 优化自动播放服务器的对接机制,提供稳定和兼容旧版ue工程的对接模式 - 数字人接口输出机器人表情,以适应新fay ui及单片机的数字人表情输出 - 使用更高级的音频时长计算方式,可以更精准控制音频播放完成后的逻辑 - 修复点击关闭按钮会导致程序退出的bug - 修复没有麦克风的设备开启麦克风会出错的问题 - 为服务器主机地址提供配置项,以方便服务器部署
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import codecs
|
|
import os
|
|
import sys
|
|
import random
|
|
import time
|
|
|
|
from core import wsa_server
|
|
from scheduler.thread_manager import MyThread
|
|
from utils import config_util
|
|
|
|
LOGS_FILE_URL = "logs/log-" + time.strftime("%Y%m%d%H%M%S") + ".log"
|
|
|
|
|
|
def random_hex(length):
|
|
result = hex(random.randint(0, 16 ** length)).replace('0x', '').lower()
|
|
if len(result) < length:
|
|
result = '0' * (length - len(result)) + result
|
|
return result
|
|
|
|
|
|
def __write_to_file(text):
|
|
if not os.path.exists("logs"):
|
|
os.mkdir("logs")
|
|
file = codecs.open(LOGS_FILE_URL, 'a', 'utf-8')
|
|
file.write(text + "\n")
|
|
file.close()
|
|
|
|
|
|
def printInfo(level, sender, text, send_time=-1):
|
|
if send_time < 0:
|
|
send_time = time.time()
|
|
format_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(send_time)) + f".{int(send_time % 1 * 10)}"
|
|
logStr = '[{}][{}] {}'.format(format_time, sender, text)
|
|
print(logStr)
|
|
if level >= 3:
|
|
if wsa_server.get_web_instance().is_connected(sender):
|
|
wsa_server.get_web_instance().add_cmd({"panelMsg": text} if sender == "系统" else {"panelMsg": text, "Username" : sender})
|
|
if wsa_server.get_instance().is_connected(sender):
|
|
content = {'Topic': 'Unreal', 'Data': {'Key': 'log', 'Value': text}} if sender == "系统" else {'Topic': 'Unreal', 'Data': {'Key': 'log', 'Value': text}, "Username" : sender}
|
|
wsa_server.get_instance().add_cmd(content)
|
|
MyThread(target=__write_to_file, args=[logStr]).start()
|
|
|
|
|
|
def log(level, text):
|
|
printInfo(level, "系统", text)
|
|
|
|
class DisablePrint:
|
|
def __enter__(self):
|
|
self._original_stdout = sys.stdout
|
|
sys.stdout = open(os.devnull, 'w')
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
sys.stdout.close()
|
|
sys.stdout = self._original_stdout |