Aibote

2024年10月30日修改
江西aibote公司的视音素2D数字人方案,可以在低算力基础cpu下使用2D克隆数字人。
官网网址:www.pyaibote.com
与Fay的对接代码如下:
代码块
# 1. 导入 WinBotMain 类
from PyAibote import WinBotMain
import time,os
import os
import websocket
import datetime
import threading
import requests
import vlc # 使用 VLC 播放音频
import time
import json
import queue
# 配置项
config = {
"url" : "127.0.0.1" #Fay的主机地址
}
text_queue = queue.Queue()
player = None
def on_message(ws, message):
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
print(f"[{timestamp}] Received message: {message}")
try:
# 解析收到的 JSON 数据
data = json.loads(message)
if "Data" in data and "Text" in data["Data"]:
text = data["Data"]["Text"]
text_queue.put(text)
except json.JSONDecodeError as e:
print(f"[Error] Failed to parse message as JSON: {e}")
def on_error(ws, error):
print(f"[Error] {error}")
def on_close(ws, close_status_code, close_msg):
print("### Connection closed ###")
def on_open(ws):
print("### Connection opened ###")
os.environ["PATH"] = os.environ["PATH"] + ";" + "H:/aibote/MyModel/WindowsDriver.exe"
# 2. 自定义一个脚本类,继承 WinBotMain
class CustomWinScript(WinBotMain):
# 2.1. 设置是否终端打印输出 DEBUG:输出, INFO:不输出, 默认打印输出
Log_Level = "DEBUG"
# 2.2. 终端打印信息是否存储LOG文件 True: 储存, False:不存储
Log_Storage = True
# 2.3. 注意:script_main 此方法是脚本执行入口必须存在此方法
def script_main(self):
# 查询所有窗口句柄
# result = self.find_windows()
# print(result)
result = self.init_speech_service("azure key", "eastasia")#需配置azure
print(result)
result = self.init_metahuman(r"H:\aibote\humanModel", 0.3, 0.3, False)
# result = self.init_metahuman(r"H:\aibote\humanModel", 0.3, 0.3, False)
print(result)
global text_queue
while True:
if not text_queue.empty():
text = text_queue.get()
result = self.metahuman_speech("H:/aibote/voice/1.mp3", text, "zh-cn", "zh-cn-XiaochenNeural", 0, True, 0, "General")#H:/aibote/voice/路径有效即可
print(result)
time.sleep(0.1)
time.sleep(10)
self.close_driver()
if __name__ == '__main__':
ws_url = f"ws://{config['url']}:10002"
ws = websocket.WebSocketApp(ws_url,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
# 运行 WebSocket 客户端
wst = threading.Thread(target=ws.run_forever)
wst.daemon = True
wst.start()
# 3. IP为:0.0.0.0, 监听 9999 号端口
# 3.1. 在远端部署脚本时,请设置 Debug=False,客户端手动启动 WindowsDriver.exe 时需指定远端 IP 或端口号
# 3.2. 命令行启动示例: WindowsDriver.exe "127.0.0.1" 9999 {'Name':'PyAibote'}
CustomWinScript.execute("0.0.0.0", 9999, Debug=True)