g-ai-robot3 0.1.44 → 0.1.46

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.
package/README.md CHANGED
@@ -20,7 +20,114 @@ import "g-ai-robot3/dist/g-ai-robot3.css"
20
20
  placement="top-end"
21
21
  >
22
22
  </g-ai-robot>
23
-
23
+ //添加到引用组件的代码中(不在组件中引入)
24
+ const video = ref(null);
25
+ const canvas = ref(null);
26
+ const ctx = ref(null);
27
+ const canvas_tmp = ref(null);
28
+ const ctx_tmp = ref(null);
29
+
30
+ const init = () => {
31
+ ctx.value = canvas.value.getContext('2d');
32
+
33
+ // 创建的canvas宽高最好与显示图片的canvas、video宽高一致
34
+ canvas_tmp.value = document.createElement('canvas');
35
+ canvas_tmp.value.setAttribute('width', 300);
36
+ canvas_tmp.value.setAttribute('height', 300);
37
+ ctx_tmp.value = canvas_tmp.value.getContext('2d');
38
+
39
+ video.value.addEventListener('play', computeFrame);
40
+ }
41
+
42
+ const numToPoint = (num, width) => {
43
+ let col = num % width;
44
+ let row = Math.floor(num / width);
45
+ row = col === 0 ? row : row + 1;
46
+ col = col === 0 ? width : col;
47
+ return [row, col];
48
+ }
49
+
50
+ const pointToNum = (point, width) => {
51
+ let [row, col] = point;
52
+ return (row - 1) * width + col
53
+ }
54
+
55
+ const getAroundPoint = (point, width, height, area) => {
56
+ let [row, col] = point;
57
+ let allAround = [];
58
+ if (row > height || col > width || row < 0 || col < 0) return allAround;
59
+ for (let i = 0; i < area; i++) {
60
+ let pRow = row - 1 + i;
61
+ for (let j = 0; j < area; j++) {
62
+ let pCol = col - 1 + j;
63
+ if (i === area % 2 && j === area % 2) continue;
64
+ allAround.push([pRow, pCol]);
65
+ }
66
+ }
67
+ return allAround.filter(([iRow, iCol]) => {
68
+ return (iRow > 0 && iCol > 0) && (iRow <= height && iCol <= width);
69
+ })
70
+ }
71
+
72
+ const computeFrame = () => {
73
+ if (video.value) {
74
+ if (video.value.paused || video.value.ended) return;
75
+ }
76
+ // 如果视频比例和canvas比例不正确可能会出现显示形变, 调整除的值进行比例调整
77
+ ctx_tmp.value.drawImage(video.value, 0, 0, video.value.clientWidth / 1, video.value.clientHeight / 1);
78
+
79
+ // 获取到绘制的canvas的所有像素rgba值组成的数组
80
+ let frame = ctx_tmp.value.getImageData(0, 0, video.value.clientWidth, video.value.clientHeight);
81
+
82
+ //----- emergence ----------
83
+ const height = frame.height;
84
+ const width = frame.width;
85
+ const pointLens = frame.data.length / 4;
86
+
87
+
88
+ for (let i = 0; i < pointLens; i++) {
89
+ let r = frame.data[i * 4];
90
+ let g = frame.data[i * 4 + 1];
91
+ let b = frame.data[i * 4 + 2];
92
+ if (r < 100 && g > 190 && b < 200) {
93
+ frame.data[i * 4 + 3] = 0;
94
+ }
95
+ }
96
+
97
+ const tempData = [...frame.data]
98
+ for (let i = 0; i < pointLens; i++) {
99
+ if (frame.data[i * 4 + 3] === 0) continue
100
+ const currentPoint = numToPoint(i + 1, width);
101
+ const arroundPoint = getAroundPoint(currentPoint, width, height, 3);
102
+ let opNum = 0;
103
+ let rSum = 0;
104
+ let gSum = 0;
105
+ let bSum = 0;
106
+ arroundPoint.forEach((position) => {
107
+ const index = pointToNum(position, width);
108
+ rSum = rSum + tempData[(index - 1) * 4];
109
+ gSum = gSum + tempData[(index - 1) * 4 + 1];
110
+ bSum = bSum + tempData[(index - 1) * 4 + 2];
111
+ if (tempData[(index - 1) * 4 + 3] !== 255) opNum++;
112
+ })
113
+ let alpha = (255 / arroundPoint.length) * (arroundPoint.length - opNum);
114
+ if (alpha !== 255) {
115
+ // debugger
116
+ frame.data[i * 4] = parseInt(rSum / arroundPoint.length);
117
+ frame.data[i * 4 + 1] = parseInt(gSum / arroundPoint.length);
118
+ frame.data[i * 4 + 2] = parseInt(bSum / arroundPoint.length);
119
+ frame.data[i * 4 + 3] = parseInt(alpha);
120
+ }
121
+ }
122
+
123
+ //------------------------
124
+ ctx.value.putImageData(frame, 0, 0);
125
+ setTimeout(computeFrame, 0);
126
+ }
127
+
128
+ onMounted(() => {
129
+ init();
130
+ })
24
131
  ```
25
132
 
26
133
 
@@ -77,6 +184,3 @@ import "g-ai-robot3/dist/g-ai-robot3.css"
77
184
  |---------- |--------------|
78
185
  | reference | 触发问答弹窗显示的HTML元素 |
79
186
 
80
-
81
-
82
-
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "g-ai-robot3",
3
3
  "private": false,
4
- "version": "0.1.44",
4
+ "version": "0.1.46",
5
5
  "type": "module",
6
6
  "main": "dist/g-ai-robot3.js",
7
7
  "module": "dist/g-ai-robot3.es.js",
@@ -1,25 +0,0 @@
1
- /**
2
- * Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights
3
- * Reserved. MIT License (https://opensource.org/licenses/MIT)
4
- */
5
- type Mode = '2pass' | 'offline';
6
- export default class WebSocketConnectMethod {
7
- private speechSokt;
8
- private msgHandle;
9
- private stateHandle;
10
- private url;
11
- private mode;
12
- constructor(config: {
13
- msgHandle: (jsonMsg: any) => void;
14
- stateHandle: (connState: (0 | 1 | 2)) => void;
15
- url?: string;
16
- });
17
- wsStart(modeStr?: Mode): 0 | 1;
18
- wsStop(): void;
19
- wsSend(data: any): void;
20
- onOpen(): void;
21
- onClose(e: any): void;
22
- onMessage(e: any): void;
23
- onError(e: any): void;
24
- }
25
- export {};