@xmov/avatar 2.0.0-alpha.39 → 2.0.0-alpha.41

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.
@@ -3,7 +3,7 @@ import XmovAvatar from "../index";
3
3
  /**
4
4
  * 资源处理模块,加载并存储资源
5
5
  */
6
- type TOptions = Pick<IAvatarOptions, "appId" | "appSecret" | "gatewayServer" | 'cacheServer' | "sdkInstance" | "config" | "headers" | "gateway_type" | "tag" | "asr_id" | "llm_id" | "session_speak_req_id"> & {
6
+ type TOptions = Pick<IAvatarOptions, "appId" | "appSecret" | "gatewayServer" | 'cacheServer' | "sdkInstance" | "config" | "headers" | "gateway_type" | "tag" | "asr_id" | "llm_id" | "session_speak_req_id" | "audioOnlyMode"> & {
7
7
  sessionRequestData?: Record<string, unknown>;
8
8
  onNetworkInfo(quality: INetworkInfo): void;
9
9
  onStartSessionWarning?: (message: Object) => void;
@@ -169,6 +169,7 @@ export default class ResourceManager {
169
169
  private isProcessingVideo;
170
170
  private cacheServer?;
171
171
  private startSessionTimer;
172
+ private audioOnlyMode;
172
173
  private downloadingVideos;
173
174
  first_load: boolean;
174
175
  constructor(options: TOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmov/avatar",
3
- "version": "2.0.0-alpha.39",
3
+ "version": "2.0.0-alpha.41",
4
4
  "description": "魔珐数字人 JS-SDK",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",
@@ -184,14 +184,25 @@ export default class MediaSourceAudioPlayer {
184
184
  * 获取缓冲范围
185
185
  */
186
186
  private getBufferedRanges(): string {
187
- if (this.sourceBuffer && this.sourceBuffer.buffered.length > 0) {
188
- const ranges: string[] = [];
189
- for (let i = 0; i < this.sourceBuffer.buffered.length; i++) {
190
- const start = this.sourceBuffer.buffered.start(i).toFixed(2);
191
- const end = this.sourceBuffer.buffered.end(i).toFixed(2);
192
- ranges.push(`[${start}-${end}]`);
187
+ try {
188
+ // stop/destroy 流程中浏览器会先移除 SourceBuffer 再置空引用,
189
+ // 此时访问 .buffered 会抛 InvalidStateError,需要 readyState 校验 + 兜底
190
+ if (
191
+ this.sourceBuffer &&
192
+ this.mediaSource?.readyState === "open" &&
193
+ this.sourceBuffer.buffered.length > 0
194
+ ) {
195
+ const ranges: string[] = [];
196
+ for (let i = 0; i < this.sourceBuffer.buffered.length; i++) {
197
+ const start = this.sourceBuffer.buffered.start(i).toFixed(2);
198
+ const end = this.sourceBuffer.buffered.end(i).toFixed(2);
199
+ ranges.push(`[${start}-${end}]`);
200
+ }
201
+ return ranges.join(", ");
193
202
  }
194
- return ranges.join(", ");
203
+ } catch (e) {
204
+ // SourceBuffer 已被移除(stop/destroy 竞态),视为无缓冲数据
205
+ return "-";
195
206
  }
196
207
  return "-";
197
208
  }
package/src/index.ts CHANGED
@@ -225,7 +225,7 @@ export default class XmovAvatar {
225
225
  if(config?.layout?.avatar?.scale){
226
226
  config.layout.avatar.scale = validateScaleWithDecimal(scale, "initializeSDK") as number | string;
227
227
  }
228
- const _config = { ...(config || {}), raw_audio: !isSupportMES() };
228
+ const _config = { ...(config || {}), raw_audio: true };
229
229
 
230
230
  if(container && container instanceof HTMLElement){
231
231
  this.el = container as HTMLElement;
@@ -270,6 +270,7 @@ export default class XmovAvatar {
270
270
  gatewayServer,
271
271
  cacheServer,
272
272
  config:_config,
273
+ audioOnlyMode: options.audioOnlyMode || false,
273
274
  onNetworkInfo(networkInfo) {
274
275
  self.networkInfo = networkInfo;
275
276
  options.onNetworkInfo?.(networkInfo);
@@ -17,7 +17,7 @@ import CacheManager from './cache-manager';
17
17
  type TOptions = Pick<
18
18
  IAvatarOptions,
19
19
  "appId" | "appSecret" | "gatewayServer" | 'cacheServer' | "sdkInstance" | "config" | "headers" | "gateway_type" | "tag" |
20
- "asr_id" | "llm_id" | "session_speak_req_id"
20
+ "asr_id" | "llm_id" | "session_speak_req_id" | "audioOnlyMode"
21
21
  > & {
22
22
  sessionRequestData?: Record<string, unknown>
23
23
  onNetworkInfo(quality: INetworkInfo): void
@@ -205,12 +205,14 @@ export default class ResourceManager {
205
205
  private isProcessingVideo = false; // 防止在视频处理过程中清理缓存
206
206
  private cacheServer?: CacheManager;
207
207
  private startSessionTimer: any = null;
208
+ private audioOnlyMode: boolean;
208
209
 
209
210
  // 新增:正在下载的视频跟踪
210
211
  private downloadingVideos = new Map<string, Promise<ArrayBuffer | undefined>>();
211
212
  first_load = true;
212
213
  constructor(options: TOptions) {
213
214
  this.options = options;
215
+ this.audioOnlyMode = options.audioOnlyMode || false;
214
216
  this.sdk = options.sdkInstance as XmovAvatar;
215
217
  this.mouthShapeLib = {
216
218
  char_info: null,
@@ -324,9 +326,11 @@ export default class ResourceManager {
324
326
  this.config = res.config as any;
325
327
  this.offlineIdle = res.resource_pack?.offline_idle || []
326
328
  if (this.resource_pack) {
327
- await this.loadMouthShapeLib(onDownloadProgress);
329
+ if(!this.audioOnlyMode) {
330
+ await this.loadMouthShapeLib(onDownloadProgress);
331
+ }
328
332
  this.getBackgroundImage();
329
- if (!this.mouthShapeLib?.char_info && res?.resource_pack?.face_ani_char_data) {
333
+ if (!this.mouthShapeLib?.char_info && res?.resource_pack?.face_ani_char_data && !this.audioOnlyMode) {
330
334
  return null
331
335
  }
332
336
  }