This commit is contained in:
HuangHai
2026-01-26 09:15:45 +08:00
parent 6b6a32c902
commit d9bb1d1f83
17 changed files with 70 additions and 358 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@@ -4,6 +4,7 @@ import time
import logging
import sys
import os
import WxUtil
# 添加项目根目录到 sys.path
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -29,11 +30,8 @@ def open_chat(target_name="糖豆爸爸"):
logger.info(f"开始执行 T1: 打开微信并进入 '{target_name}' 的对话框...")
# 连接设备
try:
d = u2.connect()
logger.info(f"设备连接成功: {d.info.get('serial')}")
except Exception as e:
logger.error(f"设备连接失败: {e}")
d = WxUtil.connect_device()
if not d:
return
# 1. 启动微信

View File

@@ -1,14 +1,15 @@
# coding=utf-8
import uiautomator2 as u2
import time
import logging
import sys
import os
import asyncio
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
sys.path.append(project_root)
from WeiXin import WxUtil
from WeiXin.WxUtil import analyze_chat_image
# 配置日志
@@ -26,14 +27,11 @@ logging.basicConfig(
)
logger = logging.getLogger("T2_GetHistory")
def get_history(target_name="对方"):
async def get_history(target_name="对方"):
logger.info("开始执行 T2: 获取当前屏幕对话历史...")
try:
d = u2.connect()
logger.info(f"设备连接成功: {d.info.get('serial')}")
except Exception as e:
logger.error(f"设备连接失败: {e}")
d = WxUtil.connect_device()
if not d:
return
# 截图
@@ -53,8 +51,12 @@ def get_history(target_name="对方"):
analyzed_path = os.path.join(screenshot_dir, analyzed_filename)
# 调用 WxUtil 中的分析函数
dialogue_log = analyze_chat_image(save_path, analyzed_path, target_name=target_name)
dialogue_log, input_box = await analyze_chat_image(save_path, analyzed_path, device=d, target_name=target_name)
if dialogue_log == "VOICE_CONVERTING":
logger.info("检测到语音正在转文字,T2 任务暂停。")
return
logger.info("✅ T2 执行完成。历史对话如下:")
if dialogue_log:
for log in dialogue_log:
@@ -66,4 +68,4 @@ def get_history(target_name="对方"):
logger.error(f"❌ T2 执行失败: {e}")
if __name__ == "__main__":
get_history()
asyncio.run(get_history())

View File

@@ -1,5 +1,4 @@
# coding=utf-8
import uiautomator2 as u2
import time
import logging
import sys
@@ -11,6 +10,7 @@ project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
sys.path.append(project_root)
from WeiXin import WxUtil
from WeiXin.WxUtil import find_input_box_center
# 配置日志
@@ -31,11 +31,8 @@ logger = logging.getLogger("T3_MarkInputBox")
def mark_input_box():
logger.info("开始执行 T3: 标识输入框位置...")
try:
d = u2.connect()
logger.info(f"设备连接成功: {d.info.get('serial')}")
except Exception as e:
logger.error(f"设备连接失败: {e}")
d = WxUtil.connect_device()
if not d:
return
screenshot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Screenshots")

View File

@@ -1,5 +1,4 @@
# coding=utf-8
import uiautomator2 as u2
import time
import logging
import sys
@@ -11,6 +10,7 @@ project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
sys.path.append(project_root)
from WeiXin import WxUtil
from WeiXin.WxUtil import find_input_box_center, perform_input_action, analyze_chat_image, clean_screenshots_dir, is_in_chat_interface
from Util.LlmUtil import get_llm_response
@@ -37,8 +37,9 @@ async def generate_and_input():
try:
# 1. 连接设备
d = u2.connect()
logger.info(f"设备连接成功: {d.info.get('serial')}")
d = WxUtil.connect_device()
if not d:
return
# 检查界面状态
if not is_in_chat_interface(d):
@@ -54,14 +55,14 @@ async def generate_and_input():
d.screenshot(tmp_shot)
analyzed_shot = os.path.join(screenshot_dir, "t4_temp_history_analyzed.jpg")
dialogue_log = analyze_chat_image(tmp_shot, analyzed_shot)
dialogue_log, input_box = await analyze_chat_image(tmp_shot, analyzed_shot, device=d)
# 语音转文字处理
if dialogue_log == "VOICE_CONVERTING":
logger.info("检测到语音正在转文字,等待 3 秒后重新截图分析...")
await asyncio.sleep(3)
d.screenshot(tmp_shot)
dialogue_log = analyze_chat_image(tmp_shot, analyzed_shot)
dialogue_log, input_box = await analyze_chat_image(tmp_shot, analyzed_shot, device=d)
history_text = ""
if dialogue_log:

