@bdky/aaas-pilot-kit 1.0.4 → 1.0.5

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.
Files changed (26) hide show
  1. package/dist/http.cjs.js +1 -1
  2. package/dist/http.esm.js +1 -1
  3. package/dist/http.umd.js +1 -1
  4. package/dist/index.cjs.js +30 -21
  5. package/dist/index.esm.js +29 -20
  6. package/dist/index.umd.js +30 -21
  7. package/dist/ky-aaas-pilot-kit.umd.js +30 -21
  8. package/dist/libs/aaas-pilot-kit/src/index.d.ts +2 -0
  9. package/dist/libs/aaas-pilot-kit/src/lib/controller.d.ts +40 -2
  10. package/dist/libs/aaas-pilot-kit/src/lib/error/codes.d.ts +6 -0
  11. package/dist/libs/aaas-pilot-kit/src/lib/error/services/AsrError.d.ts +18 -0
  12. package/dist/libs/aaas-pilot-kit/src/lib/service/agent/agentResponse.d.ts +174 -0
  13. package/dist/libs/aaas-pilot-kit/src/lib/service/agent/aiobAgentService.d.ts +1 -1
  14. package/dist/libs/aaas-pilot-kit/src/lib/service/agent/baseAgentService.d.ts +20 -2
  15. package/dist/libs/aaas-pilot-kit/src/lib/service/agent/cspAgentService.d.ts +1 -1
  16. package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/BaseDigitalHumanService.d.ts +16 -0
  17. package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/CloudDigitalHumanService.d.ts +12 -0
  18. package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/CloudNativeDigitalHumanService.d.ts +134 -0
  19. package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/PictureClientDigitalHumanService.d.ts +18 -0
  20. package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/asr/baseAsrService.d.ts +38 -3
  21. package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/asr/brtcAsrService.d.ts +2 -2
  22. package/dist/libs/aaas-pilot-kit/src/lib/utils/AudioDeviceDetector.d.ts +138 -0
  23. package/dist/libs/aaas-pilot-kit/src/lib/utils/agentResponseHelper.d.ts +42 -0
  24. package/dist/libs/aaas-pilot-kit/src/lib/utils/language-mapper.d.ts +70 -0
  25. package/dist/libs/aaas-pilot-kit/src/types/config.d.ts +175 -21
  26. package/package.json +7 -4
@@ -3,3 +3,5 @@ export * from './types/config';
3
3
  export * from './lib/service/conversation';
4
4
  export * from './lib/aaas-pilot-kit';
5
5
  export * from './lib/controller';
6
+ export { AudioDeviceDetector, AudioDeviceError, getErrorMessage, checkAudioDevice, type AudioDeviceCheckResult, type AudioDetectorOptions } from './lib/utils/AudioDeviceDetector';
7
+ export { subscribeAgentResponse, type ISubscribeAgentResponseOptions } from './lib/utils/agentResponseHelper';
@@ -5,6 +5,7 @@ import { BaseDigitalHumanService } from './service/digital-human/BaseDigitalHuma
5
5
  import { ConversationService } from './service/conversation';
6
6
  import { ErrorManager } from './error';
7
7
  import type { IResolvedOptions, IAaaSPilotKitController, IAaaSPilotKitEmitter } from '../types/config';
