from PyAibote import WinBotMain
import vlc # 使用 VLC 播放音频
"url" : "127.0.0.1" #Fay的主机地址
text_queue = queue.Queue()
def on_message(ws, message):
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
print(f"[{timestamp}] Received message: {message}")
data = json.loads(message)
if "Data" in data and "Text" in data["Data"]:
text = data["Data"]["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 ###")
print("### Connection opened ###")
os.environ["PATH"] = os.environ["PATH"] + ";" + "H:/aibote/MyModel/WindowsDriver.exe"
# 2. 自定义一个脚本类,继承 WinBotMain
class CustomWinScript(WinBotMain):
# 2.1. 设置是否终端打印输出 DEBUG:输出, INFO:不输出, 默认打印输出
# 2.2. 终端打印信息是否存储LOG文件 True: 储存, False:不存储
# 2.3. 注意:script_main 此方法是脚本执行入口必须存在此方法
# result = self.find_windows()
result = self.init_speech_service("azure key", "eastasia")#需配置azure
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)
if not text_queue.empty():
result = self.metahuman_speech("H:/aibote/voice/1.mp3", text, "zh-cn", "zh-cn-XiaochenNeural", 0, True, 0, "General")#H:/aibote/voice/路径有效即可
if __name__ == '__main__':
ws_url = f"ws://{config['url']}:10002"
ws = websocket.WebSocketApp(ws_url,
wst = threading.Thread(target=ws.run_forever)
# 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)