qt-human 2.2.0-alpha.9 → 2.3.1-alpha

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/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ import { ThreeJSON } from '@/types/model';
10
10
  import { QuanTe as QuanTe$2 } from '@/types';
11
11
  import Recorder from 'recorder-core';
12
12
  import { IResultData as IResultData$1 } from '@/api/interface';
13
+ import FramePlayer from '@/utils/framePlayer';
14
+ import { CameraConfig as CameraConfig$1 } from '@/types/camera';
13
15
 
14
16
  type ActionObjType = {
15
17
  action: THREE.AnimationAction;
@@ -70,7 +72,8 @@ declare class ThreeJSApp extends Emittery {
70
72
  gui: SceneGUI | null;
71
73
  bgScene: THREE.Scene | null;
72
74
  bgCamera: THREE.OrthographicCamera | null;
73
- constructor(container: (string | HTMLElement) | undefined, config: QuanTe$1.Model.Description);
75
+ private humanObj;
76
+ constructor(container: (string | HTMLElement) | undefined, config: QuanTe$1.Model.Description, humanObj: Human);
74
77
  init(): void;
75
78
  setContainer(): void;
76
79
  updateLight(): void;
@@ -107,6 +110,7 @@ declare class ThreeJSApp extends Emittery {
107
110
  startRender(): void;
108
111
  stopRender(): void;
109
112
  gsapMorph(target: number[], source: number[], t2: any): void;
113
+ private getDefaultAniCode;
110
114
  initIdle: lodash.DebouncedFunc<() => void>;
111
115
  playAction: lodash.DebouncedFuncLeading<(code: string, opts?: QuanTe$1.PlayActionOptions) => void>;
112
116
  stopAllActionExcludeIdle(): void;
@@ -269,13 +273,38 @@ declare class VoiceInteraction extends Emittery {
269
273
  private wakeWordDetection;
270
274
  private exitWordDetection;
271
275
  private interruptWordDetection;
272
- private onWakeDetected;
273
- private onSleepDetected;
276
+ onWakeDetected(): void;
277
+ onSleepDetected(): void;
274
278
  private onInterruptDetected;
275
279
  destroy(): void;
276
280
  }
277
281
  declare const _default: VoiceInteraction;
278
282
 
283
+ type FacingMode = "user" | "environment";
284
+
285
+ interface CameraConfig {
286
+ el: string | HTMLDivElement;
287
+ facingMode?: FacingMode; // 前/后摄像头
288
+ features?: string[]; // 功能列表 ["photo", "detection"]
289
+ overlayImage?: HTMLImageElement | null; // 合影 PNG
290
+ }
291
+
292
+ type ProximityState = 'near' | 'far' | 'stable';
293
+
294
+ declare class CameraSDK {
295
+ private manager;
296
+ private features;
297
+ private container;
298
+ private video;
299
+ constructor(config: CameraConfig);
300
+ open(): Promise<void>;
301
+ close(): void;
302
+ takePhoto(): Promise<string>;
303
+ switchCamera(facingMode: "user" | "environment"): Promise<void>;
304
+ detectPose(callback: (stable: ProximityState) => void): Promise<void>;
305
+ destroy(): void;
306
+ }
307
+
279
308
  declare class Human extends Emittery implements QuanTe$1.Human {
280
309
  name: string;
281
310
  core: ThreeJSApp | null;
@@ -297,8 +326,9 @@ declare class Human extends Emittery implements QuanTe$1.Human {
297
326
  private isNotRender;
298
327
  private mode;
299
328
  private ttsclient;
300
- private framePlayer;
329
+ framePlayer: FramePlayer | null;
301
330
  voiceInter: typeof _default;
331
+ camera: CameraSDK | null;
302
332
  constructor(config: QuanTe$1.Configuration);
303
333
  private refreshGatewayToken;
304
334
  private initTTSClient;
@@ -344,6 +374,8 @@ declare class Human extends Emittery implements QuanTe$1.Human {
344
374
  stopRender(): Promise<boolean>;
345
375
  closeRecorder(): Promise<boolean>;
346
376
  openRecorder(): Promise<QuanTe$1.Result<QuanTe$1.Recorder.PermissionResult>>;
377
+ openCamera(config: CameraConfig$1): Promise<boolean>;
378
+ wakeUp(isWake?: boolean): Promise<void>;
347
379
  }
348
380
 
349
381
  declare namespace QuanTe {
@@ -454,6 +486,8 @@ declare namespace QuanTe {
454
486
  public openVoiceInteraction(config: VoiceConfig): Promise<boolean>
455
487
  public closeRecorder(): Promise<boolean>
456
488
  public openRecorder(): Promise<QuanTe.Result<QuanTe.Recorder.PermissionResult>>
489
+ // 打开摄像头
490
+ public openCamera(config: CameraConfig): Promise<boolean>
457
491
  }
458
492
 
459
493
  export interface ModelInfo {
@@ -1039,6 +1073,8 @@ declare enum EmitEvent {
1039
1073
  AUDIO_PAUSE = 'audio.pause',
1040
1074
  // 播放音频
1041
1075
  AUDIO_PLAY = 'audio.play',
1076
+ // 摄像机人体检测结果
1077
+ CAMERA_PERSON_TEST_RESULT = 'camera.person.test.result'
1042
1078
  }
1043
1079
 
1044
1080
  export { EmitEvent, QuanTe, Human as default };
@@ -0,0 +1 @@
1
+ export declare const FeatureRegistry: Record<string, any>;
@@ -0,0 +1,15 @@
1
+ import type { CameraConfig } from "../../types/camera";
2
+ import { ProximityState } from './proximityDetector';
3
+ export declare class CameraSDK {
4
+ private manager;
5
+ private features;
6
+ private container;
7
+ private video;
8
+ constructor(config: CameraConfig);
9
+ open(): Promise<void>;
10
+ close(): void;
11
+ takePhoto(): Promise<string>;
12
+ switchCamera(facingMode: "user" | "environment"): Promise<void>;
13
+ detectPose(callback: (stable: ProximityState) => void): Promise<void>;
14
+ destroy(): void;
15
+ }
@@ -0,0 +1,12 @@
1
+ import type { FacingMode, CameraCore } from "../../types/camera";
2
+ export declare class MediaStreamManager implements CameraCore {
3
+ video: HTMLVideoElement;
4
+ private stream;
5
+ private facingMode;
6
+ constructor(video: HTMLVideoElement, facingMode?: FacingMode);
7
+ open(): Promise<void>;
8
+ close(): void;
9
+ switch(facingMode: FacingMode): Promise<void>;
10
+ getVideoEl(): HTMLVideoElement;
11
+ getStream(): MediaStream | null;
12
+ }
@@ -0,0 +1,7 @@
1
+ import type { CameraFeature, CameraCore } from "../../types/camera";
2
+ export declare class PhotoFeature implements CameraFeature {
3
+ name: string;
4
+ private overlay;
5
+ constructor(overlay?: HTMLImageElement | null);
6
+ takePhoto(camera: CameraCore): Promise<string>;
7
+ }
@@ -0,0 +1,15 @@
1
+ import * as posedetection from "@tensorflow-models/pose-detection";
2
+ import "@tensorflow/tfjs-backend-webgl";
3
+ import { MediaStreamManager } from "./mediaStream";
4
+ import { ProximityState } from "./proximityDetector";
5
+ export declare class PoseDetector {
6
+ private detector;
7
+ private mediaStrea;
8
+ private interval;
9
+ private proximityDetector;
10
+ constructor();
11
+ init(mediaStrea: MediaStreamManager): Promise<void>;
12
+ on(callback: (stable: ProximityState) => void): void;
13
+ detect(video: HTMLVideoElement): Promise<posedetection.Pose[]>;
14
+ destroy(): Promise<void>;
15
+ }
@@ -0,0 +1,11 @@
1
+ import { Keypoint } from '@tensorflow-models/pose-detection';
2
+ export type ProximityState = 'near' | 'far' | 'stable';
3
+ export declare class ProximityDetector {
4
+ private baselineWidth;
5
+ private lastState;
6
+ private threshold;
7
+ private callback?;
8
+ constructor(threshold?: number);
9
+ onChange(callback: (state: ProximityState) => void): void;
10
+ update(keypoints: Keypoint[]): void;
11
+ }
@@ -6,6 +6,7 @@ import Emittery from 'emittery';
6
6
  import type { QuanTe } from '@/types/index';
7
7
  import { SceneGUI } from '@/utils/sceneGUI';
8
8
  import type { ThreeJSON } from '@/types/model';
9
+ import Human from '../human';
9
10
  type ActionObjType = {
10
11
  action: THREE.AnimationAction;
11
12
  name: string;
@@ -65,7 +66,8 @@ declare class ThreeJSApp extends Emittery {
65
66
  gui: SceneGUI | null;
66
67
  bgScene: THREE.Scene | null;
67
68
  bgCamera: THREE.OrthographicCamera | null;
68
- constructor(container: (string | HTMLElement) | undefined, config: QuanTe.Model.Description);
69
+ private humanObj;
70
+ constructor(container: (string | HTMLElement) | undefined, config: QuanTe.Model.Description, humanObj: Human);
69
71
  init(): void;
70
72
  setContainer(): void;
71
73
  updateLight(): void;
@@ -102,6 +104,7 @@ declare class ThreeJSApp extends Emittery {
102
104
  startRender(): void;
103
105
  stopRender(): void;
104
106
  gsapMorph(target: number[], source: number[], t2: any): void;
107
+ private getDefaultAniCode;
105
108
  initIdle: import("lodash").DebouncedFunc<() => void>;
106
109
  playAction: import("lodash").DebouncedFuncLeading<(code: string, opts?: QuanTe.PlayActionOptions) => void>;
107
110
  stopAllActionExcludeIdle(): void;
@@ -37,8 +37,8 @@ declare class VoiceInteraction extends Emittery {
37
37
  private wakeWordDetection;
38
38
  private exitWordDetection;
39
39
  private interruptWordDetection;
40
- private onWakeDetected;
41
- private onSleepDetected;
40
+ onWakeDetected(): void;
41
+ onSleepDetected(): void;
42
42
  private onInterruptDetected;
43
43
  destroy(): void;
44
44
  }
@@ -5,6 +5,9 @@ import Recorder from './core/recorder';
5
5
  import type { QuanTe } from '@/types/index';
6
6
  import { IResultData } from '@/api/interface';
7
7
  import voiceInteraction from './core/voice-interaction';
8
+ import FramePlayer from '@/utils/framePlayer';
9
+ import { CameraConfig } from '@/types/camera';
10
+ import { CameraSDK } from './camera';
8
11
  declare class Human extends Emittery implements QuanTe.Human {
9
12
  name: string;
10
13
  core: ThreeJSApp | null;
@@ -26,8 +29,9 @@ declare class Human extends Emittery implements QuanTe.Human {
26
29
  private isNotRender;
27
30
  private mode;
28
31
  private ttsclient;
29
- private framePlayer;
32
+ framePlayer: FramePlayer | null;
30
33
  voiceInter: typeof voiceInteraction;
34
+ camera: CameraSDK | null;
31
35
  constructor(config: QuanTe.Configuration);
32
36
  private refreshGatewayToken;
33
37
  private initTTSClient;
@@ -73,6 +77,8 @@ declare class Human extends Emittery implements QuanTe.Human {
73
77
  stopRender(): Promise<boolean>;
74
78
  closeRecorder(): Promise<boolean>;
75
79
  openRecorder(): Promise<QuanTe.Result<QuanTe.Recorder.PermissionResult>>;
80
+ openCamera(config: CameraConfig): Promise<boolean>;
81
+ wakeUp(isWake?: boolean): Promise<void>;
76
82
  }
77
83
  export default Human;
78
84
  export type { QuanTe };
@@ -0,0 +1,19 @@
1
+ export type FacingMode = "user" | "environment";
2
+
3
+ export interface CameraConfig {
4
+ el: string | HTMLDivElement;
5
+ facingMode?: FacingMode; // 前/后摄像头
6
+ features?: string[]; // 功能列表 ["photo", "detection"]
7
+ overlayImage?: HTMLImageElement | null; // 合影 PNG
8
+ }
9
+
10
+ export interface CameraFeature {
11
+ name: string;
12
+ init?(camera: CameraCore): Promise<void> | void;
13
+ destroy?(): Promise<void> | void;
14
+ }
15
+
16
+ export interface CameraCore {
17
+ getVideoEl(): HTMLVideoElement;
18
+ getStream(): MediaStream | null;
19
+ }
@@ -16,5 +16,6 @@ export declare enum EmitEvent {
16
16
  WAKE_RECORDER_START = "wake.record.start",
17
17
  WAKE_RECORDER_STOP = "wake.record.stop",
18
18
  AUDIO_PAUSE = "audio.pause",
19
- AUDIO_PLAY = "audio.play"
19
+ AUDIO_PLAY = "audio.play",
20
+ CAMERA_PERSON_TEST_RESULT = "camera.person.test.result"
20
21
  }
@@ -35,4 +35,6 @@ export enum EmitEvent {
35
35
  AUDIO_PAUSE = 'audio.pause',
36
36
  // 播放音频
37
37
  AUDIO_PLAY = 'audio.play',
38
+ // 摄像机人体检测结果
39
+ CAMERA_PERSON_TEST_RESULT = 'camera.person.test.result'
38
40
  }
@@ -1,6 +1,7 @@
1
1
  import { API } from "./api";
2
2
  import * as THREE from 'three'
3
3
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
4
+ import { CameraConfig } from "./camera";
4
5
 
5
6
  export namespace QuanTe {
6
7
  export type Character = 'xiaomeng' | 'custom' | 'quan' | 'doctor' | 'boy' | 'girl' | '';
@@ -110,6 +111,8 @@ export namespace QuanTe {
110
111
  public openVoiceInteraction(config: VoiceConfig): Promise<boolean>
111
112
  public closeRecorder(): Promise<boolean>
112
113
  public openRecorder(): Promise<QuanTe.Result<QuanTe.Recorder.PermissionResult>>
114
+ // 打开摄像头
115
+ public openCamera(config: CameraConfig): Promise<boolean>
113
116
  }
114
117
 
115
118
  export interface ModelInfo {
@@ -24,5 +24,6 @@ export default class FramePlayer extends Emittery {
24
24
  getPlayInfo(): QuanTe.API.StreamAudioPlayInfo;
25
25
  setAudioRate(rate: number): Promise<void>;
26
26
  private mergeArrayBuffers;
27
+ getPlayingStatus(): boolean;
27
28
  }
28
29
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qt-human",
3
- "version": "2.2.0-alpha.9",
3
+ "version": "2.3.1-alpha",
4
4
  "main": "dist/bundle.umd.js",
5
5
  "module": "dist/bundle.esm.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -57,6 +57,13 @@
57
57
  "web-streams-polyfill": "^4.0.0"
58
58
  },
59
59
  "dependencies": {
60
+ "@mediapipe/pose": "^0.5.1675469404",
61
+ "@tensorflow-models/pose-detection": "^2.1.3",
62
+ "@tensorflow/tfjs-backend-cpu": "^4.22.0",
63
+ "@tensorflow/tfjs-backend-webgl": "^4.22.0",
64
+ "@tensorflow/tfjs-backend-webgpu": "^4.22.0",
65
+ "@tensorflow/tfjs-converter": "^4.22.0",
66
+ "@tensorflow/tfjs-core": "^4.22.0",
60
67
  "axios": "^1.7.2",
61
68
  "crypto-js": "^4.2.0",
62
69
  "emittery": "^1.0.3",