View File

@@ -6,13 +6,13 @@ import sys
import time
import cv2
import uiautomator2 as u2
# 添加项目根目录到 sys.path
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
sys.path.append(project_root)
from WeiXin import WxUtil
from WeiXin.WxUtil import get_vlm_analysis
from Util.EasyOcrKit import EasyOcrKit
@@ -24,11 +24,8 @@ async def main():
logger.info("🚀 T6 VLM 语音坐标调试工具启动...")
# 连接设备
try:
d = u2.connect()
logger.info(f"设备已连接: {d.info.get('serial')}")
except Exception as e:
logger.error(f"设备连接失败: {e}")
d = WxUtil.connect_device()
if not d:
return
# 截图目录

View File

@@ -4,21 +4,24 @@ import sys
import time
import cv2
import uiautomator2 as u2
# 添加项目根目录到 sys.path
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
sys.path.append(project_root)
from WeiXin import WxUtil
from WeiXin.WxUtil import find_all_template_matches
def run_cv_debug():
# 1. 拍照 (获取当前设备屏幕)
print("📸 正在连接设备并截取屏幕...")
d = WxUtil.connect_device()
if not d:
return
try:
d = u2.connect()
screenshot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Screenshots")
if not os.path.exists(screenshot_dir):
os.makedirs(screenshot_dir)

View File

@@ -6,8 +6,6 @@ import sys
import time
from datetime import datetime
import uiautomator2 as u2
# 添加项目根目录到 sys.path
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
@@ -15,6 +13,7 @@ if project_root not in sys.path:
from Util import Win32Patch
from WeiXin import WxUtil
from WeiXin.WxUtil import perform_input_action, clean_screenshots_dir, find_template_match, find_all_template_matches
from Util.LlmUtil import get_llm_response
from Util.EasyOcrKit import EasyOcrKit
@@ -54,7 +53,9 @@ CHECK_INTERVAL = 5 # 检查频率 (秒)
class ChatBot:
def __init__(self):
self.d = u2.connect()
self.d = WxUtil.connect_device()
if not self.d:
raise Exception("无法连接到设备,任务终止")
self.last_message_text = ""
self.last_processed_msg = None # 记录上一条已处理/回复过的对方消息内容
self.screenshot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Screenshots")

View File

@@ -25,6 +25,23 @@ ocr_kit = EasyOcrKit()
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger("WxUtil")
def connect_device():
"""
连接设备并返回设备对象,同时打印详细的设备信息
"""
try:
d = u2.connect()
# 获取可靠的序列号
device_serial = d.serial if hasattr(d, 'serial') else "未知"
logger.info(f"设备连接成功: {device_serial}")
# 获取并打印详细设备信息
device_info = d.device_info
logger.info(f"详细设备信息: 品牌={device_info.get('brand')}, 型号={device_info.get('model')}, SDK={device_info.get('sdk')}")
return d
except Exception as e:
logger.error(f"设备连接失败: {e}")
return None
async def get_vlm_json(image_path, prompt):
"""
@@ -249,7 +266,7 @@ async def analyze_chat_image(image_path, output_path, device=None, target_name="
unconverted_voices = [unconverted_voices[-1]]
# 使用传入的 device 或创建新连接
d = device if device else u2.connect()
d = device if device else connect_device()
for voice in unconverted_voices:
vx, vy = voice['coordinates']