cqqz-agent 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cqqz-agent-1.0.0/PKG-INFO +81 -0
- cqqz-agent-1.0.0/README.md +69 -0
- cqqz-agent-1.0.0/cqqz_agent/DigitalHuman.py +534 -0
- cqqz-agent-1.0.0/cqqz_agent/Document.py +69 -0
- cqqz-agent-1.0.0/cqqz_agent/Public.py +253 -0
- cqqz-agent-1.0.0/cqqz_agent/__init__.py +8 -0
- cqqz-agent-1.0.0/cqqz_agent/core.py +170 -0
- cqqz-agent-1.0.0/cqqz_agent.egg-info/PKG-INFO +81 -0
- cqqz-agent-1.0.0/cqqz_agent.egg-info/SOURCES.txt +14 -0
- cqqz-agent-1.0.0/cqqz_agent.egg-info/dependency_links.txt +1 -0
- cqqz-agent-1.0.0/cqqz_agent.egg-info/requires.txt +4 -0
- cqqz-agent-1.0.0/cqqz_agent.egg-info/top_level.txt +1 -0
- cqqz-agent-1.0.0/pyproject.toml +3 -0
- cqqz-agent-1.0.0/setup.cfg +21 -0
- cqqz-agent-1.0.0/setup.py +3 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cqqz-agent
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: cqqz digital human Python control SDK (WebSocket control for Unity)
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
License: UNKNOWN
|
|
7
|
+
Platform: UNKNOWN
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Provides-Extra: document
|
|
10
|
+
|
|
11
|
+
# cqqz_agent
|
|
12
|
+
|
|
13
|
+
cqqz 数字人 Python 控制 SDK。从 ICT 数字人 SDK 的 `ict_agent` 中拆出数字人相关代码独立成包,接口与原包对应模块保持一致。
|
|
14
|
+
|
|
15
|
+
SDK 是 Unity 的控制客户端,不是独立的数字人渲染程序,也不包含 Python 端大模型推理服务。
|
|
16
|
+
|
|
17
|
+
## 包含的模块
|
|
18
|
+
|
|
19
|
+
| 模块 | 用途 |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `cqqz_agent.core` | WebSocket 连接、SDK 版本校验、请求与响应等待 |
|
|
22
|
+
| `cqqz_agent.DigitalHuman` | `DigtalHuman` 类:人物外观、动作、语音、直播、消防路线 |
|
|
23
|
+
| `cqqz_agent.Public` | 场景进入、截图、相机、公共音频、场景元素、PDF 投屏 |
|
|
24
|
+
| `cqqz_agent.Document` | PDF 逐页转 PNG(依赖 PyMuPDF,仅 PDF 投屏时用到) |
|
|
25
|
+
|
|
26
|
+
不包含 `Robot`、`UAV`、`Math` 等与数字人无关的模块。
|
|
27
|
+
|
|
28
|
+
## 安装
|
|
29
|
+
|
|
30
|
+
方式一:把 `cqqz_agent` 文件夹放到脚本同目录,直接 `import cqqz_agent`。
|
|
31
|
+
|
|
32
|
+
方式二:在本目录执行安装(推荐使用目标环境自己的虚拟环境):
|
|
33
|
+
|
|
34
|
+
```bat
|
|
35
|
+
python -m pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
数字人基础功能只依赖 `websocket-client`;使用 PDF 投屏时再安装 `PyMuPDF`
|
|
39
|
+
(或用 `python -m pip install .[document]`)。`dist/` 目录下的 wheel 可在目标机器离线安装:
|
|
40
|
+
|
|
41
|
+
```bat
|
|
42
|
+
python -m pip install dist\cqqz_agent-1.0.0-py3-none-any.whl
|
|
43
|
+
python -m pip install PyMuPDF
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 使用
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from cqqz_agent import Public
|
|
50
|
+
from cqqz_agent.DigitalHuman import DigtalHuman
|
|
51
|
+
|
|
52
|
+
if not Public.enter_scene("数字人舞台"):
|
|
53
|
+
raise SystemExit("进入场景失败")
|
|
54
|
+
|
|
55
|
+
human = DigtalHuman().init_human("Female")
|
|
56
|
+
human.set_name("小美")
|
|
57
|
+
human.play_text_content("大家好,我是数字人小美。")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- 首次导入 `cqqz_agent.DigitalHuman` 或 `cqqz_agent.Public` 就会连接 Unity 并初始化场景,导入前请先启动 Unity 并确认 10088 端口可用。
|
|
61
|
+
- 默认地址为 `ws://127.0.0.1:10088/cxx`。Python 与 Unity 不在同一台电脑时,在导入前设置环境变量:
|
|
62
|
+
|
|
63
|
+
```bat
|
|
64
|
+
set ICT_UNITY_WS=ws://192.168.0.192:10088/cxx
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- 类名 `DigtalHuman` 沿用了原 SDK 的拼写;`DigitalHuman` 是其别名,二者相同。
|
|
68
|
+
- 只运行一个控制脚本,不要求也不支持多个 Python 客户端同时控制。
|
|
69
|
+
- 在普通 `.py` 脚本主线程中顺序调用,不要放在已运行事件循环的 Notebook / 异步服务里。
|
|
70
|
+
|
|
71
|
+
## 与 ict_agent 的对应关系
|
|
72
|
+
|
|
73
|
+
| 原导入 | 新导入 |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `from ict_agent.DigitalHuman import DigtalHuman` | `from cqqz_agent.DigitalHuman import DigtalHuman` |
|
|
76
|
+
| `from ict_agent import Public` | `from cqqz_agent import Public` |
|
|
77
|
+
| `from ict_agent.Public import audio` | `from cqqz_agent.Public import audio` |
|
|
78
|
+
|
|
79
|
+
命令行接口与返回值规则不变,详见原 SDK 的《ICT 数字人 Python 使用手册》。
|
|
80
|
+
|
|
81
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# cqqz_agent
|
|
2
|
+
|
|
3
|
+
cqqz 数字人 Python 控制 SDK。从 ICT 数字人 SDK 的 `ict_agent` 中拆出数字人相关代码独立成包,接口与原包对应模块保持一致。
|
|
4
|
+
|
|
5
|
+
SDK 是 Unity 的控制客户端,不是独立的数字人渲染程序,也不包含 Python 端大模型推理服务。
|
|
6
|
+
|
|
7
|
+
## 包含的模块
|
|
8
|
+
|
|
9
|
+
| 模块 | 用途 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `cqqz_agent.core` | WebSocket 连接、SDK 版本校验、请求与响应等待 |
|
|
12
|
+
| `cqqz_agent.DigitalHuman` | `DigtalHuman` 类:人物外观、动作、语音、直播、消防路线 |
|
|
13
|
+
| `cqqz_agent.Public` | 场景进入、截图、相机、公共音频、场景元素、PDF 投屏 |
|
|
14
|
+
| `cqqz_agent.Document` | PDF 逐页转 PNG(依赖 PyMuPDF,仅 PDF 投屏时用到) |
|
|
15
|
+
|
|
16
|
+
不包含 `Robot`、`UAV`、`Math` 等与数字人无关的模块。
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
方式一:把 `cqqz_agent` 文件夹放到脚本同目录,直接 `import cqqz_agent`。
|
|
21
|
+
|
|
22
|
+
方式二:在本目录执行安装(推荐使用目标环境自己的虚拟环境):
|
|
23
|
+
|
|
24
|
+
```bat
|
|
25
|
+
python -m pip install .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
数字人基础功能只依赖 `websocket-client`;使用 PDF 投屏时再安装 `PyMuPDF`
|
|
29
|
+
(或用 `python -m pip install .[document]`)。`dist/` 目录下的 wheel 可在目标机器离线安装:
|
|
30
|
+
|
|
31
|
+
```bat
|
|
32
|
+
python -m pip install dist\cqqz_agent-1.0.0-py3-none-any.whl
|
|
33
|
+
python -m pip install PyMuPDF
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 使用
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from cqqz_agent import Public
|
|
40
|
+
from cqqz_agent.DigitalHuman import DigtalHuman
|
|
41
|
+
|
|
42
|
+
if not Public.enter_scene("数字人舞台"):
|
|
43
|
+
raise SystemExit("进入场景失败")
|
|
44
|
+
|
|
45
|
+
human = DigtalHuman().init_human("Female")
|
|
46
|
+
human.set_name("小美")
|
|
47
|
+
human.play_text_content("大家好,我是数字人小美。")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- 首次导入 `cqqz_agent.DigitalHuman` 或 `cqqz_agent.Public` 就会连接 Unity 并初始化场景,导入前请先启动 Unity 并确认 10088 端口可用。
|
|
51
|
+
- 默认地址为 `ws://127.0.0.1:10088/cxx`。Python 与 Unity 不在同一台电脑时,在导入前设置环境变量:
|
|
52
|
+
|
|
53
|
+
```bat
|
|
54
|
+
set ICT_UNITY_WS=ws://192.168.0.192:10088/cxx
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- 类名 `DigtalHuman` 沿用了原 SDK 的拼写;`DigitalHuman` 是其别名,二者相同。
|
|
58
|
+
- 只运行一个控制脚本,不要求也不支持多个 Python 客户端同时控制。
|
|
59
|
+
- 在普通 `.py` 脚本主线程中顺序调用,不要放在已运行事件循环的 Notebook / 异步服务里。
|
|
60
|
+
|
|
61
|
+
## 与 ict_agent 的对应关系
|
|
62
|
+
|
|
63
|
+
| 原导入 | 新导入 |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `from ict_agent.DigitalHuman import DigtalHuman` | `from cqqz_agent.DigitalHuman import DigtalHuman` |
|
|
66
|
+
| `from ict_agent import Public` | `from cqqz_agent import Public` |
|
|
67
|
+
| `from ict_agent.Public import audio` | `from cqqz_agent.Public import audio` |
|
|
68
|
+
|
|
69
|
+
命令行接口与返回值规则不变,详见原 SDK 的《ICT 数字人 Python 使用手册》。
|
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import cqqz_agent.core
|
|
4
|
+
from cqqz_agent.core import MyWS
|
|
5
|
+
|
|
6
|
+
# 数字人
|
|
7
|
+
class DigtalHuman():
|
|
8
|
+
name = '安琪拉'
|
|
9
|
+
age = 18
|
|
10
|
+
sex = False # 性别 true:男 ,false:女
|
|
11
|
+
build = [] # 体型
|
|
12
|
+
complexion = [] # 肤色
|
|
13
|
+
voice = [] # 声音
|
|
14
|
+
volume = 1.0 # 音量
|
|
15
|
+
appearance = [] # 容貌
|
|
16
|
+
clothing_lab = ['西装男', '西装女', '古装男', '古装女'] # 服装
|
|
17
|
+
expression = [] # 表情
|
|
18
|
+
head_action = [] # 头部动作
|
|
19
|
+
hand_action = [] # 手部动作
|
|
20
|
+
Legsandtorso_action = [] # 腿和躯干动作
|
|
21
|
+
default_action = [] # 默认动作无法定制
|
|
22
|
+
|
|
23
|
+
def __init__(self):
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
MyWS.do_wait_return({'type': 'szr', 'commond': 'init'})
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
# def init_man(self):
|
|
31
|
+
# return self
|
|
32
|
+
|
|
33
|
+
def init_human(self, sex: str):
|
|
34
|
+
"""
|
|
35
|
+
初始化数字人
|
|
36
|
+
:param sex:性别Male,Female
|
|
37
|
+
:return: self
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
result = MyWS.do_wait_return(self.__handle_result('init_human', {'sex': sex}))
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def set_name(self, name: str):
|
|
44
|
+
"""
|
|
45
|
+
设置数字人名字
|
|
46
|
+
:param name:名称
|
|
47
|
+
:return: bool返回操作成功或失败
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
result = MyWS.do_wait_return(self.__handle_result('set_name', {'name': name}))
|
|
51
|
+
return result['msg']
|
|
52
|
+
|
|
53
|
+
def set_age(self, age: int):
|
|
54
|
+
"""
|
|
55
|
+
设置数字人年龄
|
|
56
|
+
:param age:年龄
|
|
57
|
+
:return: bool返回操作成功或失败
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
result = MyWS.do_wait_return(self.__handle_result('set_age', {'age': age}))
|
|
61
|
+
return result['msg']
|
|
62
|
+
|
|
63
|
+
def get_sex(self):
|
|
64
|
+
"""
|
|
65
|
+
获取数字人性别
|
|
66
|
+
:return:返回性别
|
|
67
|
+
"""
|
|
68
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_sex'})
|
|
69
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
70
|
+
j=json.loads(result['msg'])
|
|
71
|
+
return j
|
|
72
|
+
|
|
73
|
+
def set_sex(self, sex: str):
|
|
74
|
+
"""
|
|
75
|
+
设置数字人性别
|
|
76
|
+
:param sex:性别Male,Female
|
|
77
|
+
:return: bool返回操作成功或失败
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
result = MyWS.do_wait_return(self.__handle_result('set_sex', {'sex': sex}))
|
|
81
|
+
return result['msg']
|
|
82
|
+
|
|
83
|
+
def get_somatotype(self):
|
|
84
|
+
"""
|
|
85
|
+
获取体型列表
|
|
86
|
+
:return:
|
|
87
|
+
"""
|
|
88
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_somatotype'})
|
|
89
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
90
|
+
j=json.loads(result['msg'])
|
|
91
|
+
return j
|
|
92
|
+
|
|
93
|
+
def set_somatotype(self, somatotype: str):
|
|
94
|
+
"""
|
|
95
|
+
设置体型
|
|
96
|
+
:param somatotype:体型
|
|
97
|
+
:return:
|
|
98
|
+
"""
|
|
99
|
+
result = MyWS.do_wait_return(self.__handle_result('set_somatotype', {'somatotype': somatotype}))
|
|
100
|
+
return result['msg']
|
|
101
|
+
|
|
102
|
+
def set_volume(self, volume: int):
|
|
103
|
+
"""
|
|
104
|
+
设置音量
|
|
105
|
+
:param volume:音量
|
|
106
|
+
:return:
|
|
107
|
+
"""
|
|
108
|
+
result = MyWS.do_wait_return(self.__handle_result('set_volume', {'volume': volume}))
|
|
109
|
+
return result['msg']
|
|
110
|
+
return
|
|
111
|
+
|
|
112
|
+
def get_clothing(self):
|
|
113
|
+
"""
|
|
114
|
+
获取服装列表
|
|
115
|
+
:return:
|
|
116
|
+
"""
|
|
117
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_clothing'})
|
|
118
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
119
|
+
j = json.loads(result['msg'])
|
|
120
|
+
return j
|
|
121
|
+
|
|
122
|
+
def set_clothing(self, clothing: str):
|
|
123
|
+
"""
|
|
124
|
+
设置服装
|
|
125
|
+
:param clothing:服装
|
|
126
|
+
:return:
|
|
127
|
+
"""
|
|
128
|
+
result = MyWS.do_wait_return(self.__handle_result('set_clothing', {'clothing': clothing}))
|
|
129
|
+
return result['msg']
|
|
130
|
+
|
|
131
|
+
def get_pants(self):
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
:return:
|
|
135
|
+
"""
|
|
136
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_pants'})
|
|
137
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
138
|
+
return result['msg']
|
|
139
|
+
|
|
140
|
+
def set_pants(self, pants: str):
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
:return:
|
|
144
|
+
"""
|
|
145
|
+
result = MyWS.do_wait_return(self.__handle_result('set_pants', {'pants': pants}))
|
|
146
|
+
return result['msg']
|
|
147
|
+
|
|
148
|
+
def get_hairstyle(self):
|
|
149
|
+
"""
|
|
150
|
+
获取发型列表
|
|
151
|
+
:return:
|
|
152
|
+
"""
|
|
153
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_hairstyle'})
|
|
154
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
155
|
+
j=json.loads(result['msg'])
|
|
156
|
+
return j
|
|
157
|
+
|
|
158
|
+
def set_hairstyle(self, hairstyle: str):
|
|
159
|
+
"""
|
|
160
|
+
设置发型
|
|
161
|
+
:param hairstyle: 发型
|
|
162
|
+
:return:
|
|
163
|
+
"""
|
|
164
|
+
result = MyWS.do_wait_return(self.__handle_result('set_hairstyle', {'hairstyle': hairstyle}))
|
|
165
|
+
return result['msg']
|
|
166
|
+
|
|
167
|
+
def get_face(self):
|
|
168
|
+
"""
|
|
169
|
+
获取脸型列表
|
|
170
|
+
:return:
|
|
171
|
+
"""
|
|
172
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_face'})
|
|
173
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
174
|
+
j=json.loads(result['msg'])
|
|
175
|
+
return j
|
|
176
|
+
|
|
177
|
+
def set_face(self, face: str):
|
|
178
|
+
"""
|
|
179
|
+
设置脸型
|
|
180
|
+
:return: face: 脸型
|
|
181
|
+
"""
|
|
182
|
+
result = MyWS.do_wait_return(self.__handle_result('set_face', {'face': face}))
|
|
183
|
+
return result['msg']
|
|
184
|
+
|
|
185
|
+
def get_glasses(self):
|
|
186
|
+
"""
|
|
187
|
+
获取眼镜列表
|
|
188
|
+
:return:
|
|
189
|
+
"""
|
|
190
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_glasses'})
|
|
191
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
192
|
+
j=json.loads(result['msg'])
|
|
193
|
+
return j
|
|
194
|
+
|
|
195
|
+
def set_glasses(self, glasses: str):
|
|
196
|
+
"""
|
|
197
|
+
设置眼镜
|
|
198
|
+
:return: glasses : 眼镜
|
|
199
|
+
"""
|
|
200
|
+
result = MyWS.do_wait_return(self.__handle_result('set_glasses', {'glasses': glasses}))
|
|
201
|
+
return result['msg']
|
|
202
|
+
|
|
203
|
+
def __handle_result(self, commond: str, parameters: dict = None):
|
|
204
|
+
# for i in parameters:
|
|
205
|
+
return {'type': 'szr', 'commond': commond, 'parameters': parameters}
|
|
206
|
+
|
|
207
|
+
def get_head_action(self):
|
|
208
|
+
"""
|
|
209
|
+
获取头部动作列表
|
|
210
|
+
:return:
|
|
211
|
+
"""
|
|
212
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_head_action'})
|
|
213
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
214
|
+
j=json.loads(result['msg'])
|
|
215
|
+
return j
|
|
216
|
+
|
|
217
|
+
def get_hand_action(self):
|
|
218
|
+
"""
|
|
219
|
+
获取手部动作列表
|
|
220
|
+
:return:
|
|
221
|
+
"""
|
|
222
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_hand_action'})
|
|
223
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
224
|
+
j = json.loads(result['msg'])
|
|
225
|
+
return j
|
|
226
|
+
|
|
227
|
+
def get_legs_action(self):
|
|
228
|
+
"""
|
|
229
|
+
获取腿部动作列表
|
|
230
|
+
:return:
|
|
231
|
+
"""
|
|
232
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_legs_action'})
|
|
233
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
234
|
+
j = json.loads(result['msg'])
|
|
235
|
+
return j
|
|
236
|
+
|
|
237
|
+
def get_torso_action(self):
|
|
238
|
+
"""
|
|
239
|
+
获取躯干动作列表
|
|
240
|
+
:return:
|
|
241
|
+
"""
|
|
242
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_torso_action'})
|
|
243
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
244
|
+
j = json.loads(result['msg'])
|
|
245
|
+
return j
|
|
246
|
+
|
|
247
|
+
def get_emote_action(self):
|
|
248
|
+
"""
|
|
249
|
+
获取表情动作列表
|
|
250
|
+
:return:
|
|
251
|
+
"""
|
|
252
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_emote_action'})
|
|
253
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
254
|
+
j = json.loads(result['msg'])
|
|
255
|
+
return j
|
|
256
|
+
|
|
257
|
+
def set_head_action(self, action: [str], loop_times: int):
|
|
258
|
+
"""
|
|
259
|
+
设置头部动作
|
|
260
|
+
:param action:
|
|
261
|
+
:return:
|
|
262
|
+
"""
|
|
263
|
+
result = MyWS.do_wait_return(self.__handle_result('set_head_action', {'action': action,'loop_times': loop_times}))
|
|
264
|
+
return result['msg']
|
|
265
|
+
|
|
266
|
+
def set_hand_action(self, action: [str], loop_times: int):
|
|
267
|
+
"""
|
|
268
|
+
设置手部动作
|
|
269
|
+
:param action:
|
|
270
|
+
:param loop_times:
|
|
271
|
+
:return:
|
|
272
|
+
"""
|
|
273
|
+
result = MyWS.do_wait_return(self.__handle_result('set_hand_action', {'action': action,'loop_times': loop_times}))
|
|
274
|
+
return result['msg']
|
|
275
|
+
|
|
276
|
+
def set_torso_action(self, action: [str], loop_times: int):
|
|
277
|
+
"""
|
|
278
|
+
设置躯干动作
|
|
279
|
+
:param action:
|
|
280
|
+
:return:
|
|
281
|
+
"""
|
|
282
|
+
result = MyWS.do_wait_return(self.__handle_result('set_torso_action', {'action': action,'loop_times': loop_times}))
|
|
283
|
+
return result['msg']
|
|
284
|
+
|
|
285
|
+
def set_emote_action(self, emote: str):
|
|
286
|
+
"""
|
|
287
|
+
设置表情动作
|
|
288
|
+
:param action:
|
|
289
|
+
:return:
|
|
290
|
+
"""
|
|
291
|
+
result = MyWS.do_wait_return(self.__handle_result('set_emote_action', {'emote': emote}))
|
|
292
|
+
return result['msg']
|
|
293
|
+
|
|
294
|
+
def get_skincolor(self):
|
|
295
|
+
"""
|
|
296
|
+
获取肤色列表
|
|
297
|
+
:return:
|
|
298
|
+
"""
|
|
299
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_skincolor'})
|
|
300
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
301
|
+
j=json.loads(result['msg'])
|
|
302
|
+
return j
|
|
303
|
+
|
|
304
|
+
def set_skincolor(self, skincolor: str):
|
|
305
|
+
"""
|
|
306
|
+
设置肤色
|
|
307
|
+
:return:
|
|
308
|
+
"""
|
|
309
|
+
result = MyWS.do_wait_return(self.__handle_result('set_skincolor', {'skincolor': skincolor}))
|
|
310
|
+
return result['msg']
|
|
311
|
+
|
|
312
|
+
def get_timbre(self):
|
|
313
|
+
"""
|
|
314
|
+
获取音色列表
|
|
315
|
+
:return:
|
|
316
|
+
"""
|
|
317
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_timbre'})
|
|
318
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
319
|
+
j=json.loads(result['msg'])
|
|
320
|
+
return j
|
|
321
|
+
|
|
322
|
+
def set_timbre(self, timbre: str):
|
|
323
|
+
"""
|
|
324
|
+
设置音色
|
|
325
|
+
:return:
|
|
326
|
+
"""
|
|
327
|
+
result = MyWS.do_wait_return(self.__handle_result('set_timbre', {'timbre': timbre}))
|
|
328
|
+
return result['msg']
|
|
329
|
+
|
|
330
|
+
def stop_audio(self):
|
|
331
|
+
"""
|
|
332
|
+
停止音乐
|
|
333
|
+
:return:
|
|
334
|
+
"""
|
|
335
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'stop_audio'})
|
|
336
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
337
|
+
return result['msg']
|
|
338
|
+
|
|
339
|
+
def play_text_content(self, content: str):
|
|
340
|
+
"""
|
|
341
|
+
播报新闻稿
|
|
342
|
+
:param content:
|
|
343
|
+
:return:
|
|
344
|
+
"""
|
|
345
|
+
result = MyWS.do_wait_return(self.__handle_result('play_text_content', {'content': content}))
|
|
346
|
+
return result['msg']
|
|
347
|
+
|
|
348
|
+
def stop_text(self):
|
|
349
|
+
"""
|
|
350
|
+
停止播报新闻稿
|
|
351
|
+
:return:
|
|
352
|
+
"""
|
|
353
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'stop_text'})
|
|
354
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
355
|
+
return result['msg']
|
|
356
|
+
|
|
357
|
+
def get_speech_text(self):
|
|
358
|
+
"""
|
|
359
|
+
开始语音识别,并获取语音识别结果
|
|
360
|
+
:return:
|
|
361
|
+
"""
|
|
362
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_speech_text'})
|
|
363
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
364
|
+
return result['msg']
|
|
365
|
+
else:
|
|
366
|
+
print(result['msg'])
|
|
367
|
+
return None
|
|
368
|
+
|
|
369
|
+
def export_appearance(self):
|
|
370
|
+
"""
|
|
371
|
+
导出外观参数
|
|
372
|
+
:return:
|
|
373
|
+
"""
|
|
374
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'export_appearance'})
|
|
375
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
376
|
+
return result['msg']
|
|
377
|
+
|
|
378
|
+
def get_audio_clip(self):
|
|
379
|
+
"""
|
|
380
|
+
|
|
381
|
+
:return:
|
|
382
|
+
"""
|
|
383
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_audio_clip'})
|
|
384
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
385
|
+
return result['msg']
|
|
386
|
+
|
|
387
|
+
def set_audio_clip(self, audio: str):
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
:return:
|
|
391
|
+
"""
|
|
392
|
+
result = MyWS.do_wait_return(self.__handle_result('set_audio_clip', {'audio': audio}))
|
|
393
|
+
return result['msg']
|
|
394
|
+
|
|
395
|
+
def play_audio(self):
|
|
396
|
+
"""
|
|
397
|
+
|
|
398
|
+
:return:
|
|
399
|
+
"""
|
|
400
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'play_audio'})
|
|
401
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
402
|
+
return result['msg']
|
|
403
|
+
|
|
404
|
+
def pause_audio(self):
|
|
405
|
+
"""
|
|
406
|
+
|
|
407
|
+
:return:
|
|
408
|
+
"""
|
|
409
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'pause_audio'})
|
|
410
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
411
|
+
return result['msg']
|
|
412
|
+
|
|
413
|
+
def unpause_audio(self):
|
|
414
|
+
"""
|
|
415
|
+
|
|
416
|
+
:return:
|
|
417
|
+
"""
|
|
418
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'unpause_audio'})
|
|
419
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
420
|
+
return result['msg']
|
|
421
|
+
|
|
422
|
+
def stop_audio(self):
|
|
423
|
+
"""
|
|
424
|
+
|
|
425
|
+
:return:
|
|
426
|
+
"""
|
|
427
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'stop_audio'})
|
|
428
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
429
|
+
return result['msg']
|
|
430
|
+
|
|
431
|
+
def get_text_asset(self):
|
|
432
|
+
"""
|
|
433
|
+
|
|
434
|
+
:return:
|
|
435
|
+
"""
|
|
436
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'get_text_asset'})
|
|
437
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
438
|
+
j=json.loads(result['msg'])
|
|
439
|
+
return j
|
|
440
|
+
|
|
441
|
+
def set_text_asset(self, text_asset: str):
|
|
442
|
+
"""
|
|
443
|
+
|
|
444
|
+
:return:
|
|
445
|
+
"""
|
|
446
|
+
result = MyWS.do_wait_return(self.__handle_result('set_text_asset', {'text_asset': text_asset}))
|
|
447
|
+
return result['msg']
|
|
448
|
+
|
|
449
|
+
def play_text(self):
|
|
450
|
+
"""
|
|
451
|
+
|
|
452
|
+
:return:
|
|
453
|
+
"""
|
|
454
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'play_text'})
|
|
455
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
456
|
+
return result['msg']
|
|
457
|
+
|
|
458
|
+
def stop_text(self):
|
|
459
|
+
"""
|
|
460
|
+
|
|
461
|
+
:return:
|
|
462
|
+
"""
|
|
463
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'stop_text'})
|
|
464
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
465
|
+
return result['msg']
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def set_escape_route(self, points):
|
|
469
|
+
"""设置消防路线:[x, z] 世界坐标列表,开始时根据场景模型自动规划避障路径。"""
|
|
470
|
+
result = MyWS.do_wait_return(self.__handle_result('fire_set_route', {'points': points}))
|
|
471
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
472
|
+
return True
|
|
473
|
+
print(result['msg'])
|
|
474
|
+
return False
|
|
475
|
+
|
|
476
|
+
def start_escape_route(self):
|
|
477
|
+
"""构建导航并检查所有路线点后开始自动避障行走;不可达返回 False,用状态接口查询进度。"""
|
|
478
|
+
result = MyWS.do_wait_return(self.__handle_result('fire_start_route'))
|
|
479
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
480
|
+
return True
|
|
481
|
+
print(result['msg'])
|
|
482
|
+
return False
|
|
483
|
+
|
|
484
|
+
def stop_escape_route(self):
|
|
485
|
+
"""停止行走并恢复键盘控制;再次开始会从路线首点行走。"""
|
|
486
|
+
result = MyWS.do_wait_return(self.__handle_result('fire_stop_route'))
|
|
487
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
488
|
+
return True
|
|
489
|
+
print(result['msg'])
|
|
490
|
+
return False
|
|
491
|
+
|
|
492
|
+
def get_escape_route_status(self):
|
|
493
|
+
"""返回 state、reached、total、position[x,y,z]、speaking、message,失败返回 None。"""
|
|
494
|
+
result = MyWS.do_wait_return(self.__handle_result('fire_route_status'))
|
|
495
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
496
|
+
return json.loads(result['msg'])
|
|
497
|
+
print(result['msg'])
|
|
498
|
+
return None
|
|
499
|
+
|
|
500
|
+
def introduce_fire_equipment(self, equipment: str):
|
|
501
|
+
"""语音/字幕介绍“逃生面具”或“灭火器”,音频开始时返回,不含器材操作动画。"""
|
|
502
|
+
result = MyWS.do_wait_return(self.__handle_result('fire_introduce', {'equipment': equipment}))
|
|
503
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
504
|
+
return True
|
|
505
|
+
print(result['msg'])
|
|
506
|
+
return False
|
|
507
|
+
|
|
508
|
+
def start_live(self):
|
|
509
|
+
"""
|
|
510
|
+
一键启动直播(观众页面服务 + MediaMTX + RTMP 推流)
|
|
511
|
+
:return: 成功返回 'ok',失败打印原因并返回 None
|
|
512
|
+
"""
|
|
513
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'start_live'})
|
|
514
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
515
|
+
return result['msg']
|
|
516
|
+
else:
|
|
517
|
+
print(result['msg'])
|
|
518
|
+
return None
|
|
519
|
+
|
|
520
|
+
def stop_live(self):
|
|
521
|
+
"""
|
|
522
|
+
停止直播推流
|
|
523
|
+
:return: 成功返回 'ok',失败打印原因并返回 None
|
|
524
|
+
"""
|
|
525
|
+
result = MyWS.do_wait_return({'type': 'szr', 'commond': 'stop_live'})
|
|
526
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
527
|
+
return result['msg']
|
|
528
|
+
else:
|
|
529
|
+
print(result['msg'])
|
|
530
|
+
return None
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
# 类名沿用了原 SDK 的拼写,另提供正确拼写的别名
|
|
534
|
+
DigitalHuman = DigtalHuman
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PDF 文档投屏:把 PDF 逐页渲染成 PNG,交给 Unity 显示在课堂场景的电视屏幕上。
|
|
3
|
+
|
|
4
|
+
Unity 端由 Assets/Scripts/DocumentScreenController.cs 处理 document_* 指令,
|
|
5
|
+
图片只会贴到课堂场景中材质名为「屏幕」的物体上,所以调用前请先进入课堂场景。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import atexit
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import tempfile
|
|
12
|
+
|
|
13
|
+
_render_dirs = []
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _load_fitz():
|
|
17
|
+
try:
|
|
18
|
+
import pymupdf as fitz
|
|
19
|
+
except ImportError:
|
|
20
|
+
try:
|
|
21
|
+
import fitz
|
|
22
|
+
except ImportError as exc:
|
|
23
|
+
raise RuntimeError("未安装 PyMuPDF,请先执行:pip install PyMuPDF") from exc
|
|
24
|
+
return fitz
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _cleanup():
|
|
28
|
+
for path in _render_dirs:
|
|
29
|
+
shutil.rmtree(path, ignore_errors=True)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
atexit.register(_cleanup)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def render_pdf(file_path: str, dpi: int = 300):
|
|
36
|
+
"""
|
|
37
|
+
将 PDF 每一页渲染为 PNG(Python 退出时自动删除临时文件)
|
|
38
|
+
:param file_path: PDF 文件路径
|
|
39
|
+
:param dpi: 渲染分辨率(限制在 72~300),默认 300,越高越清晰、内存占用越大
|
|
40
|
+
:return: PNG 绝对路径列表,按页码升序
|
|
41
|
+
"""
|
|
42
|
+
path = os.path.abspath(os.path.expanduser(file_path))
|
|
43
|
+
if not os.path.isfile(path):
|
|
44
|
+
raise FileNotFoundError("文件不存在:" + path)
|
|
45
|
+
if os.path.splitext(path)[1].lower() != ".pdf":
|
|
46
|
+
raise ValueError("暂时只支持 PDF 文件:" + path)
|
|
47
|
+
|
|
48
|
+
dpi = max(72, min(300, int(dpi)))
|
|
49
|
+
fitz = _load_fitz()
|
|
50
|
+
|
|
51
|
+
out_dir = tempfile.mkdtemp(prefix="ict_doc_")
|
|
52
|
+
_render_dirs.append(out_dir)
|
|
53
|
+
|
|
54
|
+
doc = fitz.open(path)
|
|
55
|
+
try:
|
|
56
|
+
if doc.needs_pass:
|
|
57
|
+
raise ValueError("PDF 已加密,请先解除密码:" + path)
|
|
58
|
+
if doc.page_count == 0:
|
|
59
|
+
raise ValueError("PDF 没有可用页面:" + path)
|
|
60
|
+
|
|
61
|
+
pages = []
|
|
62
|
+
for index in range(doc.page_count):
|
|
63
|
+
pix = doc.load_page(index).get_pixmap(dpi=dpi)
|
|
64
|
+
out_path = os.path.join(out_dir, "page_%03d.png" % (index + 1))
|
|
65
|
+
pix.save(out_path)
|
|
66
|
+
pages.append(out_path)
|
|
67
|
+
return pages
|
|
68
|
+
finally:
|
|
69
|
+
doc.close()
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import time
|
|
3
|
+
import cqqz_agent.core
|
|
4
|
+
from cqqz_agent.core import MyWS
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class audio:
|
|
8
|
+
|
|
9
|
+
def __init__(self):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
def audio_load(self, filepath: str):
|
|
13
|
+
"""
|
|
14
|
+
加载音频 (仅支持wav,mp3格式)
|
|
15
|
+
:param filepath:文件路径
|
|
16
|
+
:return: 返回成功:True或失败:False
|
|
17
|
+
"""
|
|
18
|
+
# MyWS.do_immediately(
|
|
19
|
+
# {'type': 'other', 'commond': 'audio_load', 'file_name': file_name})
|
|
20
|
+
|
|
21
|
+
result =MyWS.do_wait_return( {'type': 'other', 'commond': 'audio_load', 'filepath': filepath})
|
|
22
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
23
|
+
return True
|
|
24
|
+
else:
|
|
25
|
+
print(result['msg'])
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
def audio_play(self):
|
|
29
|
+
"""
|
|
30
|
+
播放音频
|
|
31
|
+
:return:
|
|
32
|
+
"""
|
|
33
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'audio_play'})
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
def audio_pause(self):
|
|
37
|
+
"""
|
|
38
|
+
暂停音频播放
|
|
39
|
+
:return:
|
|
40
|
+
"""
|
|
41
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'audio_pause'})
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
def audio_stop(self):
|
|
45
|
+
"""
|
|
46
|
+
停止播放音频
|
|
47
|
+
:return:
|
|
48
|
+
"""
|
|
49
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'audio_stop'})
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
def audio_set_volume(self,volume:float):
|
|
53
|
+
"""
|
|
54
|
+
设置音量
|
|
55
|
+
:param volume: 音量大小(0~1)
|
|
56
|
+
:return:
|
|
57
|
+
"""
|
|
58
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'audio_set_volume','volume':volume})
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def screen_shot(isStep:bool, stepName:str=''):
|
|
63
|
+
"""
|
|
64
|
+
截图
|
|
65
|
+
:param isStep: False:整个任务截图,True:单个步骤截图
|
|
66
|
+
:param stepName: 填写对应步骤名,用于对应步骤
|
|
67
|
+
:return:
|
|
68
|
+
"""
|
|
69
|
+
if isStep==True:
|
|
70
|
+
if stepName=='':
|
|
71
|
+
print('截图步骤时步骤名称不能为空')
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'screen_shot','isStep':isStep,'stepName':stepName})
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
def set_camera_mode(mode:str,center:[float,float,float]=None,radius:float=None,speed:float=None,high:float=None):
|
|
78
|
+
"""
|
|
79
|
+
设置相机模式
|
|
80
|
+
:param mode: 模式名:自由模式 或 环绕模式
|
|
81
|
+
:param center: 环绕中点
|
|
82
|
+
:param radius: 环绕半径
|
|
83
|
+
:param speed: 环绕速度
|
|
84
|
+
:return:
|
|
85
|
+
"""
|
|
86
|
+
if mode=='自由模式':
|
|
87
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'set_camera_mode', 'mode': mode})
|
|
88
|
+
elif mode=='环绕模式':
|
|
89
|
+
if(center==None or radius==None or speed==None or high==None):
|
|
90
|
+
print('环绕模式下,请设置其它参数')
|
|
91
|
+
else:
|
|
92
|
+
MyWS.do_immediately({'type': 'other', 'commond': 'set_camera_mode', 'mode': mode,'center': center,'radius': radius,'speed': speed,'high':high})
|
|
93
|
+
else:
|
|
94
|
+
print('请输入正确模式名称')
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
def get_control_image():
|
|
98
|
+
"""
|
|
99
|
+
获取当前场景可替换的所有照片
|
|
100
|
+
:return: 返回照片名称数组 string[]
|
|
101
|
+
"""
|
|
102
|
+
result=MyWS.do_wait_return({'type': 'other', 'commond': 'get_control_image'})
|
|
103
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
104
|
+
return json.loads(result['msg'])
|
|
105
|
+
else:
|
|
106
|
+
print(result['msg'])
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
def set_control_image(bgName:str,filePath:str):
|
|
110
|
+
"""
|
|
111
|
+
设置背景照片
|
|
112
|
+
:param bgName: 照片名称
|
|
113
|
+
:param filePath: 图片本地路径
|
|
114
|
+
:return:True:设置成功,False:设置失败
|
|
115
|
+
"""
|
|
116
|
+
result=MyWS.do_wait_return({'type': 'other', 'commond': 'set_control_image', 'name': bgName,'filePath':filePath})
|
|
117
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
118
|
+
return True
|
|
119
|
+
else:
|
|
120
|
+
print("照片设置失败:"+result['msg'])
|
|
121
|
+
return False
|
|
122
|
+
|
|
123
|
+
def get_scene_objet():
|
|
124
|
+
"""
|
|
125
|
+
获取可创建的场景元素物体
|
|
126
|
+
:return:返回元素名称数组 string[]
|
|
127
|
+
"""
|
|
128
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': 'get_scene_objet'})
|
|
129
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
130
|
+
return json.loads(result['msg'])
|
|
131
|
+
else:
|
|
132
|
+
print(result['msg'])
|
|
133
|
+
return None
|
|
134
|
+
def set_scene_objet(name:str,point: [float, float,float]=[0,0,0],rotate:[float,float,float]=[0,0,0]):
|
|
135
|
+
"""
|
|
136
|
+
创建场景元素物体
|
|
137
|
+
:param name:物体名
|
|
138
|
+
:param point:坐标位置
|
|
139
|
+
:param rotate:旋转角度
|
|
140
|
+
:return:True:设置成功,False:设置失败
|
|
141
|
+
"""
|
|
142
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': 'set_scene_objet', 'name': name, 'point': point,'rotate':rotate})
|
|
143
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
144
|
+
return True
|
|
145
|
+
else:
|
|
146
|
+
print("场景元素设置失败:"+result['msg'])
|
|
147
|
+
return False
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_scene_list():
|
|
151
|
+
"""
|
|
152
|
+
获取可以通过 Python 直接进入的场景列表
|
|
153
|
+
:return: 返回场景名称数组 string[],失败返回 None
|
|
154
|
+
"""
|
|
155
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': 'get_scene_list'})
|
|
156
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
157
|
+
return json.loads(result['msg'])
|
|
158
|
+
else:
|
|
159
|
+
print(result['msg'])
|
|
160
|
+
return None
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def enter_scene(scene_name: str):
|
|
164
|
+
"""
|
|
165
|
+
进入指定场景,不需要在 LoadingScene 中点击 UI
|
|
166
|
+
:param scene_name: 数字人舞台 / 博物馆 / 课堂 / 直播间 / 消防培训 / 音乐教室
|
|
167
|
+
:return: True:进入成功,False:进入失败
|
|
168
|
+
"""
|
|
169
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': 'enter_scene', 'scene_name': scene_name})
|
|
170
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
171
|
+
return True
|
|
172
|
+
else:
|
|
173
|
+
print("进入场景失败:" + result.get('msg', ''))
|
|
174
|
+
return False
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def open_document(file_path: str, page: int = 1, dpi: int = 300):
|
|
178
|
+
"""
|
|
179
|
+
打开 PDF 并显示到课堂场景的电视屏幕上
|
|
180
|
+
:param file_path: PDF 文件路径
|
|
181
|
+
:param page: 初始页码,从 1 开始
|
|
182
|
+
:param dpi: 渲染分辨率(72~300),默认 300,屏幕文字偏小时可保持或调高
|
|
183
|
+
:return: True:显示成功,False:显示失败
|
|
184
|
+
"""
|
|
185
|
+
from cqqz_agent.Document import render_pdf
|
|
186
|
+
try:
|
|
187
|
+
pages = render_pdf(file_path, dpi=dpi)
|
|
188
|
+
except Exception as ex:
|
|
189
|
+
print("打开文档失败:" + str(ex))
|
|
190
|
+
return False
|
|
191
|
+
|
|
192
|
+
result = MyWS.do_wait_return(
|
|
193
|
+
{'type': 'other', 'commond': 'document_open', 'pages': pages, 'page': page})
|
|
194
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
195
|
+
print(result.get('msg', ''))
|
|
196
|
+
return True
|
|
197
|
+
else:
|
|
198
|
+
print("显示文档失败:" + result.get('msg', ''))
|
|
199
|
+
return False
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def next_page():
|
|
203
|
+
"""
|
|
204
|
+
显示下一页
|
|
205
|
+
:return: True:翻页成功,False:已经是最后一页或未打开文档
|
|
206
|
+
"""
|
|
207
|
+
return _document_step('document_next', '翻页失败')
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def prev_page():
|
|
211
|
+
"""
|
|
212
|
+
显示上一页
|
|
213
|
+
:return: True:翻页成功,False:已经是第一页或未打开文档
|
|
214
|
+
"""
|
|
215
|
+
return _document_step('document_prev', '翻页失败')
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def goto_page(page: int):
|
|
219
|
+
"""
|
|
220
|
+
跳转到指定页
|
|
221
|
+
:param page: 页码,从 1 开始
|
|
222
|
+
:return: True:跳转成功,False:跳转失败
|
|
223
|
+
"""
|
|
224
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': 'document_goto', 'page': page})
|
|
225
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
226
|
+
print(result.get('msg', ''))
|
|
227
|
+
return True
|
|
228
|
+
else:
|
|
229
|
+
print("跳转失败:" + result.get('msg', ''))
|
|
230
|
+
return False
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def close_document():
|
|
234
|
+
"""
|
|
235
|
+
关闭文档,电视屏幕恢复为原来的画面
|
|
236
|
+
:return: True:关闭成功,False:关闭失败
|
|
237
|
+
"""
|
|
238
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': 'document_close'})
|
|
239
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
240
|
+
return True
|
|
241
|
+
else:
|
|
242
|
+
print("关闭文档失败:" + result.get('msg', ''))
|
|
243
|
+
return False
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _document_step(command: str, error_prefix: str):
|
|
247
|
+
result = MyWS.do_wait_return({'type': 'other', 'commond': command})
|
|
248
|
+
if result['result'] == cqqz_agent.core.SUCCESS:
|
|
249
|
+
print(result.get('msg', ''))
|
|
250
|
+
return True
|
|
251
|
+
else:
|
|
252
|
+
print(error_prefix + ":" + result.get('msg', ''))
|
|
253
|
+
return False
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import websocket
|
|
9
|
+
|
|
10
|
+
Version = '1.0'
|
|
11
|
+
# 常量
|
|
12
|
+
SUCCESS = 1
|
|
13
|
+
FAILED_WARNING = 2
|
|
14
|
+
FAILED_ERROR = 3
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# sdk底层核心
|
|
18
|
+
class Core:
|
|
19
|
+
ws = None
|
|
20
|
+
asyncEvects = {} # 异步事件
|
|
21
|
+
resultEvents = {} # 异步结果
|
|
22
|
+
eventId = 0 # 等待事件id
|
|
23
|
+
loop = None
|
|
24
|
+
|
|
25
|
+
def __init__(self):
|
|
26
|
+
self.loop = asyncio.get_event_loop()
|
|
27
|
+
self.loop.run_until_complete(self.init())
|
|
28
|
+
|
|
29
|
+
def om_open(self, ws):
|
|
30
|
+
print('连接虚仿端成功')
|
|
31
|
+
self.sendmsg(json.dumps({'event_id': 0, 'type': 'checkSdk', 'data': Version}))
|
|
32
|
+
|
|
33
|
+
# 定义一个用来接收监听数据的方法
|
|
34
|
+
def on_message(self, ws, message: str):
|
|
35
|
+
# print("监听到消息,内容如下:" + message)
|
|
36
|
+
if self.ws.sock != None:
|
|
37
|
+
obj = json.loads(message)
|
|
38
|
+
id = obj['event_id']
|
|
39
|
+
if id == None:
|
|
40
|
+
print("主动消息:" + obj['msg'])
|
|
41
|
+
else:
|
|
42
|
+
self.resultEvents[id] = obj
|
|
43
|
+
self.loop.call_soon_threadsafe(lambda: self.call(id))
|
|
44
|
+
|
|
45
|
+
def call(self, id: int):
|
|
46
|
+
if id in self.asyncEvects.keys():
|
|
47
|
+
self.asyncEvects[id].set()
|
|
48
|
+
del self.asyncEvects[id]
|
|
49
|
+
print("清理"+str(id))
|
|
50
|
+
else:
|
|
51
|
+
print('无此id' + str(id))
|
|
52
|
+
|
|
53
|
+
# 定义一个用来处理错误的方法
|
|
54
|
+
def on_error(self, ws, error):
|
|
55
|
+
print("-----连接出现异常,异常信息如下-----")
|
|
56
|
+
print(error)
|
|
57
|
+
sys.exit()
|
|
58
|
+
|
|
59
|
+
# 定义一个用来处理关闭连接的方法
|
|
60
|
+
def on_close(self, ws, code, msg):
|
|
61
|
+
print("-------连接已关闭,退出运行------")
|
|
62
|
+
print(code)
|
|
63
|
+
self.ws.close()
|
|
64
|
+
self.clear_all_event()
|
|
65
|
+
sys.exit()
|
|
66
|
+
|
|
67
|
+
def sendmsg(self, msg: str):
|
|
68
|
+
if self.ws.sock != None:
|
|
69
|
+
self.ws.send(msg)
|
|
70
|
+
|
|
71
|
+
def run(self):
|
|
72
|
+
time.sleep(1)
|
|
73
|
+
# print('启动监听')
|
|
74
|
+
self.ws.run_forever()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
async def init(self):
|
|
78
|
+
print('初始化中...')
|
|
79
|
+
# 默认连接本机 Unity;Python 与 Unity 不在同一台电脑时,
|
|
80
|
+
# 设置环境变量 ICT_UNITY_WS=ws://<Unity电脑IP>:10088/cxx
|
|
81
|
+
unity_ws = os.environ.get("ICT_UNITY_WS", "ws://127.0.0.1:10088/cxx")
|
|
82
|
+
print('连接地址: ' + unity_ws)
|
|
83
|
+
self.ws = websocket.WebSocketApp(unity_ws,
|
|
84
|
+
on_open=self.om_open,
|
|
85
|
+
on_message=self.on_message,
|
|
86
|
+
on_error=self.on_error,
|
|
87
|
+
on_close=self.on_close,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
self.eventId = 0
|
|
91
|
+
self.asyncEvects[0] = asyncio.Event()
|
|
92
|
+
|
|
93
|
+
thread = threading.Thread(target=self.run)
|
|
94
|
+
thread.daemon = True
|
|
95
|
+
thread.start()
|
|
96
|
+
await self.asyncEvects[0].wait()
|
|
97
|
+
print('sdk版本检查中...')
|
|
98
|
+
obj = self.resultEvents[0]
|
|
99
|
+
del self.resultEvents[0]
|
|
100
|
+
# 检查sdk版本
|
|
101
|
+
if obj['result'] == SUCCESS:
|
|
102
|
+
print("sdk版本正确")
|
|
103
|
+
|
|
104
|
+
# 场景初始化
|
|
105
|
+
print('场景初始化中...')
|
|
106
|
+
self.eventId = 1
|
|
107
|
+
self.asyncEvects[1] = asyncio.Event()
|
|
108
|
+
self.sendmsg(json.dumps({'event_id': 1, 'type': 'other', 'commond': 'init_scene','language':'Python'}))
|
|
109
|
+
await self.asyncEvects[1].wait()
|
|
110
|
+
obj2 = self.resultEvents[1]
|
|
111
|
+
del self.resultEvents[1]
|
|
112
|
+
if obj2['result'] == SUCCESS:
|
|
113
|
+
print('场景初始化成功')
|
|
114
|
+
else:
|
|
115
|
+
print('场景初始化失败:' + obj2.get('msg'))
|
|
116
|
+
else:
|
|
117
|
+
print("sdk版本不匹配! 请更换版本,当前版本:" + Version)
|
|
118
|
+
self.ws.close()
|
|
119
|
+
sys.exit(1)
|
|
120
|
+
|
|
121
|
+
def do_wait_return(self, data: dict):
|
|
122
|
+
"""
|
|
123
|
+
发送消息并等待Unity程序返回结果
|
|
124
|
+
:param data:
|
|
125
|
+
"""
|
|
126
|
+
result = self.loop.run_until_complete(self.send_wait_return(data))
|
|
127
|
+
|
|
128
|
+
if result['result'] != FAILED_ERROR:
|
|
129
|
+
# if result.get('msg') is not None:
|
|
130
|
+
# print(result.get('msg'))
|
|
131
|
+
return result
|
|
132
|
+
else:
|
|
133
|
+
print(result.get('msg'))
|
|
134
|
+
self.ws.close()
|
|
135
|
+
sys.exit(1)
|
|
136
|
+
|
|
137
|
+
def do_immediately(self, data: dict):
|
|
138
|
+
"""
|
|
139
|
+
发送消息不等待Unity程序返回结果
|
|
140
|
+
:param data:
|
|
141
|
+
:return:
|
|
142
|
+
"""
|
|
143
|
+
asyncio.run(self.send_no_return(data))
|
|
144
|
+
|
|
145
|
+
async def send_wait_return(self, data: dict):
|
|
146
|
+
self.eventId += 1
|
|
147
|
+
__id = self.eventId
|
|
148
|
+
data['event_id'] = __id
|
|
149
|
+
self.asyncEvects[__id] = asyncio.Event()
|
|
150
|
+
self.sendmsg(json.dumps(data))
|
|
151
|
+
# print('开始等待事件%s结束' % __id)
|
|
152
|
+
await Core.asyncEvects[__id].wait()
|
|
153
|
+
obj = self.resultEvents[__id]
|
|
154
|
+
del self.resultEvents[__id]
|
|
155
|
+
return obj
|
|
156
|
+
|
|
157
|
+
async def send_no_return(self, data: dict):
|
|
158
|
+
self.eventId += 1
|
|
159
|
+
__id = self.eventId
|
|
160
|
+
data['event_id'] = __id
|
|
161
|
+
self.asyncEvects[__id] = asyncio.Event()
|
|
162
|
+
self.sendmsg(json.dumps(data))
|
|
163
|
+
|
|
164
|
+
def clear_all_event(self):
|
|
165
|
+
print("清理event")
|
|
166
|
+
keys=self.asyncEvects.copy().keys()
|
|
167
|
+
for id in keys:
|
|
168
|
+
self.loop.call_soon_threadsafe(lambda: self.call(id))
|
|
169
|
+
|
|
170
|
+
MyWS = Core()
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cqqz-agent
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: cqqz digital human Python control SDK (WebSocket control for Unity)
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
License: UNKNOWN
|
|
7
|
+
Platform: UNKNOWN
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Provides-Extra: document
|
|
10
|
+
|
|
11
|
+
# cqqz_agent
|
|
12
|
+
|
|
13
|
+
cqqz 数字人 Python 控制 SDK。从 ICT 数字人 SDK 的 `ict_agent` 中拆出数字人相关代码独立成包,接口与原包对应模块保持一致。
|
|
14
|
+
|
|
15
|
+
SDK 是 Unity 的控制客户端,不是独立的数字人渲染程序,也不包含 Python 端大模型推理服务。
|
|
16
|
+
|
|
17
|
+
## 包含的模块
|
|
18
|
+
|
|
19
|
+
| 模块 | 用途 |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `cqqz_agent.core` | WebSocket 连接、SDK 版本校验、请求与响应等待 |
|
|
22
|
+
| `cqqz_agent.DigitalHuman` | `DigtalHuman` 类:人物外观、动作、语音、直播、消防路线 |
|
|
23
|
+
| `cqqz_agent.Public` | 场景进入、截图、相机、公共音频、场景元素、PDF 投屏 |
|
|
24
|
+
| `cqqz_agent.Document` | PDF 逐页转 PNG(依赖 PyMuPDF,仅 PDF 投屏时用到) |
|
|
25
|
+
|
|
26
|
+
不包含 `Robot`、`UAV`、`Math` 等与数字人无关的模块。
|
|
27
|
+
|
|
28
|
+
## 安装
|
|
29
|
+
|
|
30
|
+
方式一:把 `cqqz_agent` 文件夹放到脚本同目录,直接 `import cqqz_agent`。
|
|
31
|
+
|
|
32
|
+
方式二:在本目录执行安装(推荐使用目标环境自己的虚拟环境):
|
|
33
|
+
|
|
34
|
+
```bat
|
|
35
|
+
python -m pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
数字人基础功能只依赖 `websocket-client`;使用 PDF 投屏时再安装 `PyMuPDF`
|
|
39
|
+
(或用 `python -m pip install .[document]`)。`dist/` 目录下的 wheel 可在目标机器离线安装:
|
|
40
|
+
|
|
41
|
+
```bat
|
|
42
|
+
python -m pip install dist\cqqz_agent-1.0.0-py3-none-any.whl
|
|
43
|
+
python -m pip install PyMuPDF
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 使用
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from cqqz_agent import Public
|
|
50
|
+
from cqqz_agent.DigitalHuman import DigtalHuman
|
|
51
|
+
|
|
52
|
+
if not Public.enter_scene("数字人舞台"):
|
|
53
|
+
raise SystemExit("进入场景失败")
|
|
54
|
+
|
|
55
|
+
human = DigtalHuman().init_human("Female")
|
|
56
|
+
human.set_name("小美")
|
|
57
|
+
human.play_text_content("大家好,我是数字人小美。")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- 首次导入 `cqqz_agent.DigitalHuman` 或 `cqqz_agent.Public` 就会连接 Unity 并初始化场景,导入前请先启动 Unity 并确认 10088 端口可用。
|
|
61
|
+
- 默认地址为 `ws://127.0.0.1:10088/cxx`。Python 与 Unity 不在同一台电脑时,在导入前设置环境变量:
|
|
62
|
+
|
|
63
|
+
```bat
|
|
64
|
+
set ICT_UNITY_WS=ws://192.168.0.192:10088/cxx
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- 类名 `DigtalHuman` 沿用了原 SDK 的拼写;`DigitalHuman` 是其别名,二者相同。
|
|
68
|
+
- 只运行一个控制脚本,不要求也不支持多个 Python 客户端同时控制。
|
|
69
|
+
- 在普通 `.py` 脚本主线程中顺序调用,不要放在已运行事件循环的 Notebook / 异步服务里。
|
|
70
|
+
|
|
71
|
+
## 与 ict_agent 的对应关系
|
|
72
|
+
|
|
73
|
+
| 原导入 | 新导入 |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `from ict_agent.DigitalHuman import DigtalHuman` | `from cqqz_agent.DigitalHuman import DigtalHuman` |
|
|
76
|
+
| `from ict_agent import Public` | `from cqqz_agent import Public` |
|
|
77
|
+
| `from ict_agent.Public import audio` | `from cqqz_agent.Public import audio` |
|
|
78
|
+
|
|
79
|
+
命令行接口与返回值规则不变,详见原 SDK 的《ICT 数字人 Python 使用手册》。
|
|
80
|
+
|
|
81
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.cfg
|
|
4
|
+
setup.py
|
|
5
|
+
cqqz_agent/DigitalHuman.py
|
|
6
|
+
cqqz_agent/Document.py
|
|
7
|
+
cqqz_agent/Public.py
|
|
8
|
+
cqqz_agent/__init__.py
|
|
9
|
+
cqqz_agent/core.py
|
|
10
|
+
cqqz_agent.egg-info/PKG-INFO
|
|
11
|
+
cqqz_agent.egg-info/SOURCES.txt
|
|
12
|
+
cqqz_agent.egg-info/dependency_links.txt
|
|
13
|
+
cqqz_agent.egg-info/requires.txt
|
|
14
|
+
cqqz_agent.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cqqz_agent
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = cqqz-agent
|
|
3
|
+
version = 1.0.0
|
|
4
|
+
description = cqqz digital human Python control SDK (WebSocket control for Unity)
|
|
5
|
+
long_description = file: README.md
|
|
6
|
+
long_description_content_type = text/markdown
|
|
7
|
+
requires_python = >=3.7
|
|
8
|
+
|
|
9
|
+
[options]
|
|
10
|
+
packages = cqqz_agent
|
|
11
|
+
install_requires =
|
|
12
|
+
websocket-client>=1.9.0
|
|
13
|
+
|
|
14
|
+
[options.extras_require]
|
|
15
|
+
document =
|
|
16
|
+
PyMuPDF>=1.23.0
|
|
17
|
+
|
|
18
|
+
[egg_info]
|
|
19
|
+
tag_build =
|
|
20
|
+
tag_date = 0
|
|
21
|
+
|