@somecat/ai-assist-sdk 1.2.1 → 1.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@somecat/ai-assist-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "AI助手 SDK — 支持 React 和 Vue3 的可嵌入AI对话组件",
6
6
  "main": "./dist/index.mjs",
@@ -1,35 +0,0 @@
1
- import { VoiceConfig, VoiceResult, VoiceError } from './types';
2
- export declare class VoiceClient {
3
- private ws;
4
- private config;
5
- private sn;
6
- constructor(config: VoiceConfig);
7
- /** WebSocket 是否处于可发送状态 */
8
- get isOpen(): boolean;
9
- /** 请求标识(用于排查日志) */
10
- getSn(): string;
11
- /**
12
- * 建立 WebSocket 连接。
13
- * 连接成功后自动发送 START 参数帧。
14
- */
15
- connect(handlers: {
16
- onOpen: () => void;
17
- onMessage: (data: VoiceResult) => void;
18
- onError: (err: VoiceError) => void;
19
- onClose: () => void;
20
- }): void;
21
- /** 发送音频数据帧(Binary) */
22
- sendAudio(data: ArrayBuffer): void;
23
- /** 发送结束帧(FINISH),等待最终结果 */
24
- finish(): void;
25
- /** 发送取消帧(CANCEL),立即终止 */
26
- cancel(): void;
27
- /** 发送心跳帧(断网补发时使用) */
28
- heartbeat(): void;
29
- /** 发送 START 参数帧 */
30
- private sendStart;
31
- /** 发送 Text 控制帧 */
32
- private send;
33
- /** 关闭并清理 WebSocket */
34
- close(): void;
35
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * PCM 音频采集器
3
- *
4
- * 使用方式:
5
- * const rec = new VoiceRecorder((arrayBuffer) => ws.send(arrayBuffer))
6
- * await rec.start() // 请求麦克风权限并开始采集
7
- * rec.stop() // 停止采集并 flush 剩余数据
8
- * rec.destroy() // 释放所有资源
9
- */
10
- export declare class VoiceRecorder {
11
- private stream;
12
- private audioContext;
13
- private processor;
14
- private source;
15
- /** 静音增益节点(避免麦克风音频输出到扬声器产生回声,同时保持 onaudioprocess 触发) */
16
- private muteGain;
17
- /** 未发送的 PCM 数据块(Int16Array) */
18
- private buffer;
19
- private isRecording;
20
- /** 音频帧回调 */
21
- private onFrame;
22
- /** 音量电平回调(0-1) */
23
- private onLevel;
24
- constructor(onFrame: (data: ArrayBuffer) => void, onLevel?: (level: number) => void);
25
- /** 是否正在采集 */
26
- get active(): boolean;
27
- /**
28
- * 请求麦克风权限并开始采集。
29
- * 失败时抛出错误(权限拒绝 / 设备不可用)。
30
- */
31
- start(): Promise<void>;
32
- /** 线性插值重采样到目标采样率(ratio=1 时为直通) */
33
- private resample;
34
- /** Float32 (-1.0 ~ 1.0) → Int16 PCM */
35
- private floatTo16BitPCM;
36
- /**
37
- * 攒够数据后按 160ms 帧切分发送。
38
- *
39
- * 关键:只发送完整的整帧,不足一帧的尾部数据保留在 buffer 中
40
- * 等待下次合并,避免:
41
- * 1. 发送过小帧(< 20ms,百度建议 20-200ms)
42
- * 2. 尾部数据被「发送后又放回 buffer」导致重复发送、时间轴错乱
43
- */
44
- private flush;
45
- /** 停止采集并 flush 剩余数据 */
46
- stop(): void;
47
- /** 释放所有资源 */
48
- destroy(): void;
49
- private cleanup;
50
- }