@spatialwalk/avatarkit 1.0.0-beta.19 → 1.0.0-beta.20
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 +5 -0
- package/dist/{StreamingAudioPlayer-Cw8IygPS.js → StreamingAudioPlayer-Dv4D0GIN.js} +2 -2
- package/dist/{StreamingAudioPlayer-Cw8IygPS.js.map → StreamingAudioPlayer-Dv4D0GIN.js.map} +1 -1
- package/dist/core/AvatarController.d.ts.map +1 -1
- package/dist/{index-CRv3XrVE.js → index-Cm5BwNVd.js} +57 -60
- package/dist/{index-CRv3XrVE.js.map → index-Cm5BwNVd.js.map} +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.0-beta.20] - 2025-01-25
|
|
9
|
+
|
|
10
|
+
### 🔧 Improvements
|
|
11
|
+
- Removed 1-second audio buffer requirement for auto-starting playback in Host mode
|
|
12
|
+
|
|
8
13
|
## [1.0.0-beta.19] - 2025-01-25
|
|
9
14
|
|
|
10
15
|
### 📚 Documentation
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var C = Object.defineProperty;
|
|
2
2
|
var g = (h, t, e) => t in h ? C(h, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[t] = e;
|
|
3
3
|
var i = (h, t, e) => g(h, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { A as m, e as f, a as c, l as u } from "./index-
|
|
4
|
+
import { A as m, e as f, a as c, l as u } from "./index-Cm5BwNVd.js";
|
|
5
5
|
class y {
|
|
6
6
|
constructor(t) {
|
|
7
7
|
// AudioContext is managed internally
|
|
@@ -331,4 +331,4 @@ class y {
|
|
|
331
331
|
export {
|
|
332
332
|
y as StreamingAudioPlayer
|
|
333
333
|
};
|
|
334
|
-
//# sourceMappingURL=StreamingAudioPlayer-
|
|
334
|
+
//# sourceMappingURL=StreamingAudioPlayer-Dv4D0GIN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamingAudioPlayer-Cw8IygPS.js","sources":["../audio/StreamingAudioPlayer.ts"],"sourcesContent":["/**\n * Streaming Audio Player\n * Implements real-time audio playback using Web Audio API\n * Supports dynamic PCM chunk addition without Workers\n */\n\nimport { APP_CONFIG } from '../config/app-config'\nimport { AvatarKit } from '../core/AvatarKit'\nimport { errorToMessage } from '../utils/error-utils'\nimport { logger } from '../utils/logger'\n\nexport interface StreamingAudioPlayerOptions {\n sampleRate?: number // PCM sample rate (default: APP_CONFIG.audio.sampleRate, backend requires 16kHz)\n channelCount?: number // Number of channels (default: 1)\n debug?: boolean\n}\n\nexport class StreamingAudioPlayer {\n // AudioContext is managed internally\n private audioContext: AudioContext | null = null\n private sampleRate: number\n private channelCount: number\n private debug: boolean\n\n // Session-level state\n private sessionId: string\n private sessionStartTime = 0 // AudioContext time when session started\n private pausedTimeOffset = 0 // Accumulated paused time\n private pausedAt = 0 // Time when paused\n private pausedAudioContextTime = 0 // audioContext.currentTime when paused (for resume calculation)\n private scheduledTime = 0 // Next chunk schedule time in AudioContext time\n\n // Playback state\n private isPlaying = false\n private isPaused = false\n private autoStartEnabled = true // Control whether to auto-start when buffer is ready\n\n // Audio buffer queue\n private audioChunks: Array<{ data: Uint8Array, isLast: boolean }> = []\n private scheduledChunks = 0 // Number of chunks already scheduled\n private activeSources = new Set<AudioBufferSourceNode>()\n\n // Event callbacks\n private onEndedCallback?: () => void\n\n constructor(options?: StreamingAudioPlayerOptions) {\n this.sessionId = `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`\n this.sampleRate = options?.sampleRate ?? APP_CONFIG.audio.sampleRate\n this.channelCount = options?.channelCount ?? 1\n this.debug = options?.debug ?? false\n }\n\n /**\n * Initialize audio context (create and ensure it's ready)\n */\n async initialize(): Promise<void> {\n if (this.audioContext) {\n return\n }\n\n try {\n // Create AudioContext\n this.audioContext = new AudioContext({\n sampleRate: this.sampleRate,\n })\n\n // Resume context (required for some browsers)\n if (this.audioContext.state === 'suspended') {\n await this.audioContext.resume()\n }\n\n this.log('AudioContext initialized', {\n sessionId: this.sessionId,\n sampleRate: this.audioContext.sampleRate,\n state: this.audioContext.state,\n })\n }\n catch (error) {\n const message = errorToMessage(error)\n AvatarKit.logEvent('activeAudioSessionFailed', 'warning', {\n sessionId: this.sessionId,\n reason: message,\n })\n logger.error('Failed to initialize AudioContext:', message)\n throw error instanceof Error ? error : new Error(message)\n }\n }\n\n /**\n * Add audio chunk (16-bit PCM)\n */\n addChunk(pcmData: Uint8Array, isLast: boolean = false): void {\n if (!this.audioContext) {\n logger.error('AudioContext not initialized')\n return\n }\n\n // Store chunk with metadata\n this.audioChunks.push({ data: pcmData, isLast })\n\n // Track buffer underrun warning\n if (this.isPlaying && this.audioChunks.length === this.scheduledChunks) {\n // Buffer underrun detected - chunks consumed faster than added\n }\n\n this.log(`Added chunk ${this.audioChunks.length}`, {\n size: pcmData.length,\n totalChunks: this.audioChunks.length,\n isLast,\n isPlaying: this.isPlaying,\n scheduledChunks: this.scheduledChunks,\n })\n\n // Auto-start if we have any audio chunks and auto-start is enabled\n if (!this.isPlaying && this.autoStartEnabled && this.audioChunks.length > 0) {\n this.log('[StreamingAudioPlayer] Auto-starting playback from addChunk')\n this.startPlayback()\n }\n // Schedule next chunk if already playing and not paused\n else if (this.isPlaying && !this.isPaused) {\n this.log('[StreamingAudioPlayer] Already playing, scheduling next chunk')\n this.scheduleNextChunk()\n } else {\n this.log('[StreamingAudioPlayer] Not playing and no chunks, waiting for more chunks')\n }\n }\n\n /**\n * Start new session (stop current and start fresh)\n */\n async startNewSession(audioChunks: Array<{ data: Uint8Array, isLast: boolean }>): Promise<void> {\n // Stop current session if playing\n this.stop()\n\n // Generate new session ID to prevent data mixing\n this.sessionId = `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`\n\n // Reset session state\n this.audioChunks = []\n this.scheduledChunks = 0\n this.pausedTimeOffset = 0\n this.pausedAt = 0\n this.pausedAudioContextTime = 0\n // Don't set sessionStartTime or scheduledTime here - let startPlayback() set them\n this.log('Starting new session', {\n chunks: audioChunks.length,\n })\n\n // Add audio chunks with their metadata\n for (const chunk of audioChunks) {\n this.addChunk(chunk.data, chunk.isLast)\n }\n }\n\n /**\n * Start playback\n */\n private startPlayback(): void {\n if (!this.audioContext) {\n this.log('[StreamingAudioPlayer] Cannot start playback: AudioContext not initialized')\n return\n }\n if (this.isPlaying) {\n this.log('[StreamingAudioPlayer] Cannot start playback: Already playing')\n return\n }\n\n this.isPlaying = true\n this.sessionStartTime = this.audioContext.currentTime\n this.scheduledTime = this.sessionStartTime\n\n this.log('[StreamingAudioPlayer] Starting playback', {\n sessionStartTime: this.sessionStartTime,\n bufferedChunks: this.audioChunks.length,\n scheduledChunks: this.scheduledChunks,\n activeSources: this.activeSources.size,\n })\n\n // Schedule all available chunks\n this.scheduleAllChunks()\n }\n\n /**\n * Schedule all pending chunks\n */\n private scheduleAllChunks(): void {\n while (this.scheduledChunks < this.audioChunks.length) {\n this.scheduleNextChunk()\n }\n }\n\n /**\n * Schedule next audio chunk\n */\n private scheduleNextChunk(): void {\n if (!this.audioContext) {\n this.log('[StreamingAudioPlayer] Cannot schedule chunk: AudioContext not initialized')\n return\n }\n if (!this.isPlaying || this.isPaused) {\n this.log('[StreamingAudioPlayer] Cannot schedule chunk: Not playing or paused')\n return\n }\n\n const chunkIndex = this.scheduledChunks\n if (chunkIndex >= this.audioChunks.length) {\n this.log(`[StreamingAudioPlayer] No more chunks to schedule (chunkIndex: ${chunkIndex}, totalChunks: ${this.audioChunks.length})`)\n return\n }\n\n const chunk = this.audioChunks[chunkIndex]\n\n // 当音频块为空且不是最后一个块时,跳过调度\n if (chunk.data.length === 0 && !chunk.isLast) {\n this.scheduledChunks++\n return\n }\n\n const pcmData = chunk.data\n const isLast = chunk.isLast\n const audioBuffer = this.pcmToAudioBuffer(pcmData)\n\n if (!audioBuffer) {\n const errorMessage = 'Failed to create AudioBuffer from PCM data'\n logger.error(errorMessage)\n AvatarKit.logEvent('character_player', 'error', {\n sessionId: this.sessionId,\n event: 'audio_buffer_creation_failed',\n })\n return\n }\n\n try {\n // Create and configure source node\n const source = this.audioContext.createBufferSource()\n source.buffer = audioBuffer\n source.connect(this.audioContext.destination)\n\n // Schedule playback\n source.start(this.scheduledTime)\n\n // Track active source for hard-cancel\n this.activeSources.add(source)\n source.onended = () => {\n // Remove from active list when it ends\n this.activeSources.delete(source)\n\n // Check if this was the last chunk and all sources have ended\n if (isLast && this.activeSources.size === 0) {\n this.log('Last audio chunk ended, marking playback as ended')\n this.markEnded()\n }\n }\n\n // Update scheduled time for next chunk\n this.scheduledTime += audioBuffer.duration\n\n this.scheduledChunks++\n\n this.log(`[StreamingAudioPlayer] Scheduled chunk ${chunkIndex + 1}/${this.audioChunks.length}`, {\n startTime: this.scheduledTime - audioBuffer.duration,\n duration: audioBuffer.duration,\n nextScheduleTime: this.scheduledTime,\n isLast,\n activeSources: this.activeSources.size,\n })\n }\n catch (err) {\n logger.errorWithError('Failed to schedule audio chunk:', err)\n AvatarKit.logEvent('character_player', 'error', {\n sessionId: this.sessionId,\n event: 'schedule_chunk_failed',\n reason: err instanceof Error ? err.message : String(err),\n })\n }\n }\n\n /**\n * Convert PCM data to AudioBuffer\n * Input: 16-bit PCM (int16), Output: AudioBuffer (float32 [-1, 1])\n */\n private pcmToAudioBuffer(pcmData: Uint8Array): AudioBuffer | null {\n if (!this.audioContext) {\n return null\n }\n\n // Handle empty PCM data (e.g., when isLast is true)\n if (pcmData.length === 0) {\n // For empty chunks (typically the last chunk), create minimal silence\n // Use a very short duration to avoid playback stuttering\n const silenceDuration = 0.01 // 1ms - minimal silence to maintain timing\n const numSamples = Math.floor(this.sampleRate * silenceDuration)\n\n const audioBuffer = this.audioContext.createBuffer(\n this.channelCount,\n numSamples,\n this.sampleRate,\n )\n\n // Fill with silence (all zeros)\n for (let channel = 0; channel < this.channelCount; channel++) {\n const channelData = audioBuffer.getChannelData(channel)\n channelData.fill(0) // Fill with silence\n }\n\n return audioBuffer\n }\n\n // Create aligned copy to avoid byte offset issues\n // Int16Array requires byteOffset to be a multiple of 2\n const alignedData = new Uint8Array(pcmData)\n const int16Array = new Int16Array(alignedData.buffer, 0, alignedData.length / 2)\n\n // Calculate number of samples\n const numSamples = int16Array.length / this.channelCount\n\n // Create AudioBuffer\n const audioBuffer = this.audioContext.createBuffer(\n this.channelCount,\n numSamples,\n this.sampleRate,\n )\n\n // Convert int16 to float32 [-1, 1]\n for (let channel = 0; channel < this.channelCount; channel++) {\n const channelData = audioBuffer.getChannelData(channel)\n\n for (let i = 0; i < numSamples; i++) {\n const sampleIndex = i * this.channelCount + channel\n // Normalize int16 (-32768 to 32767) to float32 (-1 to 1)\n channelData[i] = int16Array[sampleIndex] / 32768.0\n }\n }\n\n return audioBuffer\n }\n\n /**\n * Get current playback time (seconds)\n */\n getCurrentTime(): number {\n if (!this.audioContext || !this.isPlaying) {\n return 0\n }\n\n if (this.isPaused) {\n return this.pausedAt\n }\n\n // Calculate elapsed time using session start time and paused offset\n const currentAudioTime = this.audioContext.currentTime\n const elapsed = currentAudioTime - this.sessionStartTime - this.pausedTimeOffset\n\n return Math.max(0, elapsed)\n }\n\n /**\n * Pause playback\n */\n pause(): void {\n if (!this.isPlaying || this.isPaused || !this.audioContext) {\n return\n }\n\n // 1. 记录逻辑时间(用于 getCurrentTime 返回固定值)\n this.pausedAt = this.getCurrentTime()\n\n // 2. 记录 AudioContext 时间戳(关键!用于恢复计算)\n this.pausedAudioContextTime = this.audioContext.currentTime\n\n // 3. 设置暂停标志\n this.isPaused = true\n\n // 4. 挂起 AudioContext 以暂停所有活动的音频源\n if (this.audioContext.state === 'running') {\n this.audioContext.suspend().catch((err) => {\n logger.errorWithError('Failed to suspend AudioContext:', err)\n // 如果挂起失败,恢复状态\n this.isPaused = false\n })\n }\n\n this.log('Playback paused', {\n pausedAt: this.pausedAt,\n pausedAudioContextTime: this.pausedAudioContextTime,\n audioContextState: this.audioContext.state,\n })\n }\n\n /**\n * Resume playback\n */\n async resume(): Promise<void> {\n if (!this.isPaused || !this.audioContext || !this.isPlaying) {\n return\n }\n\n // 1. 首先恢复 AudioContext(使 currentTime 继续)\n if (this.audioContext.state === 'suspended') {\n try {\n await this.audioContext.resume()\n }\n catch (err) {\n logger.errorWithError('Failed to resume AudioContext:', err)\n throw err\n }\n }\n\n // 2. 调整 sessionStartTime,使 getCurrentTime() 从 pausedAt 继续\n // 数学推导:\n // 恢复后,我们希望:getCurrentTime() = pausedAt + (currentAudioTime - pausedAudioContextTime)\n // 当前公式:getCurrentTime() = currentAudioTime - sessionStartTime - pausedTimeOffset\n //\n // 令两者相等:\n // pausedAt + (currentAudioTime - pausedAudioContextTime) = currentAudioTime - sessionStartTime - pausedTimeOffset\n // => sessionStartTime = pausedAudioContextTime - pausedAt - pausedTimeOffset\n const currentAudioTime = this.audioContext.currentTime\n this.sessionStartTime = this.pausedAudioContextTime - this.pausedAt - this.pausedTimeOffset\n\n // 3. 清除暂停标志\n this.isPaused = false\n\n // 4. 继续调度未调度的音频块(如果在暂停期间有新数据到达)\n if (this.scheduledChunks < this.audioChunks.length) {\n this.scheduleAllChunks()\n }\n\n this.log('Playback resumed', {\n pausedAt: this.pausedAt,\n pausedAudioContextTime: this.pausedAudioContextTime,\n currentAudioContextTime: currentAudioTime,\n adjustedSessionStartTime: this.sessionStartTime,\n audioContextState: this.audioContext.state,\n })\n }\n\n /**\n * Stop playback\n */\n stop(): void {\n if (!this.audioContext) {\n return\n }\n\n // 如果暂停,先恢复 AudioContext(以便正确停止源)\n if (this.isPaused && this.audioContext.state === 'suspended') {\n this.audioContext.resume().catch(() => {\n // 忽略恢复错误,因为我们要停止播放\n })\n this.isPaused = false\n }\n\n this.isPlaying = false\n this.isPaused = false\n this.sessionStartTime = 0 // Reset session start time\n this.scheduledTime = 0 // Reset scheduled time for next session\n\n // Hard stop all scheduled sources immediately\n for (const source of this.activeSources) {\n source.onended = null\n try {\n source.stop(0)\n }\n catch {}\n try {\n source.disconnect()\n }\n catch {}\n }\n this.activeSources.clear()\n\n // 清理音频块和调度状态,确保下次播放时状态干净\n this.audioChunks = []\n this.scheduledChunks = 0\n\n this.log('[StreamingAudioPlayer] Playback stopped, state reset')\n\n // Note: Individual source nodes will stop automatically\n // We just reset our state\n }\n\n /**\n * Enable or disable auto-start (for delayed start scenarios)\n */\n setAutoStart(enabled: boolean): void {\n this.autoStartEnabled = enabled\n this.log(`Auto-start ${enabled ? 'enabled' : 'disabled'}`)\n }\n\n /**\n * Start playback manually (for delayed start scenarios)\n * This allows starting playback after transition animation completes\n */\n play(): void {\n if (this.isPlaying) {\n return\n }\n // Enable auto-start when manually starting playback\n this.autoStartEnabled = true\n this.startPlayback()\n }\n\n /**\n * Mark playback as ended\n */\n markEnded(): void {\n this.log('Playback ended')\n this.isPlaying = false\n this.onEndedCallback?.()\n }\n\n /**\n * Set ended callback\n */\n onEnded(callback: () => void): void {\n this.onEndedCallback = callback\n }\n\n /**\n * Check if playing\n */\n isPlayingNow(): boolean {\n return this.isPlaying && !this.isPaused\n }\n\n /**\n * Get total duration of buffered audio\n */\n getBufferedDuration(): number {\n if (!this.audioContext) {\n return 0\n }\n\n let totalSamples = 0\n for (const chunk of this.audioChunks) {\n totalSamples += chunk.data.length / 2 / this.channelCount // 16-bit = 2 bytes per sample\n }\n\n return totalSamples / this.sampleRate\n }\n\n /**\n * Get remaining duration (buffered - played) in seconds\n */\n getRemainingDuration(): number {\n const total = this.getBufferedDuration()\n const played = this.getCurrentTime()\n return Math.max(0, total - played)\n }\n\n\n /**\n * Dispose and cleanup\n */\n dispose(): void {\n this.stop()\n\n // Close AudioContext\n if (this.audioContext) {\n this.audioContext.close()\n this.audioContext = null\n }\n\n // Clear session state\n this.audioChunks = []\n this.scheduledChunks = 0\n this.sessionStartTime = 0\n this.pausedTimeOffset = 0\n this.pausedAt = 0\n this.pausedAudioContextTime = 0\n this.scheduledTime = 0\n this.onEndedCallback = undefined\n\n this.log('StreamingAudioPlayer disposed')\n }\n\n /**\n * Flush buffered audio\n * - hard: stops all playing sources and clears all chunks\n * - soft (default): clears UNSCHEDULED chunks only\n */\n flush(options?: { hard?: boolean }): void {\n const hard = options?.hard === true\n if (hard) {\n this.stop()\n this.audioChunks = []\n this.scheduledChunks = 0\n this.sessionStartTime = 0\n this.pausedAt = 0\n this.scheduledTime = 0\n this.log('Flushed (hard)')\n return\n }\n\n // Soft flush: drop unscheduled region\n if (this.scheduledChunks < this.audioChunks.length) {\n this.audioChunks.splice(this.scheduledChunks)\n }\n this.log('Flushed (soft)', { remainingScheduled: this.scheduledChunks })\n }\n\n /**\n * Debug logging\n */\n private log(message: string, data?: unknown): void {\n if (this.debug) {\n logger.log(`[StreamingAudioPlayer] ${message}`, data || '')\n }\n }\n}\n"],"names":["StreamingAudioPlayer","options","__publicField","APP_CONFIG","error","message","errorToMessage","AvatarKit","logger","pcmData","isLast","audioChunks","chunk","chunkIndex","audioBuffer","source","err","numSamples","channel","alignedData","int16Array","channelData","i","sampleIndex","elapsed","currentAudioTime","enabled","_a","callback","totalSamples","total","played","data"],"mappings":";;;;AAiBO,MAAMA,EAAqB;AAAA,EA4BhC,YAAYC,GAAuC;AA1B3C;AAAA,IAAAC,EAAA,sBAAoC;AACpC,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAGA;AAAA,IAAAA,EAAA;AACA,IAAAA,EAAA,0BAAmB;AACnB;AAAA,IAAAA,EAAA,0BAAmB;AACnB;AAAA,IAAAA,EAAA,kBAAW;AACX;AAAA,IAAAA,EAAA,gCAAyB;AACzB;AAAA,IAAAA,EAAA,uBAAgB;AAGhB;AAAA;AAAA,IAAAA,EAAA,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oB,KAAK,iBAAiB;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKQ,IAAII,GAAiB2B,GAAsB;AACjD,IAAI,KAAK,SACPxB,EAAO,IAAI,0BAA0BH,CAAO,IAAI2B,KAAQ,EAAE;AAAA,EAE9D;AACF;"}
|
|
1
|
+
{"version":3,"file":"StreamingAudioPlayer-Dv4D0GIN.js","sources":["../audio/StreamingAudioPlayer.ts"],"sourcesContent":["/**\n * Streaming Audio Player\n * Implements real-time audio playback using Web Audio API\n * Supports dynamic PCM chunk addition without Workers\n */\n\nimport { APP_CONFIG } from '../config/app-config'\nimport { AvatarKit } from '../core/AvatarKit'\nimport { errorToMessage } from '../utils/error-utils'\nimport { logger } from '../utils/logger'\n\nexport interface StreamingAudioPlayerOptions {\n sampleRate?: number // PCM sample rate (default: APP_CONFIG.audio.sampleRate, backend requires 16kHz)\n channelCount?: number // Number of channels (default: 1)\n debug?: boolean\n}\n\nexport class StreamingAudioPlayer {\n // AudioContext is managed internally\n private audioContext: AudioContext | null = null\n private sampleRate: number\n private channelCount: number\n private debug: boolean\n\n // Session-level state\n private sessionId: string\n private sessionStartTime = 0 // AudioContext time when session started\n private pausedTimeOffset = 0 // Accumulated paused time\n private pausedAt = 0 // Time when paused\n private pausedAudioContextTime = 0 // audioContext.currentTime when paused (for resume calculation)\n private scheduledTime = 0 // Next chunk schedule time in AudioContext time\n\n // Playback state\n private isPlaying = false\n private isPaused = false\n private autoStartEnabled = true // Control whether to auto-start when buffer is ready\n\n // Audio buffer queue\n private audioChunks: Array<{ data: Uint8Array, isLast: boolean }> = []\n private scheduledChunks = 0 // Number of chunks already scheduled\n private activeSources = new Set<AudioBufferSourceNode>()\n\n // Event callbacks\n private onEndedCallback?: () => void\n\n constructor(options?: StreamingAudioPlayerOptions) {\n this.sessionId = `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`\n this.sampleRate = options?.sampleRate ?? APP_CONFIG.audio.sampleRate\n this.channelCount = options?.channelCount ?? 1\n this.debug = options?.debug ?? false\n }\n\n /**\n * Initialize audio context (create and ensure it's ready)\n */\n async initialize(): Promise<void> {\n if (this.audioContext) {\n return\n }\n\n try {\n // Create AudioContext\n this.audioContext = new AudioContext({\n sampleRate: this.sampleRate,\n })\n\n // Resume context (required for some browsers)\n if (this.audioContext.state === 'suspended') {\n await this.audioContext.resume()\n }\n\n this.log('AudioContext initialized', {\n sessionId: this.sessionId,\n sampleRate: this.audioContext.sampleRate,\n state: this.audioContext.state,\n })\n }\n catch (error) {\n const message = errorToMessage(error)\n AvatarKit.logEvent('activeAudioSessionFailed', 'warning', {\n sessionId: this.sessionId,\n reason: message,\n })\n logger.error('Failed to initialize AudioContext:', message)\n throw error instanceof Error ? error : new Error(message)\n }\n }\n\n /**\n * Add audio chunk (16-bit PCM)\n */\n addChunk(pcmData: Uint8Array, isLast: boolean = false): void {\n if (!this.audioContext) {\n logger.error('AudioContext not initialized')\n return\n }\n\n // Store chunk with metadata\n this.audioChunks.push({ data: pcmData, isLast })\n\n // Track buffer underrun warning\n if (this.isPlaying && this.audioChunks.length === this.scheduledChunks) {\n // Buffer underrun detected - chunks consumed faster than added\n }\n\n this.log(`Added chunk ${this.audioChunks.length}`, {\n size: pcmData.length,\n totalChunks: this.audioChunks.length,\n isLast,\n isPlaying: this.isPlaying,\n scheduledChunks: this.scheduledChunks,\n })\n\n // Auto-start if we have any audio chunks and auto-start is enabled\n if (!this.isPlaying && this.autoStartEnabled && this.audioChunks.length > 0) {\n this.log('[StreamingAudioPlayer] Auto-starting playback from addChunk')\n this.startPlayback()\n }\n // Schedule next chunk if already playing and not paused\n else if (this.isPlaying && !this.isPaused) {\n this.log('[StreamingAudioPlayer] Already playing, scheduling next chunk')\n this.scheduleNextChunk()\n } else {\n this.log('[StreamingAudioPlayer] Not playing and no chunks, waiting for more chunks')\n }\n }\n\n /**\n * Start new session (stop current and start fresh)\n */\n async startNewSession(audioChunks: Array<{ data: Uint8Array, isLast: boolean }>): Promise<void> {\n // Stop current session if playing\n this.stop()\n\n // Generate new session ID to prevent data mixing\n this.sessionId = `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`\n\n // Reset session state\n this.audioChunks = []\n this.scheduledChunks = 0\n this.pausedTimeOffset = 0\n this.pausedAt = 0\n this.pausedAudioContextTime = 0\n // Don't set sessionStartTime or scheduledTime here - let startPlayback() set them\n this.log('Starting new session', {\n chunks: audioChunks.length,\n })\n\n // Add audio chunks with their metadata\n for (const chunk of audioChunks) {\n this.addChunk(chunk.data, chunk.isLast)\n }\n }\n\n /**\n * Start playback\n */\n private startPlayback(): void {\n if (!this.audioContext) {\n this.log('[StreamingAudioPlayer] Cannot start playback: AudioContext not initialized')\n return\n }\n if (this.isPlaying) {\n this.log('[StreamingAudioPlayer] Cannot start playback: Already playing')\n return\n }\n\n this.isPlaying = true\n this.sessionStartTime = this.audioContext.currentTime\n this.scheduledTime = this.sessionStartTime\n\n this.log('[StreamingAudioPlayer] Starting playback', {\n sessionStartTime: this.sessionStartTime,\n bufferedChunks: this.audioChunks.length,\n scheduledChunks: this.scheduledChunks,\n activeSources: this.activeSources.size,\n })\n\n // Schedule all available chunks\n this.scheduleAllChunks()\n }\n\n /**\n * Schedule all pending chunks\n */\n private scheduleAllChunks(): void {\n while (this.scheduledChunks < this.audioChunks.length) {\n this.scheduleNextChunk()\n }\n }\n\n /**\n * Schedule next audio chunk\n */\n private scheduleNextChunk(): void {\n if (!this.audioContext) {\n this.log('[StreamingAudioPlayer] Cannot schedule chunk: AudioContext not initialized')\n return\n }\n if (!this.isPlaying || this.isPaused) {\n this.log('[StreamingAudioPlayer] Cannot schedule chunk: Not playing or paused')\n return\n }\n\n const chunkIndex = this.scheduledChunks\n if (chunkIndex >= this.audioChunks.length) {\n this.log(`[StreamingAudioPlayer] No more chunks to schedule (chunkIndex: ${chunkIndex}, totalChunks: ${this.audioChunks.length})`)\n return\n }\n\n const chunk = this.audioChunks[chunkIndex]\n\n // 当音频块为空且不是最后一个块时,跳过调度\n if (chunk.data.length === 0 && !chunk.isLast) {\n this.scheduledChunks++\n return\n }\n\n const pcmData = chunk.data\n const isLast = chunk.isLast\n const audioBuffer = this.pcmToAudioBuffer(pcmData)\n\n if (!audioBuffer) {\n const errorMessage = 'Failed to create AudioBuffer from PCM data'\n logger.error(errorMessage)\n AvatarKit.logEvent('character_player', 'error', {\n sessionId: this.sessionId,\n event: 'audio_buffer_creation_failed',\n })\n return\n }\n\n try {\n // Create and configure source node\n const source = this.audioContext.createBufferSource()\n source.buffer = audioBuffer\n source.connect(this.audioContext.destination)\n\n // Schedule playback\n source.start(this.scheduledTime)\n\n // Track active source for hard-cancel\n this.activeSources.add(source)\n source.onended = () => {\n // Remove from active list when it ends\n this.activeSources.delete(source)\n\n // Check if this was the last chunk and all sources have ended\n if (isLast && this.activeSources.size === 0) {\n this.log('Last audio chunk ended, marking playback as ended')\n this.markEnded()\n }\n }\n\n // Update scheduled time for next chunk\n this.scheduledTime += audioBuffer.duration\n\n this.scheduledChunks++\n\n this.log(`[StreamingAudioPlayer] Scheduled chunk ${chunkIndex + 1}/${this.audioChunks.length}`, {\n startTime: this.scheduledTime - audioBuffer.duration,\n duration: audioBuffer.duration,\n nextScheduleTime: this.scheduledTime,\n isLast,\n activeSources: this.activeSources.size,\n })\n }\n catch (err) {\n logger.errorWithError('Failed to schedule audio chunk:', err)\n AvatarKit.logEvent('character_player', 'error', {\n sessionId: this.sessionId,\n event: 'schedule_chunk_failed',\n reason: err instanceof Error ? err.message : String(err),\n })\n }\n }\n\n /**\n * Convert PCM data to AudioBuffer\n * Input: 16-bit PCM (int16), Output: AudioBuffer (float32 [-1, 1])\n */\n private pcmToAudioBuffer(pcmData: Uint8Array): AudioBuffer | null {\n if (!this.audioContext) {\n return null\n }\n\n // Handle empty PCM data (e.g., when isLast is true)\n if (pcmData.length === 0) {\n // For empty chunks (typically the last chunk), create minimal silence\n // Use a very short duration to avoid playback stuttering\n const silenceDuration = 0.01 // 1ms - minimal silence to maintain timing\n const numSamples = Math.floor(this.sampleRate * silenceDuration)\n\n const audioBuffer = this.audioContext.createBuffer(\n this.channelCount,\n numSamples,\n this.sampleRate,\n )\n\n // Fill with silence (all zeros)\n for (let channel = 0; channel < this.channelCount; channel++) {\n const channelData = audioBuffer.getChannelData(channel)\n channelData.fill(0) // Fill with silence\n }\n\n return audioBuffer\n }\n\n // Create aligned copy to avoid byte offset issues\n // Int16Array requires byteOffset to be a multiple of 2\n const alignedData = new Uint8Array(pcmData)\n const int16Array = new Int16Array(alignedData.buffer, 0, alignedData.length / 2)\n\n // Calculate number of samples\n const numSamples = int16Array.length / this.channelCount\n\n // Create AudioBuffer\n const audioBuffer = this.audioContext.createBuffer(\n this.channelCount,\n numSamples,\n this.sampleRate,\n )\n\n // Convert int16 to float32 [-1, 1]\n for (let channel = 0; channel < this.channelCount; channel++) {\n const channelData = audioBuffer.getChannelData(channel)\n\n for (let i = 0; i < numSamples; i++) {\n const sampleIndex = i * this.channelCount + channel\n // Normalize int16 (-32768 to 32767) to float32 (-1 to 1)\n channelData[i] = int16Array[sampleIndex] / 32768.0\n }\n }\n\n return audioBuffer\n }\n\n /**\n * Get current playback time (seconds)\n */\n getCurrentTime(): number {\n if (!this.audioContext || !this.isPlaying) {\n return 0\n }\n\n if (this.isPaused) {\n return this.pausedAt\n }\n\n // Calculate elapsed time using session start time and paused offset\n const currentAudioTime = this.audioContext.currentTime\n const elapsed = currentAudioTime - this.sessionStartTime - this.pausedTimeOffset\n\n return Math.max(0, elapsed)\n }\n\n /**\n * Pause playback\n */\n pause(): void {\n if (!this.isPlaying || this.isPaused || !this.audioContext) {\n return\n }\n\n // 1. 记录逻辑时间(用于 getCurrentTime 返回固定值)\n this.pausedAt = this.getCurrentTime()\n\n // 2. 记录 AudioContext 时间戳(关键!用于恢复计算)\n this.pausedAudioContextTime = this.audioContext.currentTime\n\n // 3. 设置暂停标志\n this.isPaused = true\n\n // 4. 挂起 AudioContext 以暂停所有活动的音频源\n if (this.audioContext.state === 'running') {\n this.audioContext.suspend().catch((err) => {\n logger.errorWithError('Failed to suspend AudioContext:', err)\n // 如果挂起失败,恢复状态\n this.isPaused = false\n })\n }\n\n this.log('Playback paused', {\n pausedAt: this.pausedAt,\n pausedAudioContextTime: this.pausedAudioContextTime,\n audioContextState: this.audioContext.state,\n })\n }\n\n /**\n * Resume playback\n */\n async resume(): Promise<void> {\n if (!this.isPaused || !this.audioContext || !this.isPlaying) {\n return\n }\n\n // 1. 首先恢复 AudioContext(使 currentTime 继续)\n if (this.audioContext.state === 'suspended') {\n try {\n await this.audioContext.resume()\n }\n catch (err) {\n logger.errorWithError('Failed to resume AudioContext:', err)\n throw err\n }\n }\n\n // 2. 调整 sessionStartTime,使 getCurrentTime() 从 pausedAt 继续\n // 数学推导:\n // 恢复后,我们希望:getCurrentTime() = pausedAt + (currentAudioTime - pausedAudioContextTime)\n // 当前公式:getCurrentTime() = currentAudioTime - sessionStartTime - pausedTimeOffset\n //\n // 令两者相等:\n // pausedAt + (currentAudioTime - pausedAudioContextTime) = currentAudioTime - sessionStartTime - pausedTimeOffset\n // => sessionStartTime = pausedAudioContextTime - pausedAt - pausedTimeOffset\n const currentAudioTime = this.audioContext.currentTime\n this.sessionStartTime = this.pausedAudioContextTime - this.pausedAt - this.pausedTimeOffset\n\n // 3. 清除暂停标志\n this.isPaused = false\n\n // 4. 继续调度未调度的音频块(如果在暂停期间有新数据到达)\n if (this.scheduledChunks < this.audioChunks.length) {\n this.scheduleAllChunks()\n }\n\n this.log('Playback resumed', {\n pausedAt: this.pausedAt,\n pausedAudioContextTime: this.pausedAudioContextTime,\n currentAudioContextTime: currentAudioTime,\n adjustedSessionStartTime: this.sessionStartTime,\n audioContextState: this.audioContext.state,\n })\n }\n\n /**\n * Stop playback\n */\n stop(): void {\n if (!this.audioContext) {\n return\n }\n\n // 如果暂停,先恢复 AudioContext(以便正确停止源)\n if (this.isPaused && this.audioContext.state === 'suspended') {\n this.audioContext.resume().catch(() => {\n // 忽略恢复错误,因为我们要停止播放\n })\n this.isPaused = false\n }\n\n this.isPlaying = false\n this.isPaused = false\n this.sessionStartTime = 0 // Reset session start time\n this.scheduledTime = 0 // Reset scheduled time for next session\n\n // Hard stop all scheduled sources immediately\n for (const source of this.activeSources) {\n source.onended = null\n try {\n source.stop(0)\n }\n catch {}\n try {\n source.disconnect()\n }\n catch {}\n }\n this.activeSources.clear()\n\n // 清理音频块和调度状态,确保下次播放时状态干净\n this.audioChunks = []\n this.scheduledChunks = 0\n\n this.log('[StreamingAudioPlayer] Playback stopped, state reset')\n\n // Note: Individual source nodes will stop automatically\n // We just reset our state\n }\n\n /**\n * Enable or disable auto-start (for delayed start scenarios)\n */\n setAutoStart(enabled: boolean): void {\n this.autoStartEnabled = enabled\n this.log(`Auto-start ${enabled ? 'enabled' : 'disabled'}`)\n }\n\n /**\n * Start playback manually (for delayed start scenarios)\n * This allows starting playback after transition animation completes\n */\n play(): void {\n if (this.isPlaying) {\n return\n }\n // Enable auto-start when manually starting playback\n this.autoStartEnabled = true\n this.startPlayback()\n }\n\n /**\n * Mark playback as ended\n */\n markEnded(): void {\n this.log('Playback ended')\n this.isPlaying = false\n this.onEndedCallback?.()\n }\n\n /**\n * Set ended callback\n */\n onEnded(callback: () => void): void {\n this.onEndedCallback = callback\n }\n\n /**\n * Check if playing\n */\n isPlayingNow(): boolean {\n return this.isPlaying && !this.isPaused\n }\n\n /**\n * Get total duration of buffered audio\n */\n getBufferedDuration(): number {\n if (!this.audioContext) {\n return 0\n }\n\n let totalSamples = 0\n for (const chunk of this.audioChunks) {\n totalSamples += chunk.data.length / 2 / this.channelCount // 16-bit = 2 bytes per sample\n }\n\n return totalSamples / this.sampleRate\n }\n\n /**\n * Get remaining duration (buffered - played) in seconds\n */\n getRemainingDuration(): number {\n const total = this.getBufferedDuration()\n const played = this.getCurrentTime()\n return Math.max(0, total - played)\n }\n\n\n /**\n * Dispose and cleanup\n */\n dispose(): void {\n this.stop()\n\n // Close AudioContext\n if (this.audioContext) {\n this.audioContext.close()\n this.audioContext = null\n }\n\n // Clear session state\n this.audioChunks = []\n this.scheduledChunks = 0\n this.sessionStartTime = 0\n this.pausedTimeOffset = 0\n this.pausedAt = 0\n this.pausedAudioContextTime = 0\n this.scheduledTime = 0\n this.onEndedCallback = undefined\n\n this.log('StreamingAudioPlayer disposed')\n }\n\n /**\n * Flush buffered audio\n * - hard: stops all playing sources and clears all chunks\n * - soft (default): clears UNSCHEDULED chunks only\n */\n flush(options?: { hard?: boolean }): void {\n const hard = options?.hard === true\n if (hard) {\n this.stop()\n this.audioChunks = []\n this.scheduledChunks = 0\n this.sessionStartTime = 0\n this.pausedAt = 0\n this.scheduledTime = 0\n this.log('Flushed (hard)')\n return\n }\n\n // Soft flush: drop unscheduled region\n if (this.scheduledChunks < this.audioChunks.length) {\n this.audioChunks.splice(this.scheduledChunks)\n }\n this.log('Flushed (soft)', { remainingScheduled: this.scheduledChunks })\n }\n\n /**\n * Debug logging\n */\n private log(message: string, data?: unknown): void {\n if (this.debug) {\n logger.log(`[StreamingAudioPlayer] ${message}`, data || '')\n }\n }\n}\n"],"names":["StreamingAudioPlayer","options","__publicField","APP_CONFIG","error","message","errorToMessage","AvatarKit","logger","pcmData","isLast","audioChunks","chunk","chunkIndex","audioBuffer","source","err","numSamples","channel","alignedData","int16Array","channelData","i","sampleIndex","elapsed","currentAudioTime","enabled","_a","callback","totalSamples","total","played","data"],"mappings":";;;;AAiBO,MAAMA,EAAqB;AAAA,EA4BhC,YAAYC,GAAuC;AA1B3C;AAAA,IAAAC,EAAA,sBAAoC;AACpC,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAGA;AAAA,IAAAA,EAAA;AACA,IAAAA,EAAA,0BAAmB;AACnB;AAAA,IAAAA,EAAA,0BAAmB;AACnB;AAAA,IAAAA,EAAA,kBAAW;AACX;AAAA,IAAAA,EAAA,gCAAyB;AACzB;AAAA,IAAAA,EAAA,uBAAgB;AAGhB;AAAA;AAAA,IAAAA,EAAA,mBAAY;AACZ,I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AI;IAqBjB;;OAEG;IACH,KAAK,IAAI,IAAI;IAqCb;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAUvC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAYhC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IA0ElC;;OAEG;YACW,8BAA8B;IA4F5C;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA2GzB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAiB3B;;;OAGG;YACW,sBAAsB;IA6EpC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAwBhC;;OAEG;IACH,SAAS,CAAC,YAAY,IAAI,IAAI;IAa9B;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;IAOhC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;OAEG;IACH,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;CAMhD"}
|
|
@@ -52,7 +52,7 @@ function ln() {
|
|
|
52
52
|
function cn() {
|
|
53
53
|
return ln();
|
|
54
54
|
}
|
|
55
|
-
const
|
|
55
|
+
const k = {
|
|
56
56
|
// Dynamic debug mode check (includes URL parameter)
|
|
57
57
|
get debug() {
|
|
58
58
|
return cn();
|
|
@@ -351,12 +351,12 @@ let mt = () => {
|
|
|
351
351
|
w[P] = !0;
|
|
352
352
|
}
|
|
353
353
|
return (C) => {
|
|
354
|
-
const P = C.index,
|
|
355
|
-
for (; C.index <
|
|
354
|
+
const P = C.index, I = C.input;
|
|
355
|
+
for (; C.index < I.length && I.charCodeAt(C.index) in w; ) C.index += 1;
|
|
356
356
|
const T = C.index;
|
|
357
357
|
if (T > P) {
|
|
358
358
|
if (!b(g) && !C.options.silent) {
|
|
359
|
-
const $ = C.input.slice(P, T), q = c(g) ? g($,
|
|
359
|
+
const $ = C.input.slice(P, T), q = c(g) ? g($, I, String(P)) : g;
|
|
360
360
|
b(q) || C.output.push(q);
|
|
361
361
|
}
|
|
362
362
|
C.indexMax = Math.max(C.indexMax, C.index);
|
|
@@ -365,15 +365,15 @@ let mt = () => {
|
|
|
365
365
|
};
|
|
366
366
|
}, G = (f, g) => {
|
|
367
367
|
const w = f.source, C = f.flags.replace(/y|$/, "y"), P = new RegExp(w, C);
|
|
368
|
-
return be((
|
|
369
|
-
P.lastIndex =
|
|
370
|
-
const T = P.exec(
|
|
368
|
+
return be((I) => {
|
|
369
|
+
P.lastIndex = I.index;
|
|
370
|
+
const T = P.exec(I.input);
|
|
371
371
|
if (T) {
|
|
372
|
-
if (!b(g) && !
|
|
373
|
-
const $ = c(g) ? g(...T,
|
|
374
|
-
b($) ||
|
|
372
|
+
if (!b(g) && !I.options.silent) {
|
|
373
|
+
const $ = c(g) ? g(...T, I.input, String(I.index)) : g;
|
|
374
|
+
b($) || I.output.push($);
|
|
375
375
|
}
|
|
376
|
-
return
|
|
376
|
+
return I.index += T[0].length, I.indexMax = Math.max(I.indexMax, I.index), !0;
|
|
377
377
|
} else return !1;
|
|
378
378
|
});
|
|
379
379
|
}, R = (f, g) => (w) => {
|
|
@@ -386,31 +386,31 @@ let mt = () => {
|
|
|
386
386
|
} else return !1;
|
|
387
387
|
}, z = (f, g, w, C) => {
|
|
388
388
|
const P = Z(f);
|
|
389
|
-
return be(xe(Xe((
|
|
389
|
+
return be(xe(Xe((I) => {
|
|
390
390
|
let T = 0;
|
|
391
391
|
for (; T < w; ) {
|
|
392
|
-
const $ =
|
|
393
|
-
if (!P(
|
|
392
|
+
const $ = I.index;
|
|
393
|
+
if (!P(I) || (T += 1, I.index === $)) break;
|
|
394
394
|
}
|
|
395
395
|
return T >= g;
|
|
396
396
|
})));
|
|
397
397
|
}, W = (f, g) => z(f, 0, 1), Y = (f, g) => z(f, 0, 1 / 0), V = (f, g) => {
|
|
398
398
|
const w = f.map(Z);
|
|
399
399
|
return be(xe(Xe((C) => {
|
|
400
|
-
for (let P = 0,
|
|
400
|
+
for (let P = 0, I = w.length; P < I; P++) if (!w[P](C)) return !1;
|
|
401
401
|
return !0;
|
|
402
402
|
})));
|
|
403
403
|
}, j = (f, g) => {
|
|
404
404
|
const w = f.map(Z);
|
|
405
405
|
return be(xe((C) => {
|
|
406
|
-
for (let P = 0,
|
|
406
|
+
for (let P = 0, I = w.length; P < I; P++) if (w[P](C)) return !0;
|
|
407
407
|
return !1;
|
|
408
408
|
}));
|
|
409
409
|
}, Xe = (f, g = !1) => {
|
|
410
410
|
const w = Z(f);
|
|
411
411
|
return (C) => {
|
|
412
|
-
const P = C.index,
|
|
413
|
-
return (!T || g) && (C.index = P, C.output.length !==
|
|
412
|
+
const P = C.index, I = C.output.length, T = w(C);
|
|
413
|
+
return (!T || g) && (C.index = P, C.output.length !== I && (C.output.length = I)), T;
|
|
414
414
|
};
|
|
415
415
|
}, xe = (f, g) => Z(f), be = /* @__PURE__ */ (() => {
|
|
416
416
|
let f = 0;
|
|
@@ -418,9 +418,9 @@ let mt = () => {
|
|
|
418
418
|
const w = Z(g), C = f += 1;
|
|
419
419
|
return (P) => {
|
|
420
420
|
var lt;
|
|
421
|
-
var
|
|
421
|
+
var I;
|
|
422
422
|
if (P.options.memoization === !1) return w(P);
|
|
423
|
-
const T = P.index, $ = (
|
|
423
|
+
const T = P.index, $ = (I = P.cache)[C] || (I[C] = /* @__PURE__ */ new Map()), q = $.get(T);
|
|
424
424
|
if (q === !1) return !1;
|
|
425
425
|
if (m(q)) return P.index = q, !0;
|
|
426
426
|
if (q) return P.index = q.index, (lt = q.output) != null && lt.length && P.output.push(...q.output), !0;
|
|
@@ -468,8 +468,8 @@ let mt = () => {
|
|
|
468
468
|
}, cr = _(/^\*\*\/\*$/, ".*"), dr = _(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (f, g, w) => `.*${g ? "" : "(?:^|/)"}${w.replaceAll(".", "\\.")}`), ur = _(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (f, g, w, C) => `.*${g ? "" : "(?:^|/)"}${w.replaceAll(".", "\\.")}(?:${C.replaceAll(",", "|").replaceAll(".", "\\.")})`), Me = _(/\\./, K), hr = _(/[$.*+?^(){}[\]\|]/, (f) => `\\${f}`), fr = _(/./, K), mr = _(/^(?:!!)*!(.*)$/, (f, g) => `(?!^${ot(g)}$).*?`), pr = _(/^(!!)+/, ""), gr = j([mr, pr]), vr = _(/\/(\*\*\/)+/, "(?:/.+/|/)"), yr = _(/^(\*\*\/)+/, "(?:^|.*/)"), wr = _(/\/(\*\*)$/, "(?:/.*|$)"), Ar = _(/\*\*/, ".*"), tt = j([vr, yr, wr, Ar]), Sr = _(/\*\/(?!\*\*\/)/, "[^/]*/"), br = _(/\*/, "[^/]*"), rt = j([Sr, br]), nt = _("?", "[^/]"), Cr = _("[", K), _r = _("]", K), Pr = _(/[!^]/, "^/"), Er = _(/[a-z]-[a-z]|[0-9]-[0-9]/i, K), Ir = _(/[$.*+?^(){}[\|]/, (f) => `\\${f}`), kr = _(/[^\]]/, K), xr = j([Me, Ir, Er, kr]), at = V([Cr, W(Pr), Y(xr), _r]), Fr = _("{", "(?:"), Mr = _("}", ")"), Lr = _(/(\d+)\.\.(\d+)/, (f, g, w) => or(+g, +w, Math.min(g.length, w.length)).join("|")), Rr = _(/([a-z]+)\.\.([a-z]+)/, (f, g, w) => Qe(g, w).join("|")), Tr = _(/([A-Z]+)\.\.([A-Z]+)/, (f, g, w) => Qe(g.toLowerCase(), w.toLowerCase()).join("|").toUpperCase()), Br = j([Lr, Rr, Tr]), it = V([Fr, Br, Mr]), Dr = _("{", "(?:"), Or = _("}", ")"), Nr = _(",", "|"), Ur = _(/[$.*+?^(){[\]\|]/, (f) => `\\${f}`), zr = _(/[^}]/, K), Vr = Ye(() => st), $r = j([tt, rt, nt, at, it, Vr, Me, Ur, Nr, zr]), st = V([Dr, Y($r), Or]), Gr = Y(j([cr, dr, ur, gr, tt, rt, nt, at, it, st, Me, hr, fr])), Wr = Gr, qr = et(Wr), ot = qr, Hr = _(/\\./, K), jr = _(/./, K), Kr = _(/\*\*\*+/, "*"), Xr = _(/([^/{[(!])\*\*/, (f, g) => `${g}*`), Yr = _(/(^|.)\*\*(?=[^*/)\]}])/, (f, g) => `${g}*`), Zr = Y(j([Hr, Kr, Xr, Yr, jr])), Jr = Zr, Qr = et(Jr), en = Qr, Le = (f, g) => {
|
|
469
469
|
const w = Array.isArray(f) ? f : [f];
|
|
470
470
|
if (!w.length) return !1;
|
|
471
|
-
const C = w.map(Le.compile), P = w.every((T) => /(\/(?:\*\*)?|\[\/\])$/.test(T)),
|
|
472
|
-
return C.some((T) => T.test(
|
|
471
|
+
const C = w.map(Le.compile), P = w.every((T) => /(\/(?:\*\*)?|\[\/\])$/.test(T)), I = g.replace(/[\\\/]+/g, "/").replace(/\/$/, P ? "/" : "");
|
|
472
|
+
return C.some((T) => T.test(I));
|
|
473
473
|
};
|
|
474
474
|
Le.compile = (f) => new RegExp(`^${ot(en(f))}$`, "s");
|
|
475
475
|
var tn = Le;
|
|
@@ -2065,7 +2065,7 @@ const we = class we {
|
|
|
2065
2065
|
d(this, "audio", null);
|
|
2066
2066
|
d(this, "streamingPlayer", null);
|
|
2067
2067
|
d(this, "_isPlaying", !1);
|
|
2068
|
-
d(this, "fps",
|
|
2068
|
+
d(this, "fps", k.animation.fps);
|
|
2069
2069
|
d(this, "onEndedCallback");
|
|
2070
2070
|
d(this, "useStreaming", !1);
|
|
2071
2071
|
}
|
|
@@ -2123,9 +2123,9 @@ const we = class we {
|
|
|
2123
2123
|
async createAndInitializeStreamingPlayer() {
|
|
2124
2124
|
if (this.streamingPlayer)
|
|
2125
2125
|
return;
|
|
2126
|
-
const { StreamingAudioPlayer: e } = await import("./StreamingAudioPlayer-
|
|
2126
|
+
const { StreamingAudioPlayer: e } = await import("./StreamingAudioPlayer-Dv4D0GIN.js");
|
|
2127
2127
|
this.streamingPlayer = new e({
|
|
2128
|
-
sampleRate:
|
|
2128
|
+
sampleRate: k.audio.sampleRate,
|
|
2129
2129
|
channelCount: 1,
|
|
2130
2130
|
debug: !1
|
|
2131
2131
|
});
|
|
@@ -3450,7 +3450,7 @@ class ba {
|
|
|
3450
3450
|
d(this, "dataController");
|
|
3451
3451
|
// 组合播放层
|
|
3452
3452
|
d(this, "currentConversationId", null);
|
|
3453
|
-
d(this, "audioBytesPerSecond",
|
|
3453
|
+
d(this, "audioBytesPerSecond", k.audio.sampleRate * 2);
|
|
3454
3454
|
d(this, "audioMetrics", this.createAudioMetrics());
|
|
3455
3455
|
this.dataController = e;
|
|
3456
3456
|
const t = y.getEnvironmentConfig();
|
|
@@ -3877,13 +3877,10 @@ class Ca {
|
|
|
3877
3877
|
}), this.enableAudioOnlyMode();
|
|
3878
3878
|
return;
|
|
3879
3879
|
}
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
h.error("[AvatarController] Failed to auto-start playback:", s), (o = this.onError) == null || o.call(this, new Q("Failed to start playback", "PLAYBACK_START_FAILED"));
|
|
3885
|
-
});
|
|
3886
|
-
}
|
|
3880
|
+
this.currentKeyframes.length === 0 ? this.currentKeyframes = e : this.currentKeyframes.push(...e), this.emit("keyframesUpdate", this.currentKeyframes), !this.isPlaying && this.pendingAudioChunks.length > 0 && this.currentKeyframes.length > 0 && this.startStreamingPlayback().catch((a) => {
|
|
3881
|
+
var i;
|
|
3882
|
+
h.error("[AvatarController] Failed to auto-start playback:", a), (i = this.onError) == null || i.call(this, new Q("Failed to start playback", "PLAYBACK_START_FAILED"));
|
|
3883
|
+
});
|
|
3887
3884
|
}
|
|
3888
3885
|
// ========== Common Interface ==========
|
|
3889
3886
|
/**
|
|
@@ -4054,7 +4051,7 @@ class Ca {
|
|
|
4054
4051
|
startPlaybackLoop() {
|
|
4055
4052
|
if (this.playbackLoopId)
|
|
4056
4053
|
return;
|
|
4057
|
-
const e =
|
|
4054
|
+
const e = k.animation.fps, t = async () => {
|
|
4058
4055
|
if (!this.isPlaying || this.currentState === M.paused || !this.animationPlayer) {
|
|
4059
4056
|
this.playbackLoopId = null;
|
|
4060
4057
|
return;
|
|
@@ -4309,7 +4306,7 @@ class ir {
|
|
|
4309
4306
|
* @internal 供 AvatarKit 使用
|
|
4310
4307
|
*/
|
|
4311
4308
|
async loadGlobalFlameResources(e = null) {
|
|
4312
|
-
const { cdnBaseUrl: t, resources: n } =
|
|
4309
|
+
const { cdnBaseUrl: t, resources: n } = k.flame, a = {
|
|
4313
4310
|
flameModel: {
|
|
4314
4311
|
url: `${t}/${n.flameModel}`,
|
|
4315
4312
|
resourceName: n.flameModel
|
|
@@ -5884,7 +5881,7 @@ class Ua {
|
|
|
5884
5881
|
n.from,
|
|
5885
5882
|
n.to,
|
|
5886
5883
|
this.transitionDurationMs,
|
|
5887
|
-
|
|
5884
|
+
k.animation.fps
|
|
5888
5885
|
);
|
|
5889
5886
|
return a.length < 2 && (a = [n.from, n.to]), a[0] = n.from, a[a.length - 1] = n.to, a;
|
|
5890
5887
|
}
|
|
@@ -5932,23 +5929,23 @@ class Ua {
|
|
|
5932
5929
|
*/
|
|
5933
5930
|
async initializeView(e) {
|
|
5934
5931
|
try {
|
|
5935
|
-
|
|
5932
|
+
k.debug && h.log("[AvatarView] Initializing avatar view...");
|
|
5936
5933
|
const t = y.getAvatarCore();
|
|
5937
5934
|
if (!t)
|
|
5938
5935
|
throw new Error("AvatarCore not available. AvatarKit initialization may have failed.");
|
|
5939
5936
|
const n = e.getResources();
|
|
5940
|
-
|
|
5937
|
+
k.debug && h.log("[AvatarView] Loading character data..."), this.characterHandle = await t.loadCharacterFromBuffers(
|
|
5941
5938
|
n.characterData.shape,
|
|
5942
5939
|
n.characterData.pointCloud,
|
|
5943
5940
|
this.characterId
|
|
5944
|
-
), n.characterData.idleAnimation && (
|
|
5941
|
+
), n.characterData.idleAnimation && (k.debug && h.log("[AvatarView] Loading idle animation..."), await t.loadAnimationFromBuffer(n.characterData.idleAnimation, this.characterId)), n.characterData.shape = new ArrayBuffer(0), n.characterData.pointCloud = new ArrayBuffer(0), n.characterData.idleAnimation && (n.characterData.idleAnimation = new ArrayBuffer(0)), this.avatarController.setRenderCallback(
|
|
5945
5942
|
(i, s) => {
|
|
5946
5943
|
this.renderRealtimeFrame(i, s);
|
|
5947
5944
|
},
|
|
5948
5945
|
this.characterHandle
|
|
5949
|
-
),
|
|
5946
|
+
), k.debug && h.log("[AvatarView] Initializing render system...");
|
|
5950
5947
|
const a = this.resolveCameraConfig(n);
|
|
5951
|
-
await this.initializeRenderSystem(a),
|
|
5948
|
+
await this.initializeRenderSystem(a), k.debug && h.log("[AvatarView] Starting rendering..."), await this.renderFirstFrame(), this.startIdleAnimationLoop(), this.isInitialized = !0, k.debug && h.log("[AvatarView] Avatar view initialized successfully");
|
|
5952
5949
|
} catch (t) {
|
|
5953
5950
|
throw h.error("[AvatarView] Failed to initialize avatar view:", t instanceof Error ? t.message : String(t)), t;
|
|
5954
5951
|
}
|
|
@@ -5962,13 +5959,13 @@ class Ua {
|
|
|
5962
5959
|
camera: this.cameraConfig,
|
|
5963
5960
|
backgroundColor: [0, 0, 0, 0]
|
|
5964
5961
|
// 透明背景,让 CSS 背景透出
|
|
5965
|
-
}), await this.renderSystem.initialize(),
|
|
5962
|
+
}), await this.renderSystem.initialize(), k.debug && h.log("[AvatarView] Render system initialized successfully");
|
|
5966
5963
|
}
|
|
5967
5964
|
/**
|
|
5968
5965
|
* 获取默认相机配置
|
|
5969
5966
|
*/
|
|
5970
5967
|
getDefaultCameraConfig() {
|
|
5971
|
-
return { ...
|
|
5968
|
+
return { ...k.camera };
|
|
5972
5969
|
}
|
|
5973
5970
|
/**
|
|
5974
5971
|
* 根据资源解析最终的相机配置,优先使用角色设置,其次 camera.json
|
|
@@ -6039,7 +6036,7 @@ class Ua {
|
|
|
6039
6036
|
eyes_pose: [0, 0, 0, 0, 0, 0]
|
|
6040
6037
|
}, n = await e.computeFrameFlatFromParams(t, this.characterHandle ?? void 0);
|
|
6041
6038
|
if (n)
|
|
6042
|
-
this.renderSystem.loadSplatsFromPackedData(n), this.renderSystem.renderFrame(),
|
|
6039
|
+
this.renderSystem.loadSplatsFromPackedData(n), this.renderSystem.renderFrame(), k.debug && h.log("[AvatarView] First frame rendered successfully");
|
|
6043
6040
|
else
|
|
6044
6041
|
throw new Error("Failed to compute first frame splat data");
|
|
6045
6042
|
}
|
|
@@ -6062,12 +6059,12 @@ class Ua {
|
|
|
6062
6059
|
*/
|
|
6063
6060
|
startIdleAnimationLoop() {
|
|
6064
6061
|
if (this.idleAnimationLoopId && this.stopIdleAnimationLoop(), this.renderingState !== "idle") {
|
|
6065
|
-
|
|
6062
|
+
k.debug && h.log("[AvatarView] Skip starting idle loop because not in idle state");
|
|
6066
6063
|
return;
|
|
6067
6064
|
}
|
|
6068
6065
|
this.idleCurrentFrameIndex = 0;
|
|
6069
6066
|
let e = 0;
|
|
6070
|
-
const n = 1e3 /
|
|
6067
|
+
const n = 1e3 / k.animation.fps;
|
|
6071
6068
|
this.initFPS();
|
|
6072
6069
|
const a = async (i) => {
|
|
6073
6070
|
try {
|
|
@@ -6096,7 +6093,7 @@ class Ua {
|
|
|
6096
6093
|
h.error("[AvatarView] Idle animation loop error:", s instanceof Error ? s.message : String(s)), this.stopIdleAnimationLoop();
|
|
6097
6094
|
}
|
|
6098
6095
|
};
|
|
6099
|
-
this.idleAnimationLoopId = requestAnimationFrame(a),
|
|
6096
|
+
this.idleAnimationLoopId = requestAnimationFrame(a), k.debug && h.log("[AvatarView] Idle animation loop started");
|
|
6100
6097
|
}
|
|
6101
6098
|
/**
|
|
6102
6099
|
* 开始实时对话动画循环
|
|
@@ -6104,7 +6101,7 @@ class Ua {
|
|
|
6104
6101
|
startRealtimeAnimationLoop() {
|
|
6105
6102
|
this.realtimeAnimationLoopId && this.stopRealtimeAnimationLoop();
|
|
6106
6103
|
let e = 0;
|
|
6107
|
-
const n = 1e3 /
|
|
6104
|
+
const n = 1e3 / k.animation.fps;
|
|
6108
6105
|
this.initFPS();
|
|
6109
6106
|
const a = async (i) => {
|
|
6110
6107
|
try {
|
|
@@ -6152,19 +6149,19 @@ class Ua {
|
|
|
6152
6149
|
h.error("[AvatarView] Realtime animation loop error:", s instanceof Error ? s.message : String(s)), this.stopRealtimeAnimationLoop();
|
|
6153
6150
|
}
|
|
6154
6151
|
};
|
|
6155
|
-
this.realtimeAnimationLoopId = requestAnimationFrame(a),
|
|
6152
|
+
this.realtimeAnimationLoopId = requestAnimationFrame(a), k.debug && h.log("[AvatarView] Realtime animation loop started");
|
|
6156
6153
|
}
|
|
6157
6154
|
/**
|
|
6158
6155
|
* 停止idle动画循环
|
|
6159
6156
|
*/
|
|
6160
6157
|
stopIdleAnimationLoop() {
|
|
6161
|
-
this.idleAnimationLoopId && (cancelAnimationFrame(this.idleAnimationLoopId), this.idleAnimationLoopId = null,
|
|
6158
|
+
this.idleAnimationLoopId && (cancelAnimationFrame(this.idleAnimationLoopId), this.idleAnimationLoopId = null, k.debug && h.log("[AvatarView] Idle animation loop stopped"));
|
|
6162
6159
|
}
|
|
6163
6160
|
/**
|
|
6164
6161
|
* 停止实时对话动画循环
|
|
6165
6162
|
*/
|
|
6166
6163
|
stopRealtimeAnimationLoop() {
|
|
6167
|
-
this.realtimeAnimationLoopId && (cancelAnimationFrame(this.realtimeAnimationLoopId), this.realtimeAnimationLoopId = null,
|
|
6164
|
+
this.realtimeAnimationLoopId && (cancelAnimationFrame(this.realtimeAnimationLoopId), this.realtimeAnimationLoopId = null, k.debug && h.log("[AvatarView] Realtime animation loop stopped"));
|
|
6168
6165
|
}
|
|
6169
6166
|
/**
|
|
6170
6167
|
* 停止所有动画循环
|
|
@@ -6263,7 +6260,7 @@ class Ua {
|
|
|
6263
6260
|
this.transitionKeyframes = this.generateAndAlignTransitionFrames(i, s), this.transitionStartTime = performance.now(), this.transitionKeyframes.length === 0 ? (this.setState(
|
|
6264
6261
|
"speaking"
|
|
6265
6262
|
/* Speaking */
|
|
6266
|
-
), this.avatarController.onTransitionComplete()) :
|
|
6263
|
+
), this.avatarController.onTransitionComplete()) : k.debug && h.log("[AvatarView] Transition started:", this.transitionKeyframes.length, "frames");
|
|
6267
6264
|
}
|
|
6268
6265
|
} catch (n) {
|
|
6269
6266
|
h.warn("[AvatarView] Transition generation failed:", n instanceof Error ? n.message : String(n)), this.renderingState === "transitioningToSpeaking" && (this.setState(
|
|
@@ -6277,7 +6274,7 @@ class Ua {
|
|
|
6277
6274
|
* 开始实时渲染循环
|
|
6278
6275
|
*/
|
|
6279
6276
|
startRealtimeRendering() {
|
|
6280
|
-
|
|
6277
|
+
k.debug && h.log("[AvatarView] Starting realtime rendering with", this.currentKeyframes.length, "keyframes"), y.logEvent("character_view", "info", {
|
|
6281
6278
|
characterId: this.avatar.id,
|
|
6282
6279
|
event: "rendering_started",
|
|
6283
6280
|
keyframesCount: this.currentKeyframes.length
|
|
@@ -6306,7 +6303,7 @@ class Ua {
|
|
|
6306
6303
|
if (y.getAvatarCore() && this.currentKeyframes.length > 0) {
|
|
6307
6304
|
const n = this.lastRealtimeProtoFrame || this.currentKeyframes[Math.max(0, this.lastRenderedFrameIndex)], a = await this.getCachedIdleFirstFrame();
|
|
6308
6305
|
if (a && (this.transitionKeyframes = this.generateAndAlignTransitionFrames(n, a), this.transitionStartTime = performance.now(), this.transitionKeyframes.length > 0 && this.renderingState === "transitioningToIdle")) {
|
|
6309
|
-
|
|
6306
|
+
k.debug && h.log("[AvatarView] Return transition started:", this.transitionKeyframes.length, "frames"), this.realtimeAnimationLoopId || this.startRealtimeAnimationLoop();
|
|
6310
6307
|
return;
|
|
6311
6308
|
}
|
|
6312
6309
|
}
|
|
@@ -6325,7 +6322,7 @@ class Ua {
|
|
|
6325
6322
|
* 关闭 avatarController 并清理所有相关资源
|
|
6326
6323
|
*/
|
|
6327
6324
|
dispose() {
|
|
6328
|
-
|
|
6325
|
+
k.debug && h.log("[AvatarView] Disposing avatar view..."), y.logEvent("character_view", "info", {
|
|
6329
6326
|
characterId: this.avatar.id,
|
|
6330
6327
|
event: "disposed"
|
|
6331
6328
|
}), this.avatarController && (this.avatarController.clear(), this.avatarController.dispose()), this.stopAllAnimationLoops(), this.setState(
|
|
@@ -6335,11 +6332,11 @@ class Ua {
|
|
|
6335
6332
|
const e = y.getAvatarCore();
|
|
6336
6333
|
if (e && this.characterHandle)
|
|
6337
6334
|
try {
|
|
6338
|
-
e.removeCharacter(this.characterHandle, this.characterId),
|
|
6335
|
+
e.removeCharacter(this.characterHandle, this.characterId), k.debug && h.log("[AvatarView] AvatarCore character resources released"), this.characterHandle = null;
|
|
6339
6336
|
} catch (t) {
|
|
6340
6337
|
h.error("[AvatarView] Failed to release AvatarCore resources:", t instanceof Error ? t.message : String(t));
|
|
6341
6338
|
}
|
|
6342
|
-
this.renderSystem && (this.renderSystem.dispose(), this.renderSystem = null), this.canvas && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), window.removeEventListener("resize", this.onWindowResize), this.isInitialized = !1,
|
|
6339
|
+
this.renderSystem && (this.renderSystem.dispose(), this.renderSystem = null), this.canvas && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), window.removeEventListener("resize", this.onWindowResize), this.isInitialized = !1, k.debug && h.log("[AvatarView] Avatar view disposed successfully");
|
|
6343
6340
|
}
|
|
6344
6341
|
/**
|
|
6345
6342
|
* 获取相机配置
|
|
@@ -6353,7 +6350,7 @@ class Ua {
|
|
|
6353
6350
|
* @internal
|
|
6354
6351
|
*/
|
|
6355
6352
|
updateCameraConfig(e) {
|
|
6356
|
-
this.cameraConfig = e,
|
|
6353
|
+
this.cameraConfig = e, k.debug && h.log("[AvatarView] Camera config updated:", e), this.renderSystem && (this.renderSystem.updateCamera(e), k.debug && h.log("[AvatarView] Applied new camera config to render system"));
|
|
6357
6354
|
}
|
|
6358
6355
|
/**
|
|
6359
6356
|
* 处理尺寸变化:通知渲染系统更新视口与投影
|
|
@@ -6377,7 +6374,7 @@ class Ua {
|
|
|
6377
6374
|
}
|
|
6378
6375
|
}
|
|
6379
6376
|
export {
|
|
6380
|
-
|
|
6377
|
+
k as A,
|
|
6381
6378
|
ye as C,
|
|
6382
6379
|
ze as D,
|
|
6383
6380
|
ie as E,
|
|
@@ -6395,4 +6392,4 @@ export {
|
|
|
6395
6392
|
Na as i,
|
|
6396
6393
|
h as l
|
|
6397
6394
|
};
|
|
6398
|
-
//# sourceMappingURL=index-
|
|
6395
|
+
//# sourceMappingURL=index-Cm5BwNVd.js.map
|