@bdky/aaas-pilot-kit 1.0.2
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 +222 -0
- package/dist/http.cjs.js +2 -0
- package/dist/http.cjs.js.LICENSE.txt +1 -0
- package/dist/http.esm.js +2 -0
- package/dist/http.esm.js.LICENSE.txt +1 -0
- package/dist/http.umd.js +2 -0
- package/dist/http.umd.js.LICENSE.txt +1 -0
- package/dist/index.cjs.js +44 -0
- package/dist/index.cjs.js.LICENSE.txt +45 -0
- package/dist/index.esm.js +44 -0
- package/dist/index.esm.js.LICENSE.txt +45 -0
- package/dist/index.umd.js +44 -0
- package/dist/index.umd.js.LICENSE.txt +45 -0
- package/dist/ky-aaas-pilot-kit.umd.js +44 -0
- package/dist/ky-aaas-pilot-kit.umd.js.LICENSE.txt +45 -0
- package/dist/libs/aaas-pilot-kit/src/http.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/index.d.ts +5 -0
- package/dist/libs/aaas-pilot-kit/src/lib/DI/types.d.ts +12 -0
- package/dist/libs/aaas-pilot-kit/src/lib/aaas-pilot-kit.d.ts +5 -0
- package/dist/libs/aaas-pilot-kit/src/lib/api/request.d.ts +9 -0
- package/dist/libs/aaas-pilot-kit/src/lib/constants/env.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/controller.d.ts +107 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/BaseError.d.ts +12 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/ErrorEmitter.d.ts +54 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/ErrorHandler.d.ts +17 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/ErrorManager.d.ts +34 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/codes.d.ts +57 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/index.d.ts +16 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/monitoring/MonitoringError.d.ts +46 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/reporters/ConsoleReporter.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/reporters/HttpReporter.d.ts +16 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/reporters/index.d.ts +2 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/AgentError.d.ts +17 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/AsrError.d.ts +23 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/ConversationError.d.ts +23 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/DigitalHumanError.d.ts +32 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/index.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/types.d.ts +41 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/utils/ErrorUtils.d.ts +7 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/agent/aiobAgentService.d.ts +69 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/agent/baseAgentService.d.ts +65 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/agent/cspAgentService.d.ts +90 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/aiWorkerConversationBean.d.ts +39 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/clientConversationBean.d.ts +25 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/ImageContent.d.ts +25 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/MultimodalContent.d.ts +42 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/TextContent.d.ts +41 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/VideoContent.d.ts +26 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/index.d.ts +8 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/conversationBean.d.ts +25 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/conversationService.d.ts +36 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/index.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/BaseDigitalHumanService.d.ts +62 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/CloudDigitalHumanService.d.ts +102 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/PictureClientDigitalHumanService.d.ts +85 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/interface.d.ts +100 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/asr/baseAsrService.d.ts +82 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/asr/brtcAsrService.d.ts +38 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/signal/base.d.ts +19 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/signal/brtc.d.ts +69 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/applyTextReplacements.d.ts +15 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/customXmlParser.d.ts +46 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/isEmptyObject.d.ts +14 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/isPlainObject.d.ts +13 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/noop.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/sleep.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/toQueryString.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/ua.d.ts +3 -0
- package/dist/libs/aaas-pilot-kit/src/samples/react/Route/index.d.ts +3 -0
- package/dist/libs/aaas-pilot-kit/src/samples/react/conversation.d.ts +2 -0
- package/dist/libs/aaas-pilot-kit/src/samples/react/index.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/test-setup.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/types/agent.d.ts +8 -0
- package/dist/libs/aaas-pilot-kit/src/types/common.d.ts +5 -0
- package/dist/libs/aaas-pilot-kit/src/types/config.d.ts +552 -0
- package/package.json +64 -0
package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/PictureClientDigitalHumanService.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import PictureClient from '@bddh/starling-dh-picture-client';
|
|
2
|
+
import { type IOptions } from '../../../types/config';
|
|
3
|
+
import { BaseDigitalHumanService } from './BaseDigitalHumanService';
|
|
4
|
+
export declare namespace NPictureClientDigitalHumanService {
|
|
5
|
+
interface IPictureClientProps {
|
|
6
|
+
readonly modelUrl: string;
|
|
7
|
+
readonly licenseUrl: string;
|
|
8
|
+
readonly licenseKey: string;
|
|
9
|
+
readonly reportUrl?: string;
|
|
10
|
+
readonly reportInterval?: number;
|
|
11
|
+
readonly showLog?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface ITtsConfig {
|
|
14
|
+
readonly per: number | string;
|
|
15
|
+
readonly spd?: number;
|
|
16
|
+
readonly pit?: number;
|
|
17
|
+
readonly vol?: number;
|
|
18
|
+
}
|
|
19
|
+
interface IFinishData {
|
|
20
|
+
readonly code?: string | number;
|
|
21
|
+
readonly message?: string;
|
|
22
|
+
}
|
|
23
|
+
interface IStatusType {
|
|
24
|
+
readonly code: number;
|
|
25
|
+
readonly status?: {
|
|
26
|
+
readonly value: 'SUCCESS' | 'PENDING' | 'ERROR';
|
|
27
|
+
readonly progress: number;
|
|
28
|
+
};
|
|
29
|
+
readonly message?: string;
|
|
30
|
+
}
|
|
31
|
+
interface ITextRenderMessage {
|
|
32
|
+
readonly token: string;
|
|
33
|
+
readonly text: string;
|
|
34
|
+
readonly tts: Required<ITtsConfig>;
|
|
35
|
+
readonly interrupted: boolean;
|
|
36
|
+
readonly last: boolean;
|
|
37
|
+
readonly encodeType?: 'PCM' | 'OPUS';
|
|
38
|
+
}
|
|
39
|
+
interface ITextRenderData {
|
|
40
|
+
readonly msg: ITextRenderMessage;
|
|
41
|
+
readonly finishListener: (data?: IFinishData) => void;
|
|
42
|
+
}
|
|
43
|
+
interface IWebSocketMessage {
|
|
44
|
+
readonly [key: string]: unknown;
|
|
45
|
+
readonly action: string;
|
|
46
|
+
}
|
|
47
|
+
type IPictureClientConstructor = typeof PictureClient;
|
|
48
|
+
interface IWSEmitter {
|
|
49
|
+
reply_start: never;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export interface IPictureClientOptions extends IOptions {
|
|
53
|
+
readonly pictureClient?: NPictureClientDigitalHumanService.IPictureClientProps;
|
|
54
|
+
readonly ttsConfig?: NPictureClientDigitalHumanService.ITtsConfig;
|
|
55
|
+
}
|
|
56
|
+
export declare class PictureClientDigitalHumanService extends BaseDigitalHumanService {
|
|
57
|
+
static DEFAULT_TTS_CONFIG: Required<Omit<NPictureClientDigitalHumanService.ITtsConfig, 'per'>>;
|
|
58
|
+
private pictureClient;
|
|
59
|
+
private requestId;
|
|
60
|
+
private originalWebSocket;
|
|
61
|
+
private renderListenerCleanups;
|
|
62
|
+
private isStreamRendering;
|
|
63
|
+
private readonly wsProxyEmitter;
|
|
64
|
+
get ready(): boolean;
|
|
65
|
+
mount: (container?: HTMLElement) => Promise<void>;
|
|
66
|
+
bindEvents: () => this;
|
|
67
|
+
unbindEvents: () => this;
|
|
68
|
+
renderPlainText: (text: string) => this;
|
|
69
|
+
renderStreamText: (text: string, hasEnded?: boolean) => this;
|
|
70
|
+
interrupt: () => this;
|
|
71
|
+
sendSilenceMessage: () => this;
|
|
72
|
+
dispose: () => this;
|
|
73
|
+
GetRequestId: () => string;
|
|
74
|
+
checkIsReady: () => boolean;
|
|
75
|
+
private readonly loadPictureClient;
|
|
76
|
+
private readonly refreshRequestId;
|
|
77
|
+
private readonly setupWebSocketProxy;
|
|
78
|
+
private readonly handleWebSocketMessage;
|
|
79
|
+
private readonly isWebSocketMessage;
|
|
80
|
+
private readonly setupRenderListener;
|
|
81
|
+
private readonly cleanupRenderListeners;
|
|
82
|
+
private readonly restoreWebSocket;
|
|
83
|
+
private readonly handleRenderFinish;
|
|
84
|
+
private readonly onStatusChange;
|
|
85
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file 数字员工sdk相关接口定义
|
|
3
|
+
* @author lifuxin(lifuxin@baidu.com)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 消息类型
|
|
7
|
+
*
|
|
8
|
+
* msg: 数字员工驱动消息回调通知
|
|
9
|
+
*
|
|
10
|
+
* rtcState: webRTC 的状态
|
|
11
|
+
*
|
|
12
|
+
* wsState: webSocket 的链接状态
|
|
13
|
+
*/
|
|
14
|
+
export type TMessageType = 'msg' | 'rtcState' | 'wsState';
|
|
15
|
+
/**
|
|
16
|
+
* 错误码枚举
|
|
17
|
+
*
|
|
18
|
+
* 只列举了必要的
|
|
19
|
+
*/
|
|
20
|
+
export declare enum EErrorCode {
|
|
21
|
+
/**
|
|
22
|
+
* 成功
|
|
23
|
+
*/
|
|
24
|
+
Success = 0,
|
|
25
|
+
/**
|
|
26
|
+
* app 会话路数已经达到上限
|
|
27
|
+
*/
|
|
28
|
+
ReachSessionLimit = 1004,
|
|
29
|
+
/**
|
|
30
|
+
* 系统渲染资源不足导致
|
|
31
|
+
*/
|
|
32
|
+
ResourceNotEnough = 3001
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 类型为msg的消息体
|
|
36
|
+
*/
|
|
37
|
+
export interface IMsgContent {
|
|
38
|
+
action: 'RENDER_START' | 'FINISHED' | 'RENDER_ERROR' | 'DOWN_SUBTITLE' | 'RENDER_INTERRUPTED' | 'TIMEOUT_EXIT' | 'CONNECT' | 'TEXT_RENDER' | 'TEXT_STREAM_RENDER' | 'DISCONNECT_ALERT';
|
|
39
|
+
code: EErrorCode;
|
|
40
|
+
requestId: string;
|
|
41
|
+
body: string;
|
|
42
|
+
message?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 类型为rtcState的消息体
|
|
46
|
+
*/
|
|
47
|
+
export interface IRtcStateContent {
|
|
48
|
+
action: 'success' | 'error' | 'remotevideoloading' | 'remoteVideoConnected' | 'remotevideoon' | 'localVideoMuted';
|
|
49
|
+
body: unknown;
|
|
50
|
+
}
|
|
51
|
+
export declare enum EWSReadyState {
|
|
52
|
+
UNINSTANTIATED = -1,
|
|
53
|
+
CONNECTING = 0,
|
|
54
|
+
OPEN = 1,
|
|
55
|
+
CLOSING = 2,
|
|
56
|
+
CLOSED = 3
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 类型为wsState的消息体
|
|
60
|
+
*/
|
|
61
|
+
export interface IWsStateContent {
|
|
62
|
+
readyState: EWSReadyState;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 从数字员工接受到的原始消息
|
|
66
|
+
*/
|
|
67
|
+
export interface IBaseRawMessage {
|
|
68
|
+
type: TMessageType;
|
|
69
|
+
content: unknown;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 从数字员工sdk接受到的msg类型原始消息
|
|
73
|
+
*/
|
|
74
|
+
export interface IMsgTypeRawMessage extends IBaseRawMessage {
|
|
75
|
+
type: 'msg';
|
|
76
|
+
content: IMsgContent;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 从数字员工sdk接受到的rtcState类型原始消息
|
|
80
|
+
*/
|
|
81
|
+
export interface IRtcStateTypeRawMessage extends IBaseRawMessage {
|
|
82
|
+
type: 'rtcState';
|
|
83
|
+
content: IRtcStateContent;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 从数字员工sdk接受到的wsState类型原始消息
|
|
87
|
+
*/
|
|
88
|
+
export interface IWsStateTypeRawMessage extends IBaseRawMessage {
|
|
89
|
+
type: 'wsState';
|
|
90
|
+
content: IWsStateContent;
|
|
91
|
+
}
|
|
92
|
+
export type TRawMessage = IMsgTypeRawMessage | IRtcStateTypeRawMessage | IWsStateTypeRawMessage;
|
|
93
|
+
/**
|
|
94
|
+
* 数字员工字幕结构
|
|
95
|
+
*/
|
|
96
|
+
export interface ISubtitle {
|
|
97
|
+
subtitleId: string;
|
|
98
|
+
content: string;
|
|
99
|
+
completed: boolean;
|
|
100
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import Emittery from 'emittery';
|
|
2
|
+
import type { IOptions } from '../../../../types/config';
|
|
3
|
+
import type { BaseSignalingService } from '../signal/base';
|
|
4
|
+
import { ErrorManager } from '../../../error';
|
|
5
|
+
export declare namespace NBaseAsrService {
|
|
6
|
+
enum EMessageType {
|
|
7
|
+
Query = 0,
|
|
8
|
+
Event = 1
|
|
9
|
+
}
|
|
10
|
+
interface IMessageProtocol {
|
|
11
|
+
type: EMessageType;
|
|
12
|
+
data: string;
|
|
13
|
+
continued: boolean;
|
|
14
|
+
completed: boolean;
|
|
15
|
+
isCollectingSounds: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface IEventWithSessionIdPayload {
|
|
18
|
+
sessionId: string | null;
|
|
19
|
+
}
|
|
20
|
+
interface IUserEventPayload extends IEventWithSessionIdPayload {
|
|
21
|
+
id: string;
|
|
22
|
+
display: string;
|
|
23
|
+
attribute?: string;
|
|
24
|
+
}
|
|
25
|
+
interface IMediaStateEventPayload extends IEventWithSessionIdPayload {
|
|
26
|
+
id: string;
|
|
27
|
+
medium: string;
|
|
28
|
+
on: boolean;
|
|
29
|
+
}
|
|
30
|
+
type ISilenceEventPayload = IEventWithSessionIdPayload;
|
|
31
|
+
type IStartEventPayload = IEventWithSessionIdPayload;
|
|
32
|
+
type IStopEventPayload = IEventWithSessionIdPayload;
|
|
33
|
+
interface IErrorEventPayload extends IEventWithSessionIdPayload {
|
|
34
|
+
error: Error;
|
|
35
|
+
}
|
|
36
|
+
interface IMessageEventPayload extends IMessageProtocol, IEventWithSessionIdPayload {
|
|
37
|
+
}
|
|
38
|
+
interface IEmitter {
|
|
39
|
+
start: IStartEventPayload;
|
|
40
|
+
stop: IStopEventPayload;
|
|
41
|
+
error: IErrorEventPayload;
|
|
42
|
+
message: IMessageEventPayload;
|
|
43
|
+
user_joined_room: IUserEventPayload;
|
|
44
|
+
user_leaving_room: IUserEventPayload;
|
|
45
|
+
media_state_changed: IMediaStateEventPayload;
|
|
46
|
+
silence: ISilenceEventPayload;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export declare abstract class BaseAsrService<E = NBaseAsrService.IEmitter> {
|
|
50
|
+
readonly opts: Required<IOptions>;
|
|
51
|
+
readonly signalingService: BaseSignalingService;
|
|
52
|
+
readonly errorManager: ErrorManager;
|
|
53
|
+
disabled: boolean;
|
|
54
|
+
mutedByUser: boolean;
|
|
55
|
+
muted: boolean;
|
|
56
|
+
readonly emitter: Emittery<E, E & import("emittery").OmnipresentEventData, import("emittery").DatalessEventNames<E>>;
|
|
57
|
+
protected started: boolean;
|
|
58
|
+
constructor(opts: Required<IOptions>, signalingService: BaseSignalingService, errorManager: ErrorManager);
|
|
59
|
+
get sessionId(): string | null;
|
|
60
|
+
mute: (muted: boolean) => void;
|
|
61
|
+
setMutedByUser: (muted: boolean) => void;
|
|
62
|
+
/**
|
|
63
|
+
* 尝试取消asr静音
|
|
64
|
+
*
|
|
65
|
+
* 如果用户手动静音、或者出于手动输入驱动方式,则不能取消asr的静音
|
|
66
|
+
*
|
|
67
|
+
* @returns 是否成功取消静音
|
|
68
|
+
*/
|
|
69
|
+
tryUnmuteAsr: () => boolean;
|
|
70
|
+
disable: () => void;
|
|
71
|
+
enable: () => void;
|
|
72
|
+
protected readonly _stop: () => Promise<void>;
|
|
73
|
+
protected readonly _dispose: () => void;
|
|
74
|
+
protected readonly _ensureMicPermission: () => Promise<void>;
|
|
75
|
+
private readonly _ensureMicPermissionPolyfill;
|
|
76
|
+
abstract preloadDeps(): Promise<void>;
|
|
77
|
+
abstract start(): Promise<void>;
|
|
78
|
+
abstract stop(): Promise<void>;
|
|
79
|
+
abstract dispose(): void;
|
|
80
|
+
protected abstract makeStartOptions(extra: any): unknown;
|
|
81
|
+
protected abstract parseMessage(raw: string): NBaseAsrService.IMessageProtocol;
|
|
82
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseAsrService, NBaseAsrService } from './baseAsrService';
|
|
2
|
+
import { NBRTCSignalingService } from '../signal/brtc';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
adapter: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare namespace NBRTCAsrService {
|
|
9
|
+
interface IRtcDomOptions {
|
|
10
|
+
remoteVideoElement?: HTMLElement | string;
|
|
11
|
+
localVideoElement?: HTMLElement | string;
|
|
12
|
+
}
|
|
13
|
+
interface IBRTCAsrClientConfig {
|
|
14
|
+
displayName: string;
|
|
15
|
+
debugLevel?: boolean | 'all' | Array<'debug' | 'log' | 'error'>;
|
|
16
|
+
rtcOptions?: IRtcDomOptions;
|
|
17
|
+
cfg?: NBRTCSignalingService.IRuntimeCfg;
|
|
18
|
+
silenceTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
const DEFAULT_BRTC_SDK_URL = "https://brtc-sdk.cdn.bcebos.com/npm/baidurtc@1.2.19/baidu.rtc.sdk.js";
|
|
21
|
+
const DEFAULT_BRTC_CLIENT_CONFIG: Required<IBRTCAsrClientConfig>;
|
|
22
|
+
}
|
|
23
|
+
export declare class BRTCAsrService extends BaseAsrService {
|
|
24
|
+
private static readonly MESSAGE_INTERVAL_THRESHOLD;
|
|
25
|
+
private brtcLoadPromise;
|
|
26
|
+
private silenceTimer;
|
|
27
|
+
private lastMessageTime;
|
|
28
|
+
private messageIntervalTimer;
|
|
29
|
+
preloadDeps(src?: string): Promise<void>;
|
|
30
|
+
start: () => Promise<void>;
|
|
31
|
+
stop: () => Promise<void>;
|
|
32
|
+
dispose: () => void;
|
|
33
|
+
protected makeStartOptions(): Required<NBRTCAsrService.IBRTCAsrClientConfig>;
|
|
34
|
+
protected parseMessage(raw: string): NBaseAsrService.IMessageProtocol;
|
|
35
|
+
private readonly resetSilenceTimer;
|
|
36
|
+
private readonly triggerSilence;
|
|
37
|
+
private readonly checkMessageInterval;
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file 基础 RTC 信令服务抽象类
|
|
3
|
+
* @author zhangwenxi(zhangwenxi@baidu.com)
|
|
4
|
+
*/
|
|
5
|
+
import type { IOptions } from '../../../../types/config';
|
|
6
|
+
import { ErrorManager } from '../../../error';
|
|
7
|
+
export declare abstract class BaseSignalingService {
|
|
8
|
+
readonly opts: Required<IOptions>;
|
|
9
|
+
readonly errorManager: ErrorManager;
|
|
10
|
+
protected started: boolean;
|
|
11
|
+
protected sessionId: string;
|
|
12
|
+
constructor(opts: Required<IOptions>, errorManager: ErrorManager);
|
|
13
|
+
protected readonly _dispose: () => void;
|
|
14
|
+
abstract Start<P extends Record<string, any>>(opts: P): Promise<void>;
|
|
15
|
+
abstract Stop(): Promise<void>;
|
|
16
|
+
abstract Mute(muted: boolean): void;
|
|
17
|
+
abstract GetSessionID(): string;
|
|
18
|
+
abstract Dispose(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BaseSignalingService } from './base';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
BRTC_Start: (options: NBRTCSignalingService.ILoginParams) => void;
|
|
5
|
+
BRTC_Stop: () => void;
|
|
6
|
+
BRTC_MuteMicphone: (muted: boolean) => void;
|
|
7
|
+
BRTC_SendMessageToUser: (message: string, uid?: string) => void;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare namespace NBRTCSignalingService {
|
|
11
|
+
interface IRuntimeCfg {
|
|
12
|
+
llm?: string;
|
|
13
|
+
llm_url?: string;
|
|
14
|
+
lang?: string;
|
|
15
|
+
tts?: string;
|
|
16
|
+
asr?: string;
|
|
17
|
+
tag?: string;
|
|
18
|
+
tts_sayhi?: string;
|
|
19
|
+
role?: string;
|
|
20
|
+
location?: string;
|
|
21
|
+
llm_cfg?: string;
|
|
22
|
+
asr_url?: string;
|
|
23
|
+
tts_url?: string;
|
|
24
|
+
audiocodec?: string;
|
|
25
|
+
xiling_auth?: string;
|
|
26
|
+
xiling_bgimg?: string;
|
|
27
|
+
fid?: string;
|
|
28
|
+
llm_token?: string;
|
|
29
|
+
asr_vad?: number;
|
|
30
|
+
}
|
|
31
|
+
interface IRawMessage {
|
|
32
|
+
id: string;
|
|
33
|
+
data: string;
|
|
34
|
+
}
|
|
35
|
+
interface IStartParams extends Record<string, any> {
|
|
36
|
+
cfg?: IRuntimeCfg;
|
|
37
|
+
apihost?: string;
|
|
38
|
+
authUrl?: string;
|
|
39
|
+
debuglevel?: boolean | 'all' | Array<'debug' | 'log' | 'error'>;
|
|
40
|
+
remotevideoviewid?: string | HTMLElement;
|
|
41
|
+
localvideoviewid?: string | HTMLElement;
|
|
42
|
+
success?: () => void;
|
|
43
|
+
error?: (err: Error) => void;
|
|
44
|
+
onmessage?: (msg: IRawMessage) => void;
|
|
45
|
+
userevent_joinedroom?: (id: string, display: string, attribute: string) => void;
|
|
46
|
+
userevent_leavingroom?: (id: string, display: string) => void;
|
|
47
|
+
remotemediastating?: (id: string, medium: string, on: boolean) => void;
|
|
48
|
+
}
|
|
49
|
+
interface ILoginParams extends IStartParams {
|
|
50
|
+
appid: string;
|
|
51
|
+
roomname: string;
|
|
52
|
+
userid: string;
|
|
53
|
+
token: string;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export declare class BRTCSignalingService extends BaseSignalingService {
|
|
57
|
+
static ONLINE_PREFIX_URL: string;
|
|
58
|
+
static SANDBOX_PREFIX_URL: string;
|
|
59
|
+
static AUTH_URL: string;
|
|
60
|
+
appId: string;
|
|
61
|
+
get prefixUrl(): string;
|
|
62
|
+
Start: (params: NBRTCSignalingService.IStartParams) => Promise<void>;
|
|
63
|
+
Stop: () => Promise<void>;
|
|
64
|
+
Mute: (muted: boolean) => void;
|
|
65
|
+
GetSessionID: () => string;
|
|
66
|
+
Dispose: () => void;
|
|
67
|
+
private readonly getAuthToken;
|
|
68
|
+
private loginBRTC;
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 定义一条替换规则:用 RegExp 搜索,用字符串替换 */
|
|
2
|
+
export interface ReplacementRule {
|
|
3
|
+
/** 正则表达式,务必带 g 标志,否则只会替换第一个命中 */
|
|
4
|
+
pattern: RegExp;
|
|
5
|
+
/** 要替换成的目标文本 */
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const defaultRules: ReplacementRule[];
|
|
9
|
+
/**
|
|
10
|
+
* 按给定规则批量替换文本(用于配置好热词后 ASR 仍然识别错误的场景)
|
|
11
|
+
* @param input 原始文本
|
|
12
|
+
* @param rules 替换规则数组
|
|
13
|
+
* @returns 处理后的文本
|
|
14
|
+
*/
|
|
15
|
+
export declare const applyReplacements: (input: string, rules?: ReplacementRule[]) => string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
2
|
+
export declare namespace NCustomXMLParser {
|
|
3
|
+
interface TextNode {
|
|
4
|
+
text: [
|
|
5
|
+
{
|
|
6
|
+
'#text': string;
|
|
7
|
+
}
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
interface ImageNode {
|
|
11
|
+
image: [
|
|
12
|
+
{
|
|
13
|
+
'#text': string;
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
interface VideoNode {
|
|
18
|
+
video: [
|
|
19
|
+
{
|
|
20
|
+
'#text': string;
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
type ContentNode = TextNode | ImageNode | VideoNode;
|
|
25
|
+
type XMLStructure = [
|
|
26
|
+
{
|
|
27
|
+
root: [
|
|
28
|
+
{
|
|
29
|
+
content: ContentNode[];
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
type ParsedXmlResult<R extends XMLStructure> = R | string | unknown;
|
|
35
|
+
}
|
|
36
|
+
export declare class CustomXMLParser {
|
|
37
|
+
xmlParser: XMLParser;
|
|
38
|
+
constructor();
|
|
39
|
+
static isTextNode: (node: NCustomXMLParser.ContentNode) => node is NCustomXMLParser.TextNode;
|
|
40
|
+
static isImageNode: (node: NCustomXMLParser.ContentNode) => node is NCustomXMLParser.ImageNode;
|
|
41
|
+
static isVideoNode: (node: NCustomXMLParser.ContentNode) => node is NCustomXMLParser.VideoNode;
|
|
42
|
+
static isXml: (text: unknown) => text is string;
|
|
43
|
+
isXml: (text: unknown) => text is string;
|
|
44
|
+
parseXmlOrText: <R extends NCustomXMLParser.XMLStructure = NCustomXMLParser.XMLStructure>(input: string) => NCustomXMLParser.ParsedXmlResult<R>;
|
|
45
|
+
hasMixContentByParsedXml: <R extends NCustomXMLParser.XMLStructure = NCustomXMLParser.XMLStructure>(result: NCustomXMLParser.ParsedXmlResult<R>) => result is R;
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断一个 *plain object* 是否“空对象”——
|
|
3
|
+
* 即既没有自有字符串键,也没有自有 Symbol 键。
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ 若传入的值不是 plain object,则结果恒为 false。
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isEmptyObject({}) // true
|
|
9
|
+
* isEmptyObject(Object.create(null)) // true
|
|
10
|
+
* isEmptyObject({ a: 1 }) // false
|
|
11
|
+
* isEmptyObject([]) // false (不是 plain object)
|
|
12
|
+
* isEmptyObject(new Map()) // false (不是 plain object)
|
|
13
|
+
*/
|
|
14
|
+
export declare function isEmptyObject(value: unknown): value is Record<PropertyKey, never>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 严谨判断一个值是否为 *plain object*:
|
|
3
|
+
* 1. 直接量 `{}`;
|
|
4
|
+
* 2. `new Object()`;
|
|
5
|
+
* 3. `Object.create(null)`;
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isPlainObject({}) // true
|
|
9
|
+
* isPlainObject(Object.create(null)) // true
|
|
10
|
+
* isPlainObject([]) // false
|
|
11
|
+
* isPlainObject(new (class Foo {})()) // false
|
|
12
|
+
*/
|
|
13
|
+
export declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noop: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (timeout?: number) => Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toQueryString: (params: Record<string, any>) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|