8
+ import { AgentResponse } from './service/agent/agentResponse';
8
9
  export interface IAsrMessageEventPayload {
9
10
  text: string;
10
11
  completed: boolean;
@@ -21,7 +22,11 @@ export interface IInterruptEventPayload {
21
22
  queryId?: string;
22
23
  sessionId?: string;
23
24
  }
24
- export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAgentService> implements IAaaSPilotKitController {
25
+ type ExtractResponseType<P> = P extends BaseAgentService<infer R, any> ? R : never;
26
+ export interface IReplyStartEventPayload<AS extends BaseAgentService = BaseAgentService> {
27
+ agentResponse: AgentResponse<ExtractResponseType<AS>> | null;
28
+ }
29
+ export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAgentService> implements IAaaSPilotKitController<AS> {
25
30
  private readonly opts;
26
31
  private readonly errorManager;
27
32
  readonly agentService: AS;
@@ -29,11 +34,13 @@ export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAg
29
34
  private readonly digitalHumanService;
30
35
  readonly conversationService: ConversationService;
31
36
  static ENTRY_EMITTER_NAME: string;
32
- emitter: Emittery<IAaaSPilotKitEmitter>;
37
+ emitter: Emittery<IAaaSPilotKitEmitter<AS>>;
33
38
  interruptible: boolean;
34
39
  private isRenderingMultiModConversation;
35
40
  private isDigitalHumanServiceReady;
36
41
  private isAsrServiceReady;
42
+ /** 缓存上一次触发reply_start时的requestId */
43
+ private lastReplyStartRequestId;
37
44
  /** 缓存最新一条agent消息 */
38
45
  private aiWorkerMessageCache;
39
46
  /** 用于中断渲染中的多模态消息的signal */
@@ -70,6 +77,31 @@ export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAg
70
77
  input: (text: string) => IAaaSPilotKitController;
71
78
  dispose: () => IAaaSPilotKitController;
72
79
  setInterruptible: (interruptible: boolean) => IAaaSPilotKitController;
80
+ /**
81
+ * 🎙️ 检查音频设备可用性
82
+ *
83
+ * 执行 4 层渐进式检测:
84
+ * - Level 1: API 支持检查 (MediaDevices API)
85
+ * - Level 2: 设备枚举 (enumerateDevices)
86
+ * - Level 3: 权限状态查询 (Permissions API)
87
+ * - Level 4: 实际流获取 (getUserMedia + 轨道状态)
88
+ *
89
+ * @param options 检测配置选项
90
+ * @returns 检测结果
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const result = await controller.checkAudioDevice();
95
+ * if (!result.available) {
96
+ * alert(getErrorMessage(result.error));
97
+ * }
98
+ * ```
99
+ */
100
+ checkAudioDevice: (options?: {
101
+ timeout?: number;
102
+ autoCleanup?: boolean;
103
+ forceCheck?: boolean;
104
+ }) => Promise<import("./utils/AudioDeviceDetector").AudioDeviceCheckResult>;
73
105
  private readonly bindAsrServiceEvents;
74
106
  private readonly bindAgentServiceEvents;
75
107
  private readonly bindDigitalHumanServiceEvents;
@@ -93,6 +125,11 @@ export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAg
93
125
  * 处理asr消息
94
126
  */
95
127
  private readonly handleAsrMessage;
128
+ /**
129
+ * 处理设备检测完成事件
130
+ * 聚合 ASR 服务的设备检测结果,添加用户友好的错误提示,并对外发布
131
+ */
132
+ private readonly handleDeviceCheckCompleted;
96
133
  /**
97
134
  * 处理client conversation
98
135
  */
@@ -105,3 +142,4 @@ export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAg
105
142
  private readonly checkServiceReady;
106
143
  private readonly handleAIWorkerConversationChange;
107
144
  }
145
+ export {};
@@ -29,6 +29,12 @@ export declare const ERROR_CODES: {
29
29
  readonly ASR_MUTE_FAILED: "3012";
30
30
  readonly ASR_MESSAGE_INTERVAL_TIMEOUT: "3013";
31
31
  readonly ASR_RUNTIME_ERROR: "3014";
32
+ readonly ASR_DEVICE_API_NOT_SUPPORTED: "3100";
33
+ readonly ASR_DEVICE_INSECURE_CONTEXT: "3101";
34
+ readonly ASR_DEVICE_ENUMERATION_FAILED: "3102";
35
+ readonly ASR_DEVICE_PERMISSION_DISMISSED: "3103";
36
+ readonly ASR_DEVICE_OCCUPIED: "3104";
37
+ readonly ASR_DEVICE_CHECK_TIMEOUT: "3105";
32
38
  readonly DH_MOUNT_FAILED: "4001";
33
39
  readonly DH_IFRAME_LOAD_ERROR: "4002";
34
40
  readonly DH_RENDER_ERROR: "4003";
@@ -24,3 +24,21 @@ export declare class AsrMessageIntervalTimeoutError extends AsrError {
24
24
  export declare class AsrRuntimeError extends AsrError {
25
25
  constructor(message?: string, metadata?: Partial<IErrorMetadata>);
26
26
  }
27
+ export declare class AsrDeviceNotFoundError extends AsrError {
28
+ constructor(message?: string, metadata?: Partial<IErrorMetadata>);
29
+ }
30
+ export declare class AsrDeviceOccupiedError extends AsrError {
31
+ constructor(message?: string, metadata?: Partial<IErrorMetadata>);
32
+ }
33
+ export declare class AsrDeviceApiNotSupportedError extends AsrError {
34
+ constructor(message?: string, metadata?: Partial<IErrorMetadata>);
35
+ }
36
+ export declare class AsrDeviceInsecureContextError extends AsrError {
37
+ constructor(message?: string, metadata?: Partial<IErrorMetadata>);
38
+ }
39
+ export declare class AsrDevicePermissionDismissedError extends AsrError {
40
+ constructor(message?: string, metadata?: Partial<IErrorMetadata>);
41
+ }
42
+ export declare class AsrDeviceCheckTimeoutError extends AsrError {
43
+ constructor(message?: string, metadata?: Partial<IErrorMetadata>);
44
+ }
@@ -0,0 +1,174 @@
1
+ import Emittery from 'emittery';
2
+ export interface IEventWithSessionIdPayload {
3
+ sessionId: string;
4
+ queryId?: string;
5
+ }
6
+ export declare namespace NAgentResponse {
7
+ interface IUpdateEventPayload<T> extends IEventWithSessionIdPayload {
8
+ response: AgentResponse<T>;
9
+ }
10
+ interface IEmitter<T> {
11
+ update: IUpdateEventPayload<T>;
12
+ }
13
+ }
14
+ export interface IResponseChunkRaw<T = any> {
15
+ data: T;
16
+ index: number;
17
+ }
18
+ export interface IAgentResponseRaw<T = any> {
19
+ id: string;
20
+ sessionId: string;
21
+ queryId: string;
22
+ startTime: number;
23
+ endTime: number;
24
+ duration: number;
25
+ isCompleted: boolean;
26
+ chunks: Array<IResponseChunkRaw<T>>;
27
+ fullText: string;
28
+ }
29
+ /**
30
+ * 响应 Chunk 基类
31
+ * 代表流式响应中的单个数据块
32
+ */
33
+ export declare class ResponseChunk<T = any> {
34
+ /**
35
+ * chunk 的原始数据
36
+ */
37
+ readonly data: T;
38
+ /**
39
+ * chunk 的序号
40
+ */
41
+ readonly index: number;
42
+ constructor(data: T, index: number);
43
+ /**
44
+ * 获取 chunk 的文本内容
45
+ * 子类可以重写此方法来提取特定格式的文本
46
+ */
47
+ getText: () => string;
48
+ /**
49
+ * 将 chunk 转换为 JSON 对象
50
+ */
51
+ toJSON: () => IResponseChunkRaw<T>;
52
+ }
53
+ /**
54
+ * Agent 响应类
55
+ * 维护单次完整回复的所有 chunks
56
+ */
57
+ export declare class AgentResponse<T = unknown> {
58
+ readonly emitter: Emittery<NAgentResponse.IEmitter<T>, NAgentResponse.IEmitter<T> & import("emittery").OmnipresentEventData, never>;
59
+ /**
60
+ * 响应的唯一标识
61
+ */
62
+ readonly id: string;
63
+ /**
64
+ * 关联的 session ID
65
+ */
66
+ readonly sessionId: string;
67
+ /**
68
+ * 关联的 query ID
69
+ */
70
+ readonly queryId: string;
71
+ /**
72
+ * 响应开始时间
73
+ */
74
+ readonly startTime: number;
75
+ /**
76
+ * 响应结束时间
77
+ */
78
+ private _endTime;
79
+ /**
80
+ * 响应是否完成
81
+ */
82
+ private _isCompleted;
83
+ /**
84
+ * 所有 chunks 的列表
85
+ */
86
+ private readonly chunks;
87
+ constructor(sessionId: string, queryId: string);
88
+ /**
89
+ * 获取结束时间
90
+ */
91
+ get endTime(): number;
92
+ /**
93
+ * 添加一个 chunk
94
+ */
95
+ appendChunk: (chunk: ResponseChunk<T>) => void;
96
+ /**
97
+ * 标记响应完成
98
+ */
99
+ complete: () => void;
100
+ /**
101
+ * 获取所有 chunks
102
+ */
103
+ getChunks: () => Array<ResponseChunk<T>>;
104
+ /**
105
+ * 获取完整的文本内容
106
+ */
107
+ getFullText: () => string;
108
+ /**
109
+ * 获取响应时长(毫秒)
110
+ */
111
+ getDuration: () => number;
112
+ /**
113
+ * 检查响应是否完成
114
+ */
115
+ isCompleted: () => boolean;
116
+ /**
117
+ * 转换为 JSON 对象
118
+ */
119
+ toJSON: () => IAgentResponseRaw<T>;
120
+ /**
121
+ * 转换为字符串
122
+ */
123
+ toString: () => string;
124
+ }
125
+ /**
126
+ * 响应列表管理器
127
+ * 用于管理多个 AgentResponse
128
+ */
129
+ export declare class ResponseManager<T = unknown> {
130
+ /**
131
+ * 当前正在构建的响应
132
+ */
133
+ protected currentResponse: AgentResponse<T> | null;
134
+ /**
135
+ * 所有响应的列表
136
+ */
137
+ private responses;
138
+ /**
139
+ * 最大保存的响应数量
140
+ * 0 表示不限制
141
+ */
142
+ private readonly maxSize;
143
+ constructor(maxSize?: number);
144
+ onResponse: (rawResponse: T, sessionId: string, queryId: string) => void;
145
+ onComplete: () => void;
146
+ /**
147
+ * 获取所有响应
148
+ */
149
+ getResponses: () => Array<AgentResponse<T>>;
150
+ /**
151
+ * 根据 ID 获取响应
152
+ */
153
+ getResponseById: (id: string) => AgentResponse<T> | undefined;
154
+ /**
155
+ * 根据 queryId 获取响应
156
+ */
157
+ getResponseByQueryId: (queryId: string) => AgentResponse<T> | undefined;
158
+ /**
159
+ * 获取最后一个响应
160
+ */
161
+ getLastResponse: () => AgentResponse<T> | null;
162
+ /**
163
+ * 清空所有响应
164
+ */
165
+ clear: () => void;
166
+ /**
167
+ * 转换为 JSON 数组
168
+ */
169
+ toJSON: () => Array<IAgentResponseRaw<T>>;
170
+ /**
171
+ * 添加一个响应
172
+ */
173
+ private readonly addResponse;
174
+ }
@@ -61,7 +61,7 @@ export declare namespace NAiobAgentService {
61
61
  llm = 1
62
62
  }
63
63
  }
64
- export declare class AiobAgentService extends BaseAgentService {
64
+ export declare class AiobAgentService extends BaseAgentService<NAiobAgentService.IConversationSSEMessage> {
65
65
  static REQUEST_URI: string;
66
66
  query: (text: string) => Promise<void>;
67
67
  hangup: () => Promise<void>;
@@ -2,6 +2,7 @@ import Emittery from 'emittery';
2
2
  import { CommonRequest } from '../../api/request';
3
3
  import type { IResolvedOptions } from '../../../types/config';
4
4
  import { ErrorManager } from '../../error';
5
+ import { ResponseManager, AgentResponse } from './agentResponse';
5
6
  export declare namespace NBaseAgentService {
6
7
  interface IEventWithSessionIdPayload {
7
8
  sessionId: string;
@@ -13,6 +14,9 @@ export declare namespace NBaseAgentService {
13
14
  interface IInstructionReceivedEventPayload extends IEventWithSessionIdPayload {
14
15
  instruction: Record<string, Record<string, any>>;
15
16
  }
17
+ interface IResponseEventPayload<R = any> extends IEventWithSessionIdPayload {
18
+ response: AgentResponse<R>;
19
+ }
16
20
  type IHangupEventPayload = IEventWithSessionIdPayload;
17
21
  type ICompletedEventPayload = IEventWithSessionIdPayload;
18
22
  interface IEmitter {
@@ -21,11 +25,12 @@ export declare namespace NBaseAgentService {
21
25
  timeout: IEventWithSessionIdPayload;
22
26
  hangup: IHangupEventPayload;
23
27
  instruction_received: IInstructionReceivedEventPayload;
28
+ response: IResponseEventPayload;
24
29
  quota_expired: IEventWithSessionIdPayload;
25
30
  usage_quota_reached: IEventWithSessionIdPayload;
26
31
  }
27
32
  }
28
- export declare abstract class BaseAgentService<E extends NBaseAgentService.IEmitter = NBaseAgentService.IEmitter> {
33
+ export declare abstract class BaseAgentService<R = any, E extends NBaseAgentService.IEmitter = NBaseAgentService.IEmitter> {
29
34
  readonly request: CommonRequest;
30
35
  readonly errorManager: ErrorManager;
31
36
  readonly opts: IResolvedOptions;
@@ -33,17 +38,29 @@ export declare abstract class BaseAgentService<E extends NBaseAgentService.IEmit
33
38
  protected conversationSessionId: string;
34
39
  protected abortController: AbortController | null;
35
40
  /**
36
- * 每一轮query的id,用于区分不同的query
41
+ * 每一轮query的id,用于区分不同的query
37
42
  */
38
43
  protected _queryId: string;
39
44
  /**
40
45
  * 上一轮的query id
41
46
  */
42
47
  protected _lastQueryId: string;
48
+ /**
49
+ * 响应管理器,维护所有 Agent 回复
50
+ */
51
+ protected responseManager: ResponseManager<R>;
43
52
  constructor(request: CommonRequest, errorManager: ErrorManager, opts: IResolvedOptions);
44
53
  get sessionId(): string;
45
54
  get queryId(): string;
46
55
  get lastQueryId(): string;
56
+ /**
57
+ * 获取所有响应
58
+ */
59
+ getResponses(): ReadonlyArray<AgentResponse<R>>;
60
+ /**
61
+ * 获取响应管理器
62
+ */
63
+ getResponseManager(): ResponseManager<R>;
47
64
  setSessionId: (sessionId: string) => void;
48
65
  setQueryId: (queryId: string) => void;
49
66
  setLastQueryId: (queryId: string) => void;
@@ -57,6 +74,7 @@ export declare abstract class BaseAgentService<E extends NBaseAgentService.IEmit
57
74
  protected onHangup: (payload: E["hangup"]) => void;
58
75
  protected onTimeout: (payload: E["timeout"]) => void;
59
76
  protected onInstructionReceived: (payload: E["instruction_received"]) => void;
77
+ protected onResponse: (response: R) => void;
60
78
  protected onUsageQuotaReached: (payload: E["usage_quota_reached"]) => void;
61
79
  protected onQuotaExpired: (payload: E["quota_expired"]) => void;
62
80
  protected _dispose: () => void;
@@ -83,7 +83,7 @@ export declare namespace NCspAgentService {
83
83
  thumbDetail?: string;
84
84
  }
85
85
  }
86
- export declare class CspAgentService extends BaseAgentService {
86
+ export declare class CspAgentService extends BaseAgentService<NCspAgentService.IConversationSSEMessage> {
87
87
  static REQUEST_URI: string;
88
88
  query: (text: string) => Promise<void>;
89
89
  dispose: () => void;
@@ -58,5 +58,21 @@ export declare abstract class BaseDigitalHumanService {
58
58
  abstract sendSilenceMessage(): this;
59
59
  abstract dispose(): this;
60
60
  abstract GetRequestId(): string;
61
+ /**
62
+ * 取消静音
63
+ */
64
+ abstract cancelMute(): void | Promise<void>;
65
+ /**
66
+ * 静音数字人
67
+ */
68
+ abstract muteHuman(): void | Promise<void>;
69
+ /**
70
+ * 恢复播放
71
+ */
72
+ abstract play(): void | Promise<void>;
73
+ /**
74
+ * 暂停播放
75
+ */
76
+ abstract pause(): void | Promise<void>;
61
77
  protected abstract checkIsReady(): boolean;
62
78
  }
@@ -72,6 +72,18 @@ export declare class CloudDigitalHumanService extends BaseDigitalHumanService {
72
72
  bindEvents: () => this;
73
73
  unbindEvents: () => this;
74
74
  cancelMute: () => void;
75
+ /**
76
+ * 静音数字人
77
+ */
78
+ muteHuman: () => void;
79
+ /**
80
+ * 恢复播放
81
+ */
82
+ play: () => Promise<void>;
83
+ /**
84
+ * 暂停播放
85
+ */
86
+ pause: () => void;
75
87
  renderPlainText: (text: string) => this;
76
88
  renderStreamText: (text: string, hasEnded?: boolean) => this;
77
89
  interrupt: () => this;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @file 数字人服务 - npm 包方式实现(标准化实现,适用于移动端)
3
+ * @description 使用 @bddh/starling-realtime-client 直接集成数字人服务,规避移动端点击限制
4
+ */
5
+ import { BaseDigitalHumanService } from './BaseDigitalHumanService';
6
+ export declare class CloudNativeDigitalHumanService extends BaseDigitalHumanService {
7
+ /**
8
+ * SDK 实例
9
+ */
10
+ private humanInstance;
11
+ /**
12
+ * 当前请求 ID
13
+ * - textRender: 每次调用生成新的 requestId
14
+ * - textStreamRender: 同一轮流式渲染使用相同的 requestId
15
+ */
16
+ private requestId;
17
+ /**
18
+ * WebSocket 是否已连接
19
+ */
20
+ private isWSConnected;
21
+ /**
22
+ * RTC 视频流是否就绪
23
+ */
24
+ private isRtcReady;
25
+ /**
26
+ * 是否正在进行流式文本渲染
27
+ */
28
+ private isStreamTextRendering;
29
+ /**
30
+ * WebSocket 连接关闭次数计数器
31
+ * (用于检测重连失败)
32
+ */
33
+ private wsClosedCount;
34
+ /**
35
+ * 服务是否就绪
36
+ */
37
+ get ready(): boolean;
38
+ /**
39
+ * 挂载数字人到指定容器
40
+ * @param $container - 容器元素
41
+ */
42
+ mount: ($container?: HTMLElement) => Promise<void>;
43
+ /**
44
+ * 绑定事件监听
45
+ * @description SDK 内部自动处理,无需手动绑定
46
+ */
47
+ bindEvents: () => this;
48
+ /**
49
+ * 解绑事件监听
50
+ * @description SDK 内部自动处理,无需手动解绑
51
+ */
52
+ unbindEvents: () => this;
53
+ /**
54
+ * 整段文本驱动
55
+ * @param text - 播报文本(支持 SSML)
56
+ */
57
+ renderPlainText: (text: string) => this;
58
+ /**
59
+ * 流式文本驱动
60
+ * @param text - 播报文本片段
61
+ * @param hasEnded - 是否为最后一段
62
+ */
63
+ renderStreamText: (text: string, hasEnded?: boolean) => this;
64
+ /**
65
+ * 打断当前播报
66
+ */
67
+ interrupt: () => this;
68
+ /**
69
+ * 发送静默消息(不播报)
70
+ */
71
+ sendSilenceMessage: () => this;
72
+ /**
73
+ * 销毁数字人实例
74
+ */
75
+ dispose: () => this;
76
+ /**
77
+ * 获取当前 requestId
78
+ */
79
+ GetRequestId: () => string;
80
+ /**
81
+ * 检查服务是否就绪
82
+ */
83
+ checkIsReady: () => boolean;
84
+ /**
85
+ * 取消静音
86
+ */
87
+ cancelMute: () => Promise<void>;
88
+ /**
89
+ * 静音数字人
90
+ */
91
+ muteHuman: () => void;
92
+ /**
93
+ * 恢复播放
94
+ */
95
+ play: () => Promise<void>;
96
+ /**
97
+ * 暂停播放
98
+ */
99
+ pause: () => void;
100
+ /**
101
+ * 构造连接参数
102
+ */
103
+ private readonly buildConnectParams;
104
+ /**
105
+ * 构造渲染参数
106
+ */
107
+ private readonly buildRenderParams;
108
+ /**
109
+ * 刷新 requestId
110
+ */
111
+ private readonly refreshRequestId;
112
+ /**
113
+ * 播报完成的统一处理
114
+ */
115
+ private readonly onRenderFinished;
116
+ /**
117
+ * 数字人回调处理
118
+ * @description SDK 主回调函数,处理各种状态消息
119
+ */
120
+ private readonly onDigitalHumanCallback;
121
+ /**
122
+ * 处理状态消息
123
+ */
124
+ private readonly handleStatusMessage;
125
+ /**
126
+ * 处理文本渲染相关的回调消息
127
+ * @description 通用回调,适用于 textRender 和 textStreamRender
128
+ */
129
+ private readonly handleTextRenderCallback;
130
+ /**
131
+ * 错误处理
132
+ */
133
+ private readonly handleError;
134
+ }
@@ -72,6 +72,24 @@ export declare class PictureClientDigitalHumanService extends BaseDigitalHumanSe
72
72
  dispose: () => this;
73
73
  GetRequestId: () => string;
74
74
  checkIsReady: () => boolean;
75
+ /**
76
+ * 取消静音
77
+ * @description PictureClient SDK 不支持静音控制,此方法为空实现
78
+ */
79
+ cancelMute: () => void;
80
+ /**
81
+ * 静音数字人
82
+ * @description PictureClient SDK 不支持静音控制,此方法为空实现
83
+ */
84
+ muteHuman: () => void;
85
+ /**
86
+ * 恢复播放
87
+ */
88
+ play: () => Promise<void>;
89
+ /**
90
+ * 暂停播放
91
+ */
92
+ pause: () => Promise<void>;
75
93
  private readonly loadPictureClient;
76
94
  private readonly refreshRequestId;
77
95
  private readonly setupWebSocketProxy;
@@ -2,6 +2,7 @@ import Emittery from 'emittery';
2
2
  import type { IResolvedOptions } from '../../../../types/config';
3
3
  import type { BaseSignalingService } from '../signal/base';
4
4
  import { ErrorManager } from '../../../error';
5
+ import { type AudioDeviceCheckResult, type AudioDetectorOptions } from '../../../utils/AudioDeviceDetector';
5
6
  export declare namespace NBaseAsrService {
6
7
  enum EMessageType {
7
8
  Query = 0,
@@ -35,6 +36,7 @@ export declare namespace NBaseAsrService {
35
36
  }
36
37
  interface IMessageEventPayload extends IMessageProtocol, IEventWithSessionIdPayload {
37
38
  }
39
+ type IDeviceCheckCompletedPayload = AudioDeviceCheckResult;
38
40
  interface IEmitter {
39
41
  start: IStartEventPayload;
40
42
  stop: IStopEventPayload;
@@ -44,9 +46,10 @@ export declare namespace NBaseAsrService {
44
46
  user_leaving_room: IUserEventPayload;
45
47
  media_state_changed: IMediaStateEventPayload;
46
48
  silence: ISilenceEventPayload;
49
+ device_check_completed: IDeviceCheckCompletedPayload;
47
50
  }
48
51
  }
49
- export declare abstract class BaseAsrService<E = NBaseAsrService.IEmitter> {
52
+ export declare abstract class BaseAsrService<E extends NBaseAsrService.IEmitter = NBaseAsrService.IEmitter> {
50
53
  readonly opts: IResolvedOptions;
51
54
  readonly signalingService: BaseSignalingService;
52
55
  readonly errorManager: ErrorManager;
@@ -55,6 +58,9 @@ export declare abstract class BaseAsrService<E = NBaseAsrService.IEmitter> {
55
58
  muted: boolean;
56
59
  readonly emitter: Emittery<E, E & import("emittery").OmnipresentEventData, import("emittery").DatalessEventNames<E>>;
57
60
  protected started: boolean;
61
+ private lastCheckResult;
62
+ private lastCheckTime;
63
+ private readonly CHECK_CACHE_TTL;
58
64
  constructor(opts: IResolvedOptions, signalingService: BaseSignalingService, errorManager: ErrorManager);
59
65
  get sessionId(): string | null;
60
66
  mute: (muted: boolean) => void;
@@ -69,10 +75,39 @@ export declare abstract class BaseAsrService<E = NBaseAsrService.IEmitter> {
69
75
  tryUnmuteAsr: () => boolean;
70
76
  disable: () => void;
71
77
  enable: () => void;
78
+ /**
79
+ * 检查音频设备可用性
80
+ *
81
+ * 🎙️ 执行 4 层渐进式检测:
82
+ * - Level 1: API 支持检查 (MediaDevices API)
83
+ * - Level 2: 设备枚举 (enumerateDevices)
84
+ * - Level 3: 权限状态查询 (Permissions API, Safari 可能不支持)
85
+ * - Level 4: 实际流获取 (getUserMedia + 轨道状态检查)
86
+ *
87
+ * 🚀 性能优化:5 秒内缓存结果,避免重复检测
88
+ *
89
+ * @param options 检测配置选项
90
+ * @returns 检测结果
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const result = await asrService.checkAudioDevice();
95
+ * if (result.available) {
96
+ * console.log('设备可用,通过层级:', result.passedLevel);
97
+ * } else {
98
+ * console.error('设备不可用:', result.error, result.message);
99
+ * }
100
+ * ```
101
+ */
102
+ checkAudioDevice: (options?: AudioDetectorOptions & {
103
+ forceCheck?: boolean;
104
+ }) => Promise<AudioDeviceCheckResult>;
72
105
  protected readonly _stop: () => Promise<void>;
73
106
  protected readonly _dispose: () => void;
74
- protected readonly _ensureMicPermission: () => Promise<void>;
75
- private readonly _ensureMicPermissionPolyfill;
107
+ /**
108
+ * AudioDeviceError 映射为对应的 AsrError
109
+ */
110
+ private readonly mapToAsrError;
76
111
  abstract preloadDeps(): Promise<void>;
77
112
  abstract start(): Promise<void>;
78
113
  abstract stop(): Promise<void>;
@@ -1,3 +1,4 @@
1
+ import 'baidurtc';
1
2
  import { BaseAsrService, NBaseAsrService } from './baseAsrService';
2
3
  import { NBRTCSignalingService } from '../signal/brtc';
3
4
  declare global {
@@ -22,11 +23,10 @@ export declare namespace NBRTCAsrService {
22
23
  }
23
24
  export declare class BRTCAsrService extends BaseAsrService {
24
25
  private static readonly MESSAGE_INTERVAL_THRESHOLD;
25
- private brtcLoadPromise;
26
26
  private silenceTimer;
27
27
  private lastMessageTime;
28
28
  private messageIntervalTimer;
29
- preloadDeps(src?: string): Promise<void>;
29
+ preloadDeps(): Promise<void>;
30
30
  start: () => Promise<void>;
31
31
  stop: () => Promise<void>;
32
32
  dispose: () => void;