# -*- coding: utf-8 -*- """服务端接上新命令:音色列表 / 本机音频列表 / 播放本机音频 / 投图标题。""" from __future__ import annotations import sys from pathlib import Path SERVER = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\windows" r"\lanremote\server.py") OLD_IMAGE = ''' if kind == P.CMD_IMAGE: note = self.actions.show_image(str(target))''' NEW_IMAGE = ''' if kind == P.CMD_IMAGE: note = self.actions.show_image(str(target), str(msg.get("title") or ""))''' OLD_SAY = ''' if cmd == P.CMD_SAY: note = self.actions.say(str(msg.get("text") or "")) self._log(f"[播报] {note}") return {"ok": True, "note": note} ''' NEW_SAY = ''' if cmd == P.CMD_SAY: try: rate = int(msg.get("rate") or 0) except (TypeError, ValueError): rate = 0 note = self.actions.say(str(msg.get("text") or ""), str(msg.get("voice") or ""), rate) self._log(f"[播报] {note}") return {"ok": True, "note": note} if cmd == P.CMD_VOICE_LIST: voices = self.actions.list_voices() return {"ok": True, "voices": voices, "current": str(self.store.get("tts_voice") or "")} if cmd == P.CMD_AUDIO_LIST: return {"ok": True, "files": self.actions.list_local_audio(), "roots": [str(p) for p in self.actions.audio_roots()]} if cmd == P.CMD_PLAY_LOCAL: note = self.actions.play_local(str(msg.get("path") or "")) self._log(f"[本机播放] {note}") return {"ok": True, "note": note} ''' def main() -> int: text = SERVER.read_text(encoding="utf-8") ok = True for old, new, tag in ((OLD_IMAGE, NEW_IMAGE, "投图标题"), (OLD_SAY, NEW_SAY, "新命令")): if old not in text: print(f" [失败] {tag} 锚点未匹配") ok = False else: text = text.replace(old, new, 1) print(f" {tag}: OK") if ok: SERVER.write_text(text, encoding="utf-8") print("\n语法检查:") import ast try: ast.parse(SERVER.read_text(encoding="utf-8")) print(" server.py: OK") except SyntaxError as exc: print(f" server.py: 语法错误 {exc}") ok = False return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())