diff --git a/src/AI_Drone_Face_Recognition_Human_Tracking/drone_control.py b/src/AI_Drone_Face_Recognition_Human_Tracking/drone_control.py index d2709c0001..6f01baec22 100644 --- a/src/AI_Drone_Face_Recognition_Human_Tracking/drone_control.py +++ b/src/AI_Drone_Face_Recognition_Human_Tracking/drone_control.py @@ -1,4 +1,4 @@ -"""无人机控制模块""" +'''无人机控制模块''' import pyvista as pv import pygame import numpy as np @@ -29,6 +29,10 @@ def __init__(self): self.max_height = 10.0 # 最大飞行高度(m) self.min_height = 0.0 # 最小高度(m) + def get_battery(self): + """新增:获取当前电量(适配主程序调用)""" + return self.battery + def takeoff(self): """起飞(仅落地状态可执行)""" if self.state == DroneState.LANDED and self.battery > 20: @@ -117,6 +121,15 @@ def rotate(self, direction): self.yaw %= 360 # 限制在0-360° print(f"🔄 旋转 {direction} | 偏航角: {self.yaw:.0f}°") + # 可选:补充主程序可能用到的扩展方法 + def get_position(self): + """获取当前位置(方便主程序调用)""" + return self.position + + def get_state(self): + """获取当前状态(返回字符串,适配主程序)""" + return self.state.value + # ===================== 3D可视化+交互控制 ===================== class DroneSimulator: diff --git a/src/AI_Drone_Face_Recognition_Human_Tracking/drone_one.py b/src/AI_Drone_Face_Recognition_Human_Tracking/drone_one.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/AI_Drone_Face_Recognition_Human_Tracking/main.py b/src/AI_Drone_Face_Recognition_Human_Tracking/main.py index 52bf16264f..fcba515a92 100644 --- a/src/AI_Drone_Face_Recognition_Human_Tracking/main.py +++ b/src/AI_Drone_Face_Recognition_Human_Tracking/main.py @@ -1,18 +1,20 @@ import cv2 import argparse -from drone_control import TelloDrone -from detection_module import DetectionEngine -from map_overlay import MapOverlay -from face_database import FaceDatabase +import numpy as np +from drone_control import VirtualDrone # 导入正确的无人机类 +from detection_module import DroneDetection # 导入正确的检测类 + + +# 注:MapOverlay/FaceDatabase为自定义模块,若未实现先注释,避免运行报错 +# from map_overlay import MapOverlay +# from face_database import FaceDatabase def parse_args(): """解析命令行参数""" - parser = argparse.ArgumentParser(description="AI无人机面部识别与人体追踪") - parser.add_argument("--yolo-model", default="yolov8n.pt", help="YOLO模型路径") + parser = argparse.ArgumentParser(description="AI无人机面部识别与人体追踪(虚拟版)") parser.add_argument("--conf-thres", type=float, default=0.5, help="检测置信度阈值") parser.add_argument("--track-thres", type=float, default=0.4, help="追踪IOU阈值") - parser.add_argument("--map-path", default="map.png", help="地图图片路径") parser.add_argument("--map-alpha", type=float, default=0.3, help="地图透明度") return parser.parse_args() @@ -20,51 +22,57 @@ def parse_args(): def main(): args = parse_args() - # 初始化核心模块 - drone = TelloDrone() # 无人机控制 - detector = DetectionEngine( - model_path=args.yolo_model, - conf_thres=args.conf_thres, - track_thres=args.track_thres - ) # 检测引擎 - face_db = FaceDatabase(db_path="face_database/") # 人脸数据库 - map_overlay = MapOverlay(map_path=args.map_path, alpha=args.map_alpha) # 地图叠加 - - # 加载人脸库 - face_db.load_all_faces() - print(f"人脸库加载完成,共{len(face_db.get_face_names())}个人脸") - - # 无人机连接与视频流启动 - if not drone.connect(): - print("无人机连接失败!") - return - drone.start_video_stream() - print(f"无人机电量:{drone.get_battery()}%") + # ===================== 初始化核心模块(适配虚拟无人机) ===================== + # 1. 初始化虚拟无人机(替换原TelloDrone) + drone = VirtualDrone() + # 2. 初始化检测模块(关联无人机,替换原DetectionEngine) + detector = DroneDetection(drone=drone) + # 3. 人脸数据库/地图叠加(未实现则注释,后续可补充) + # face_db = FaceDatabase(db_path="face_database/") + # map_overlay = MapOverlay(map_path=args.map_path, alpha=args.map_alpha) + + # ===================== 模拟初始化逻辑 ===================== + # 加载人脸库(注释,待实现FaceDatabase后启用) + # face_db.load_all_faces() + # print(f"人脸库加载完成,共{len(face_db.get_face_names())}个人脸") + + # 虚拟无人机无需真实连接,模拟启动视频流 + print("✅ 虚拟无人机初始化完成") + print(f"初始电量:{drone.get_battery()}% | 初始状态:{drone.state.value}") + # ===================== 主循环(适配虚拟无人机逻辑) ===================== try: + # 创建虚拟视频窗口(模拟无人机视频流) + cv2.namedWindow("AI Drone Face & Human Tracking", cv2.WINDOW_NORMAL) + while True: - # 获取无人机视频帧 - frame = drone.get_frame() - if frame is None: - continue - - # 1. 检测人脸/人体 - results = detector.detect(frame) - # 2. 人脸匹配 - frame = detector.match_faces(frame, results, face_db) - # 3. 人体追踪(可选:追踪最大的人体目标) - track_target = detector.get_largest_human(results) - if track_target: - # 无人机追踪逻辑(简化版:根据目标位置调整云台/飞行) - drone.track_target(frame, track_target) - - # 4. 叠加地图 - frame = map_overlay.overlay(frame) - - # 显示画面 + # 1. 生成虚拟帧(替代真实无人机视频帧) + frame = np.zeros((480, 640, 3), dtype=np.uint8) + # 在虚拟帧上绘制无人机状态 + cv2.putText(frame, f"Battery: {drone.get_battery():.1f}%", (10, 30), + cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) + cv2.putText(frame, f"Position: {drone.position.round(1)}", (10, 70), + cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) + cv2.putText(frame, f"State: {drone.state.value}", (10, 110), + cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) + + # 2. 执行无人机状态检测(替代真实人脸/人体检测) + detection_results = detector.full_detection() + # 在帧上绘制检测预警信息 + y_offset = 150 + for res in detection_results: + color = (0, 0, 255) if res.get("warning") or res.get("risk") else (0, 255, 0) + cv2.putText(frame, res["message"], (10, y_offset), + cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2) + y_offset += 30 + + # 3. 地图叠加(注释,待实现MapOverlay后启用) + # frame = map_overlay.overlay(frame) + + # 4. 显示画面 cv2.imshow("AI Drone Face & Human Tracking", frame) - # 按键控制 + # ===================== 按键控制(适配虚拟无人机) ===================== key = cv2.waitKey(1) & 0xFF if key == ord('q'): # 退出 break @@ -74,16 +82,34 @@ def main(): drone.land() elif key == ord('s'): # 保存画面 cv2.imwrite(f"drone_capture_{cv2.getTickCount()}.jpg", frame) - print("画面已保存") + print("✅ 画面已保存") + # 无人机移动控制 + elif key == ord('w'): + drone.move("forward") + elif key == ord('s'): + drone.move("back") + elif key == ord('a'): + drone.move("left") + elif key == ord('d'): + drone.move("right") + elif key == 2490368: # 上方向键:上升 + drone.move("up") + elif key == 2621440: # 下方向键:下降 + drone.move("down") + elif key == ord('q'): # 左转 + drone.rotate("left") + elif key == ord('e'): # 右转 + drone.rotate("right") except Exception as e: - print(f"程序异常:{str(e)}") + print(f"❌ 程序异常:{str(e)}") finally: - # 资源释放 - drone.stop_video_stream() - drone.land() # 紧急降落 + # ===================== 资源释放(适配虚拟无人机) ===================== + print("\n🔄 程序退出,释放资源...") + if drone.state.value == "FLYING": + drone.land() # 紧急降落 cv2.destroyAllWindows() - print("程序正常退出") + print("✅ 程序正常退出") if __name__ == "__main__": diff --git a/src/AI_Drone_Face_Recognition_Human_Tracking/overlay_map.py b/src/AI_Drone_Face_Recognition_Human_Tracking/overlay_map.py deleted file mode 100644 index 2446ee1056..0000000000 --- a/src/AI_Drone_Face_Recognition_Human_Tracking/overlay_map.py +++ /dev/null @@ -1,170 +0,0 @@ -import cv2 -import numpy as np -import os -import platform - - -class MapOverlay: - """地图叠加类(增强容错+单独运行支持)""" - - def __init__(self, map_path="map.png", alpha=0.3): - """ - :param map_path: 地图图片路径 - :param alpha: 地图透明度(0-1,越小越透明) - """ - self.alpha = alpha - self.map_img = None - self._load_map(map_path) # 加载地图(兼容无文件场景) - - def _load_map(self, map_path): - """加载地图图片,无文件时生成默认地图""" - try: - if os.path.exists(map_path): - self.map_img = cv2.imread(map_path) - if self.map_img is None: - raise Exception("地图文件损坏或格式不支持") - print(f"✅ 成功加载地图: {map_path}") - else: - # 生成默认空白地图(带文字提示) - self.map_img = np.zeros((200, 300, 3), dtype=np.uint8) - cv2.putText( - self.map_img, "DEFAULT MAP", (20, 60), - cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2 - ) - cv2.putText( - self.map_img, f"({map_path} not found)", (20, 100), - cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1 - ) - print(f"⚠️ 未找到地图文件: {map_path},使用默认地图") - except Exception as e: - # 异常时仍生成默认地图 - self.map_img = np.zeros((200, 300, 3), dtype=np.uint8) - cv2.putText( - self.map_img, "MAP LOAD FAILED", (20, 80), - cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2 - ) - print(f"❌ 加载地图失败: {str(e)}") - - def overlay(self, frame, drone_pos=(0, 0)): - """ - 将地图叠加到视频帧右上角 - :param frame: 原始视频帧 - :param drone_pos: 无人机位置(用于绘制标记) - :return: 叠加后的帧 - """ - if self.map_img is None or frame is None: - return frame # 无地图/无帧时直接返回原帧 - - h, w = frame.shape[:2] - map_h, map_w = self.map_img.shape[:2] - - # 调整地图大小(适配帧尺寸,占帧的1/4) - target_map_w = int(w / 4) - target_map_h = int(target_map_w * (map_h / map_w)) # 保持宽高比 - map_resized = cv2.resize(self.map_img, (target_map_w, target_map_h)) - map_h, map_w = map_resized.shape[:2] - - # 叠加位置(右上角,留10px边距) - x_offset = w - map_w - 10 - y_offset = 10 - - # 边界校验(避免地图超出帧范围) - if x_offset < 0: x_offset = 10 - if y_offset < 0: y_offset = 10 - if (y_offset + map_h) > h: map_h = h - y_offset - 10 - if (x_offset + map_w) > w: map_w = w - x_offset - 10 - - # 透明度混合(仅叠加有效区域) - roi = frame[y_offset:y_offset + map_h, x_offset:x_offset + map_w] - map_cropped = map_resized[:map_h, :map_w] # 裁剪地图适配ROI - blended = cv2.addWeighted(roi, 1 - self.alpha, map_cropped, self.alpha, 0) - frame[y_offset:y_offset + map_h, x_offset:x_offset + map_w] = blended - - # 绘制无人机位置标记(地图中心) - drone_x = x_offset + map_w // 2 - drone_y = y_offset + map_h // 2 - cv2.circle(frame, (drone_x, drone_y), 5, (0, 0, 255), -1) # 红色圆点 - cv2.putText( - frame, "Drone", (drone_x - 20, drone_y - 10), - cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 255), 1 - ) - return frame - - def adjust_alpha(self, new_alpha): - """调整地图透明度(调试用)""" - if 0.0 <= new_alpha <= 1.0: - self.alpha = new_alpha - print(f"✅ 地图透明度已调整为: {new_alpha}") - else: - print("⚠️ 透明度范围需在0.0-1.0之间!") - - -# ===================== 独立运行测试逻辑 ===================== -if __name__ == "__main__": - # 初始化地图叠加器(可自定义地图路径) - map_overlay = MapOverlay(map_path="map.png", alpha=0.3) - - # 打印系统信息 - print("\n" + "=" * 50) - print("🎯 地图叠加模块测试工具(独立运行模式)") - print(f"💻 当前系统: {platform.system()}") - print(f"🗺️ 地图透明度: {map_overlay.alpha}") - print("=" * 50) - - # 打开摄像头(默认0号设备) - cap = cv2.VideoCapture(0) - if not cap.isOpened(): - print("❌ 无法打开摄像头!") - exit(1) - - # 设置摄像头分辨率 - cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) - cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) - - # 操作提示 - print("\n📢 操作说明:") - print(" ↑ → 增加地图透明度") - print(" ↓ → 降低地图透明度") - print(" s → 保存当前叠加画面") - print(" q → 退出程序") - print("-" * 30) - - save_count = 0 # 保存图片计数 - while True: - # 读取摄像头帧 - ret, frame = cap.read() - if not ret: - print("❌ 无法读取摄像头画面!") - break - - # 叠加地图 - frame_overlay = map_overlay.overlay(frame) - - # 显示叠加后的画面 - cv2.imshow("Map Overlay Test (overlay_map.py)", frame_overlay) - - # 按键处理 - key = cv2.waitKey(1) & 0xFF - if key == ord('q'): - print("🔚 退出地图叠加测试程序...") - break - - elif key == ord('s'): - # 保存当前画面 - save_path = f"overlay_test_{save_count}.jpg" - cv2.imwrite(save_path, frame_overlay) - print(f"✅ 已保存画面: {save_path}") - save_count += 1 - - elif key == 2490368: # 上方向键(增加透明度) - new_alpha = min(map_overlay.alpha + 0.1, 1.0) - map_overlay.adjust_alpha(new_alpha) - - elif key == 2621440: # 下方向键(降低透明度) - new_alpha = max(map_overlay.alpha - 0.1, 0.0) - map_overlay.adjust_alpha(new_alpha) - - # 释放资源 - cap.release() - cv2.destroyAllWindows() - print("\n✅ 资源已释放,程序结束") \ No newline at end of file diff --git a/src/AI_Drone_Face_Recognition_Human_Tracking/utils.py.py b/src/AI_Drone_Face_Recognition_Human_Tracking/utils.py.py deleted file mode 100644 index e7962cbefe..0000000000 --- a/src/AI_Drone_Face_Recognition_Human_Tracking/utils.py.py +++ /dev/null @@ -1,160 +0,0 @@ -import os -import cv2 -from deepface import DeepFace -import numpy as np - - -class FaceDB: - """人脸数据库管理类""" - - def __init__(self, face_dir="faces"): - self.face_dir = face_dir - self.face_data = {} # 存储{人名: 人脸特征} - self._load_face_database() - - def _load_face_database(self): - """加载人脸库中的所有人脸特征""" - if not os.path.exists(self.face_dir): - os.makedirs(self.face_dir) - print(f"创建人脸库目录: {self.face_dir}") - - self.face_data.clear() # 清空旧数据 - for img_name in os.listdir(self.face_dir): - if img_name.endswith((".jpg", ".png")): - person_name = os.path.splitext(img_name)[0] - img_path = os.path.join(self.face_dir, img_name) - try: - # 提取人脸特征(Facenet模型) - embedding = DeepFace.represent( - img_path, - model_name="Facenet", - enforce_detection=True - )[0]["embedding"] - self.face_data[person_name] = embedding - print(f"✅ 成功加载人脸: {person_name}") - except Exception as e: - print(f"❌ 加载{img_name}失败: {str(e)[:50]}...") - - def recognize_face(self, frame, threshold=0.6): - """识别人脸,返回匹配的人名或None""" - try: - # 提取当前帧人脸特征 - frame_embedding = DeepFace.represent( - frame, - model_name="Facenet", - enforce_detection=True - )[0]["embedding"] - - # 对比人脸库(计算欧式距离) - min_distance = float("inf") - matched_name = None - for name, embedding in self.face_data.items(): - distance = np.linalg.norm(np.array(frame_embedding) - np.array(embedding)) - if distance < min_distance and distance < threshold: - min_distance = distance - matched_name = name - return matched_name, min_distance # 新增返回距离,方便调试 - except Exception as e: - print(f"❌ 人脸识别失败: {str(e)[:50]}...") - return None, float("inf") - - def add_face(self, frame, person_name): - """添加人脸到数据库""" - # 先检测人脸,确保有效 - try: - # 验证帧中有人脸 - DeepFace.extract_faces(frame, enforce_detection=True) - # 保存人脸图片 - img_path = os.path.join(self.face_dir, f"{person_name}.jpg") - cv2.imwrite(img_path, frame) - # 重新加载数据库 - self._load_face_database() - print(f"✅ 已添加[{person_name}]到人脸库,路径: {img_path}") - return True - except Exception as e: - print(f"❌ 添加人脸失败: {str(e)[:50]}...") - return False - - def list_faces(self): - """列出人脸库中所有已注册的人名""" - return list(self.face_data.keys()) - - -def draw_detection_box(frame, bbox, label, color=(0, 255, 0)): - """绘制检测框和标签""" - x1, y1, x2, y2 = map(int, bbox) - cv2.rectangle(frame, (x1, y1), (x2, y2), color, 2) - cv2.putText( - frame, label, (x1, y1 - 10), - cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2 - ) - return frame - - -# ===================== 独立运行测试逻辑 ===================== -if __name__ == "__main__": - # 初始化人脸库 - face_db = FaceDB(face_dir="faces") - print(f"\n当前人脸库已注册: {face_db.list_faces()}\n") - - # 打开摄像头 - cap = cv2.VideoCapture(0) - if not cap.isOpened(): - print("❌ 无法打开摄像头,请检查设备!") - exit(1) - - # 设置摄像头分辨率 - cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) - cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) - - print("=" * 50) - print("🎯 FaceDB 测试工具(独立运行模式)") - print("按键说明:") - print(" a → 添加当前帧人脸到数据库") - print(" r → 识别当前帧人脸") - print(" l → 列出已注册人脸") - print(" q → 退出程序") - print("=" * 50) - - while True: - # 读取摄像头帧 - ret, frame = cap.read() - if not ret: - print("❌ 无法读取摄像头画面!") - break - - # 显示实时画面 - cv2.imshow("FaceDB Test (utils.py)", frame) - - # 按键处理 - key = cv2.waitKey(1) & 0xFF - if key == ord('q'): - print("🔚 退出测试程序...") - break - - elif key == ord('a'): - # 添加人脸 - person_name = input("\n请输入要添加的人名: ").strip() - if not person_name: - print("❌ 人名不能为空!") - continue - face_db.add_face(frame, person_name) - - elif key == ord('r'): - # 识别人脸 - print("\n🔍 正在识别人脸...") - name, distance = face_db.recognize_face(frame) - if name: - print(f"✅ 识别成功!匹配到: {name} (距离: {distance:.4f})") - else: - print(f"❌ 未识别到匹配人脸(最小距离: {distance:.4f})") - - elif key == ord('l'): - # 列出已注册人脸 - faces = face_db.list_faces() - print(f"\n📋 人脸库已注册名单: {faces if faces else '空'}") - - # 释放资源 - cap.release() - cv2.destroyAllWindows() - print("\n✅ 资源已释放,程序结束") \ No newline at end of file diff --git a/src/AI_Drone_Face_Recognition_Human_Tracking/voice_module.py b/src/AI_Drone_Face_Recognition_Human_Tracking/voice_module.py deleted file mode 100644 index 168813fa82..0000000000 --- a/src/AI_Drone_Face_Recognition_Human_Tracking/voice_module.py +++ /dev/null @@ -1,172 +0,0 @@ -import pyttsx3 -import platform - - -class VoiceAssistant: - """语音助手类(增强兼容性+详细日志)""" - - def __init__(self): - self.engine = None - self._init_engine() # 初始化语音引擎 - - def _init_engine(self): - """初始化语音引擎,兼容不同系统""" - try: - self.engine = pyttsx3.init() - # 基础配置 - self.engine.setProperty("rate", 150) # 语速(100-200为宜) - self.engine.setProperty("volume", 1.0) # 音量(0.0-1.0) - - # 系统适配:Windows优先使用中文语音包 - system = platform.system() - if system == "Windows": - self._set_chinese_voice() - - print("✅ 语音引擎初始化成功!") - except Exception as e: - print(f"❌ 语音引擎初始化失败: {str(e)}") - self.engine = None - - def _set_chinese_voice(self): - """Windows系统设置中文语音包(需提前安装)""" - try: - voices = self.engine.getProperty('voices') - # 遍历语音包,选择中文语音 - for voice in voices: - if "zh-CN" in voice.id or "中文" in voice.name: - self.engine.setProperty('voice', voice.id) - print(f"✅ 已切换为中文语音包: {voice.name}") - break - else: - print("⚠️ 未找到中文语音包,使用默认语音(可能为英文)") - except Exception as e: - print(f"⚠️ 设置中文语音包失败: {str(e)}") - - def speak(self, text): - """文本转语音(增加容错)""" - if not self.engine: - print("❌ 语音引擎未初始化,无法合成语音") - return - - if not text.strip(): - print("❌ 合成文本不能为空!") - return - - try: - print(f"🔊 正在合成语音: {text}") - self.engine.say(text) - self.engine.runAndWait() # 等待语音播放完成 - print("✅ 语音合成完成!") - except Exception as e: - print(f"❌ 语音合成失败: {str(e)}") - - def list_voices(self): - """列出当前系统可用的语音包(调试用)""" - if not self.engine: - print("❌ 语音引擎未初始化,无法获取语音包") - return [] - - try: - voices = self.engine.getProperty('voices') - print("\n📋 系统可用语音包列表:") - for idx, voice in enumerate(voices): - print(f" [{idx}] 名称: {voice.name} | ID: {voice.id} | 语言: {voice.languages}") - return voices - except Exception as e: - print(f"❌ 获取语音包列表失败: {str(e)}") - return [] - - def adjust_settings(self, rate=None, volume=None): - """调整语速/音量(调试用)""" - if not self.engine: - print("❌ 语音引擎未初始化,无法调整设置") - return - - if rate is not None: - if 50 <= rate <= 300: - self.engine.setProperty("rate", rate) - print(f"✅ 语速已调整为: {rate}") - else: - print("⚠️ 语速范围需在50-300之间!") - - if volume is not None: - if 0.0 <= volume <= 1.0: - self.engine.setProperty("volume", volume) - print(f"✅ 音量已调整为: {volume}") - else: - print("⚠️ 音量范围需在0.0-1.0之间!") - - def __del__(self): - """析构函数,释放引擎资源""" - if self.engine: - try: - self.engine.stop() - except: - pass - - -# ===================== 独立运行测试逻辑 ===================== -if __name__ == "__main__": - # 初始化语音助手 - voice_assist = VoiceAssistant() - - # 打印系统信息 - print("\n" + "=" * 50) - print("🎯 语音助手测试工具(独立运行模式)") - print(f"💻 当前系统: {platform.system()}") - print("=" * 50) - - # 列出可用语音包 - voice_assist.list_voices() - - # 交互菜单 - print("\n📢 操作菜单:") - print(" 1 → 播放测试文本(中文)") - print(" 2 → 播放测试文本(英文)") - print(" 3 → 自定义文本播放") - print(" 4 → 调整语速(默认150)") - print(" 5 → 调整音量(默认1.0)") - print(" q → 退出程序") - print("-" * 30) - - while True: - choice = input("\n请输入操作编号: ").strip() - - if choice == "q": - print("🔚 退出语音助手测试程序...") - break - - elif choice == "1": - # 中文测试 - voice_assist.speak("你好,我是AI无人机语音助手,测试语音合成功能正常!") - - elif choice == "2": - # 英文测试 - voice_assist.speak("Hello, I am the AI drone voice assistant, test speech synthesis function is normal!") - - elif choice == "3": - # 自定义文本 - custom_text = input("请输入要合成的文本: ").strip() - if custom_text: - voice_assist.speak(custom_text) - else: - print("❌ 自定义文本不能为空!") - - elif choice == "4": - # 调整语速 - try: - new_rate = int(input("请输入新语速(50-300): ").strip()) - voice_assist.adjust_settings(rate=new_rate) - except ValueError: - print("❌ 请输入有效的数字!") - - elif choice == "5": - # 调整音量 - try: - new_volume = float(input("请输入新音量(0.0-1.0): ").strip()) - voice_assist.adjust_settings(volume=new_volume) - except ValueError: - print("❌ 请输入有效的数字(如0.5)!") - - else: - print("❌ 无效的操作编号,请重新输入!") \ No newline at end of file