@spatius/avatarkit 1.3.9 → 1.3.10-beta.1
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/CHANGELOG.md +18 -0
- package/dist/assets/{OpusDecoderWorker.worker-DWI3dYQC.js → OpusDecoderWorker.worker-6yl1qL0f.js} +217 -10170
- package/dist/assets/{OpusEncoderWorker.worker-BlkaRHli.js → OpusEncoderWorker.worker-BTGeizmj.js} +217 -10170
- package/dist/core/AvatarController.d.ts +68 -2
- package/dist/core/AvatarSDK.d.ts +2 -1
- package/dist/core/AvatarView.d.ts +3 -2
- package/dist/index.js +314 -127
- package/dist/internal-telemetry.js +1 -1
- package/dist/{otel-trace-DqXSWBaw.js → otel-trace-CjdZ3saJ.js} +155 -10247
- package/dist/types/index.d.ts +17 -2
- package/package.json +2 -3
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { Avatar } from './Avatar';
|
|
2
|
-
import { ConnectionState, AvatarError, DrivingServiceMode, FrameStarvationMode, ConversationState, AnimationType } from '../types';
|
|
2
|
+
import { ConnectionState, AvatarError, DrivingServiceMode, FrameStarvationMode, ConversationState, AnimationType, AudioFormat, AudioFormatPatch } from '../types';
|
|
3
3
|
import { FrameRateInfo } from '../performance/FrameRateMonitor';
|
|
4
4
|
export declare class AvatarController {
|
|
5
5
|
private networkLayer?;
|
|
6
6
|
private readonly playbackMode;
|
|
7
|
+
/**
|
|
8
|
+
* 宿主**要求**的音频格式:构造时传入的值,之后由 {@link setAudioFormat} 逐字段合并。
|
|
9
|
+
* 与 `_audioFormat` 分开存,是为了让规范化可逆:22050 + Opus 上行会被规范化成
|
|
10
|
+
* 「Opus 上行关」,之后把采样率改回 16000 时上行应当自动恢复——只存规范化后的值就找
|
|
11
|
+
* 不回宿主原本要的 `opusUplinkEnabled: true` 了。唯一不可逆的一条:切到 Opus 输入时
|
|
12
|
+
* 采样率写死 48000(与 Android / iOS 的 `AudioFormat` 构造语义一致,三端同形)。
|
|
13
|
+
*/
|
|
14
|
+
private _requestedAudioFormat;
|
|
15
|
+
/**
|
|
16
|
+
* 本 view 生效的音频格式(已规范化)。**不是全局的**:同一页面里两个 view 可以跑不同
|
|
17
|
+
* 采样率。构造时定下,之后任一字段都可经 {@link setAudioFormat} 改。
|
|
18
|
+
*/
|
|
19
|
+
private _audioFormat;
|
|
20
|
+
/**
|
|
21
|
+
* 本 view 生效的音频格式(已规范化)。只读——改格式走 {@link setAudioFormat}。
|
|
22
|
+
*
|
|
23
|
+
* 对外可读,与 iOS `AvatarController.audioFormat` / Android `AvatarController.audioFormat`
|
|
24
|
+
* 对齐:宿主传进去的值会被规范化(Opus 输入归一到 48 kHz、不兼容的 Opus 上行采样率会关掉
|
|
25
|
+
* Opus 上行),读回来才能确认实际生效的是什么。
|
|
26
|
+
*/
|
|
27
|
+
get audioFormat(): AudioFormat;
|
|
7
28
|
private isStartingPlayback;
|
|
8
29
|
private currentConversationId;
|
|
9
30
|
private reqEnd;
|
|
@@ -132,11 +153,12 @@ export declare class AvatarController {
|
|
|
132
153
|
/**
|
|
133
154
|
* 音频字节率(bytes/s),按 **实际配置的采样率** 动态计算,而不是写死 16kHz。
|
|
134
155
|
* SDK 支持 8k/16k/22.05k/24k/32k/44.1k/48k,写死会让非 16k 的时长统计整体缩放出错。
|
|
135
|
-
* Opus 输入已被
|
|
156
|
+
* Opus 输入已被 normalizeAudioFormat 归一化成 48000,正是解码后 PCM 的真实采样率。
|
|
136
157
|
*/
|
|
137
158
|
private get audioBytesPerSecond();
|
|
138
159
|
constructor(avatar: Avatar, options?: {
|
|
139
160
|
playbackMode?: DrivingServiceMode;
|
|
161
|
+
audioFormat?: AudioFormat;
|
|
140
162
|
});
|
|
141
163
|
private handleVisibilityChange;
|
|
142
164
|
/**
|
|
@@ -173,6 +195,50 @@ export declare class AvatarController {
|
|
|
173
195
|
* on PCM exactly as before.
|
|
174
196
|
*/
|
|
175
197
|
private normalizeInputAudioToPcm;
|
|
198
|
+
/**
|
|
199
|
+
* 改本 view 的音频格式——**部分更新**:传什么改什么,没传的字段保持原状。
|
|
200
|
+
*
|
|
201
|
+
* 四个字段走同一条路,不区分「重」「轻」:**打断当前轮次 → 销毁音频上下文 → 写入新格式
|
|
202
|
+
* → direct 模式断连**。之后喂入的音频按新格式解释;下次 `start()` 时编码器、输入解码器与
|
|
203
|
+
* 会话配置都按新格式重建。
|
|
204
|
+
*
|
|
205
|
+
* - 不设 idle 门禁:「音频已喂进来、动画还在路上、尚未起播」这个中间态既不是 idle 也不在
|
|
206
|
+
* 播,恰恰必须清干净;interrupt 本就是为此存在的,idle 且无音频时它是空操作。
|
|
207
|
+
* - **只销毁音频上下文,不重建**:`AudioContext` 的采样率是构造参数、Web Audio 不允许改,
|
|
208
|
+
* 而重建需要用户手势——那是 SDK 保证不了、只有宿主知道的前提。宿主在自己的手势回调里调
|
|
209
|
+
* {@link initializeAudioContext} 重建;在那之前 `send()` 会经 `onError` 报
|
|
210
|
+
* `audioContextNotInitialized` 并返回 null,不会静默无声。
|
|
211
|
+
* - 断连而不自动重连:宿主接下来还要重建上下文,连接由它后续的 `start()` 带起。
|
|
212
|
+
*
|
|
213
|
+
* 规则:
|
|
214
|
+
* - 切到 `inputAudioFormat: 'opus'` 时采样率写死 48000(Opus 解码固定值),传了别的值也
|
|
215
|
+
* 会被改写。切回 `'pcm'` 时采样率**保持当前值**(可能是 48000)——要换就在同一次调用里
|
|
216
|
+
* 一起传 `sampleRate`。
|
|
217
|
+
* - 采样率不兼容 Opus 上行(不是 8k/16k/24k/48k)时 Opus 上行会被关掉;之后把采样率改回
|
|
218
|
+
* 兼容值,上行按宿主原本的要求自动恢复。
|
|
219
|
+
* - 传入的值与当前要求完全一致时什么都不做(不打断、不销毁、不断连)。
|
|
220
|
+
*
|
|
221
|
+
* **两种非法用法都只记一条 `logger.error` 后原样返回**,不抛异常也不进 `onError`:
|
|
222
|
+
* 1. `sampleRate` 不在支持列表里(8000 / 16000 / 22050 / 24000 / 32000 / 44100 / 48000)
|
|
223
|
+
* 2. 在 Opus 输入下传 `sampleRate`(无论是本来就是 Opus 输入,还是这一次一起切过去)
|
|
224
|
+
*
|
|
225
|
+
* 都是调用方把代码写错了,不是运行期可恢复的 SDK 故障。走 `onError` 并不更可靠:那是
|
|
226
|
+
* 可选回调,宿主未必注册、注册了也未必打到控制台;为它们新增 ErrorCode 还会平白扩大
|
|
227
|
+
* 三端公开错误码面。注释 + 日志 + 文档已经够让写代码的人当场发现。三端一致。
|
|
228
|
+
*/
|
|
229
|
+
setAudioFormat(patch: AudioFormatPatch): void;
|
|
230
|
+
/**
|
|
231
|
+
* 把错误交给宿主,同时写一条 `logger.error`。
|
|
232
|
+
*
|
|
233
|
+
* **所有 onError 都必须走这里。** 直接调 `this.onError?.()` 的写法曾让 9 个调用点里 7 个
|
|
234
|
+
* 不打日志:宿主如果没把回调接到 console(demo 的 log() 就只写页面面板),这些错误在
|
|
235
|
+
* 控制台完全不可见,排查时看起来像「什么都没发生」——一次上下文未初始化的正常拒绝,
|
|
236
|
+
* 因此被当成功能失效查了很久。
|
|
237
|
+
*
|
|
238
|
+
* 日志走 SDK 自己的 logger(受 logLevel 控制),宿主自己再打一条也无妨:重复一行日志的
|
|
239
|
+
* 代价,远小于一条错误在控制台彻底消失。
|
|
240
|
+
*/
|
|
241
|
+
private emitError;
|
|
176
242
|
/**
|
|
177
243
|
* Start service (SDK mode only)
|
|
178
244
|
*/
|
package/dist/core/AvatarSDK.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Configuration, RenderQuality } from '../types';
|
|
2
|
+
/** PCM 输入 + Opus 上行时受支持的采样率(Opus 编码器可用的采样率)。 */
|
|
2
3
|
export declare class AvatarSDK {
|
|
3
4
|
private static _initializationState;
|
|
4
5
|
private static _initializingPromise;
|
|
@@ -72,7 +73,7 @@ export declare class AvatarSDK {
|
|
|
72
73
|
private static readonly GPU_SCORE_THRESHOLD;
|
|
73
74
|
/**
|
|
74
75
|
* Check if the current device can run the avatar.
|
|
75
|
-
* Runs a ~2s benchmark, reports device info and scores
|
|
76
|
+
* Runs a ~2s benchmark, reports device info and scores via telemetry.
|
|
76
77
|
* Returns false when neither WebGL2 nor WebGPU can be created — that is deterministic
|
|
77
78
|
* and the benchmark is skipped. Otherwise runs the benchmark and returns true; the
|
|
78
79
|
* score thresholds are not yet enforced and will be calibrated from production data.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CameraConfig } from '../types';
|
|
1
|
+
import { AvatarViewOptions, CameraConfig } from '../types';
|
|
2
2
|
import { Avatar } from './Avatar';
|
|
3
3
|
import { AvatarController } from './AvatarController';
|
|
4
4
|
export declare class AvatarView {
|
|
@@ -36,8 +36,9 @@ export declare class AvatarView {
|
|
|
36
36
|
* Creates a unified AvatarController, internally composes network layer based on configuration
|
|
37
37
|
* @param avatar - Avatar instance
|
|
38
38
|
* @param container - Canvas container element (required)
|
|
39
|
+
* @param options - Per-view options; see {@link AvatarViewOptions}
|
|
39
40
|
*/
|
|
40
|
-
constructor(avatar: Avatar, container: HTMLElement);
|
|
41
|
+
constructor(avatar: Avatar, container: HTMLElement, options?: AvatarViewOptions);
|
|
41
42
|
/**
|
|
42
43
|
* Get controller (public interface)
|
|
43
44
|
*/
|