sentifyd-bot 1.5.0 → 1.5.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 +6 -0
- package/LICENSE.md +4 -3
- package/README.md +1 -1
- package/dist/{AzureTalkingAvatar-DwFpnwON.js → AzureTalkingAvatar-G4LQw7TE.js} +1 -1
- package/dist/{LiveCaptions-CxsuwP4M.js → LiveCaptions-DsQXlM8P.js} +1 -1
- package/dist/TalkingAvatar-CCG2emPQ.js +1 -0
- package/dist/index-BHDdsuP1.js +3243 -0
- package/dist/index.es.js +1 -1
- package/package.json +2 -2
- package/src/index.d.ts +20 -12
- package/src/react/SentifydBot.jsx +3 -2
- package/src/react/index.d.ts +28 -20
- package/src/react/index.js +3 -2
- package/src/vite-plugin.js +8 -0
- package/dist/TalkingAvatar--N4jOsLi.js +0 -1
- package/dist/index-DY_KYJkq.js +0 -3016
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as t,a as e,i,r as a}from"./index-
|
|
1
|
+
import{S as t,a as e,i,r as a}from"./index-BHDdsuP1.js";export{t as SentifydBot,e as createSentifydBot,i as initializeStorage,a as registerSentifydBot};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sentifyd-bot",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Sentifyd conversational AI chatbot with 3D avatar - npm package for React, Vue, and modern web frameworks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.es.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"url": "git+https://github.com/Sentifyd/Sentifyd-frontend.git",
|
|
54
54
|
"directory": "npm-package"
|
|
55
55
|
},
|
|
56
|
-
"author": "
|
|
56
|
+
"author": "Sentify Technology O\u00dc <info@sentifyd.io>",
|
|
57
57
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
58
58
|
"homepage": "https://sentifyd.io",
|
|
59
59
|
"engines": {
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
********************************************************************************
|
|
3
|
+
* Company: Sentify Technology OÜ
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2026 Sentify Technology OÜ. All rights reserved.
|
|
6
|
+
********************************************************************************
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* Type definitions for Sentifyd Frontend
|
|
3
11
|
* @module sentifyd-frontend
|
|
@@ -18,40 +26,40 @@ export interface SentifydStorage {
|
|
|
18
26
|
export interface SentifydBotConfig {
|
|
19
27
|
/** API key for authentication (required) */
|
|
20
28
|
apiKey: string;
|
|
21
|
-
|
|
29
|
+
|
|
22
30
|
/** Avatar ID to use (required) */
|
|
23
31
|
avatarId: string;
|
|
24
|
-
|
|
32
|
+
|
|
25
33
|
/** Show toggler button (default: "true") */
|
|
26
34
|
toggler?: boolean | string;
|
|
27
|
-
|
|
35
|
+
|
|
28
36
|
/** Use compact layout (default: "false") */
|
|
29
37
|
compact?: boolean | string;
|
|
30
|
-
|
|
38
|
+
|
|
31
39
|
/** Target application type (default: "web") */
|
|
32
40
|
targetApp?: "web" | "mobile";
|
|
33
|
-
|
|
41
|
+
|
|
34
42
|
/** Brand name to display */
|
|
35
43
|
brandName?: string;
|
|
36
|
-
|
|
44
|
+
|
|
37
45
|
/** Brand logo URL */
|
|
38
46
|
brandLogo?: string;
|
|
39
|
-
|
|
47
|
+
|
|
40
48
|
/** Terms of service URL */
|
|
41
49
|
termsHref?: string;
|
|
42
|
-
|
|
50
|
+
|
|
43
51
|
/** Privacy policy URL */
|
|
44
52
|
privacyHref?: string;
|
|
45
|
-
|
|
53
|
+
|
|
46
54
|
/** Enable live captions (default: false) */
|
|
47
55
|
enableCaptions?: boolean | string;
|
|
48
|
-
|
|
56
|
+
|
|
49
57
|
/** Custom token endpoint for authentication */
|
|
50
58
|
tokenEndpoint?: string;
|
|
51
|
-
|
|
59
|
+
|
|
52
60
|
/** ID of container element to mount in */
|
|
53
61
|
containerId?: string;
|
|
54
|
-
|
|
62
|
+
|
|
55
63
|
/** Additional custom attributes */
|
|
56
64
|
customAttributes?: Record<string, string | number | boolean>;
|
|
57
65
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*********************************************************************************
|
|
2
2
|
* react/SentifydBot.jsx
|
|
3
|
-
* Company:
|
|
4
|
-
* Copyright (c)
|
|
3
|
+
* Company: Sentify Technology OÜ
|
|
4
|
+
* Copyright (c) 2026 Sentify Technology OÜ. All rights reserved.
|
|
5
5
|
*
|
|
6
6
|
* React wrapper component for the Sentifyd bot web component.
|
|
7
7
|
* Provides idiomatic React API with proper lifecycle management.
|
|
@@ -166,3 +166,4 @@ const SentifydBot = forwardRef(({
|
|
|
166
166
|
SentifydBot.displayName = 'SentifydBot';
|
|
167
167
|
|
|
168
168
|
export default SentifydBot;
|
|
169
|
+
|
package/src/react/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
********************************************************************************
|
|
3
|
+
* Company: Sentify Technology OÜ
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2026 Sentify Technology OÜ. All rights reserved.
|
|
6
|
+
********************************************************************************
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* React type definitions for Sentifyd Frontend
|
|
3
11
|
* @module sentifyd-frontend/react
|
|
@@ -11,55 +19,55 @@ import { ComponentPropsWithRef, ForwardRefExoticComponent, RefAttributes } from
|
|
|
11
19
|
export interface SentifydBotProps {
|
|
12
20
|
/** API key for authentication (required) */
|
|
13
21
|
apiKey: string;
|
|
14
|
-
|
|
22
|
+
|
|
15
23
|
/** Avatar ID to use (required) */
|
|
16
24
|
avatarId: string;
|
|
17
|
-
|
|
25
|
+
|
|
18
26
|
/** Show toggler button (default: true) */
|
|
19
27
|
toggler?: boolean;
|
|
20
|
-
|
|
28
|
+
|
|
21
29
|
/** Use compact layout (default: false) */
|
|
22
30
|
compact?: boolean;
|
|
23
|
-
|
|
31
|
+
|
|
24
32
|
/** Target application type (default: "web") */
|
|
25
33
|
targetApp?: "web" | "mobile";
|
|
26
|
-
|
|
34
|
+
|
|
27
35
|
/** Brand name to display */
|
|
28
36
|
brandName?: string;
|
|
29
|
-
|
|
37
|
+
|
|
30
38
|
/** Brand logo URL */
|
|
31
39
|
brandLogo?: string;
|
|
32
|
-
|
|
40
|
+
|
|
33
41
|
/** Terms of service URL */
|
|
34
42
|
termsHref?: string;
|
|
35
|
-
|
|
43
|
+
|
|
36
44
|
/** Privacy policy URL */
|
|
37
45
|
privacyHref?: string;
|
|
38
|
-
|
|
46
|
+
|
|
39
47
|
/** Enable live captions (default: false) */
|
|
40
48
|
enableCaptions?: boolean;
|
|
41
|
-
|
|
49
|
+
|
|
42
50
|
/** Custom token endpoint for authentication */
|
|
43
51
|
tokenEndpoint?: string;
|
|
44
|
-
|
|
52
|
+
|
|
45
53
|
/** CSS class name */
|
|
46
54
|
className?: string;
|
|
47
|
-
|
|
55
|
+
|
|
48
56
|
/** Inline styles */
|
|
49
57
|
style?: React.CSSProperties;
|
|
50
|
-
|
|
58
|
+
|
|
51
59
|
/** Callback when bot is ready */
|
|
52
60
|
onReady?: (bot: HTMLElement, event: Event) => void;
|
|
53
|
-
|
|
61
|
+
|
|
54
62
|
/** Callback when an error occurs */
|
|
55
63
|
onError?: (error: any, event: Event) => void;
|
|
56
|
-
|
|
64
|
+
|
|
57
65
|
/** Callback when bot is opened */
|
|
58
66
|
onOpen?: (event: Event) => void;
|
|
59
|
-
|
|
67
|
+
|
|
60
68
|
/** Callback when bot is closed */
|
|
61
69
|
onClose?: (event: Event) => void;
|
|
62
|
-
|
|
70
|
+
|
|
63
71
|
/** Additional custom attributes */
|
|
64
72
|
[key: string]: any;
|
|
65
73
|
}
|
|
@@ -70,13 +78,13 @@ export interface SentifydBotProps {
|
|
|
70
78
|
export interface SentifydBotHandle {
|
|
71
79
|
/** Access the underlying web component element */
|
|
72
80
|
element: HTMLElement | null;
|
|
73
|
-
|
|
81
|
+
|
|
74
82
|
/** Open the chatbot */
|
|
75
83
|
open: () => void;
|
|
76
|
-
|
|
84
|
+
|
|
77
85
|
/** Close the chatbot */
|
|
78
86
|
close: () => void;
|
|
79
|
-
|
|
87
|
+
|
|
80
88
|
/** Send a message programmatically */
|
|
81
89
|
sendMessage: (message: string) => void;
|
|
82
90
|
}
|
package/src/react/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/*********************************************************************************
|
|
2
2
|
* react/index.js
|
|
3
|
-
* Company:
|
|
4
|
-
* Copyright (c)
|
|
3
|
+
* Company: Sentify Technology OÜ
|
|
4
|
+
* Copyright (c) 2026 Sentify Technology OÜ. All rights reserved.
|
|
5
5
|
*
|
|
6
6
|
* React exports entry point.
|
|
7
7
|
*********************************************************************************/
|
|
8
8
|
|
|
9
9
|
export { default as SentifydBot } from './SentifydBot.jsx';
|
|
10
|
+
|
package/src/vite-plugin.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
********************************************************************************
|
|
3
|
+
* Company: Sentify Technology OÜ
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2026 Sentify Technology OÜ. All rights reserved.
|
|
6
|
+
********************************************************************************
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* Vite plugin for sentifyd-bot to handle @met4citizen/talkinghead module compatibility.
|
|
3
11
|
*
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{TalkingHead as t}from"@met4citizen/talkinghead";import{C as e,c as i}from"./index-DY_KYJkq.js";import{L as a}from"./LiveCaptions-CxsuwP4M.js";const n={dance:["dance\\M_Dances_007.fbx","dance\\M_Dances_008.fbx","dance\\M_Dances_009.fbx","dance\\M_Dances_011.fbx","dance\\F_Dances_001.fbx","dance\\F_Dances_004.fbx","dance\\F_Dances_005.fbx","dance\\F_Dances_006.fbx","dance\\F_Dances_007.fbx","dance\\M_Dances_001.fbx","dance\\M_Dances_002.fbx","dance\\M_Dances_003.fbx","dance\\M_Dances_004.fbx","dance\\M_Dances_005.fbx","dance\\M_Dances_006.fbx"],expression:["expression\\M_Standing_Expressions_016.fbx","expression\\M_Standing_Expressions_017.fbx","expression\\M_Standing_Expressions_018.fbx","expression\\M_Talking_Variations_001.fbx","expression\\M_Talking_Variations_002.fbx","expression\\M_Talking_Variations_003.fbx","expression\\M_Talking_Variations_004.fbx","expression\\M_Talking_Variations_005.fbx","expression\\M_Talking_Variations_006.fbx","expression\\M_Talking_Variations_007.fbx","expression\\M_Talking_Variations_008.fbx","expression\\M_Talking_Variations_009.fbx","expression\\M_Talking_Variations_010.fbx","expression\\F_Talking_Variations_001.fbx","expression\\F_Talking_Variations_002.fbx","expression\\F_Talking_Variations_003.fbx","expression\\F_Talking_Variations_004.fbx","expression\\F_Talking_Variations_005.fbx","expression\\F_Talking_Variations_006.fbx","expression\\M_Standing_Expressions_001.fbx","expression\\M_Standing_Expressions_002.fbx","expression\\M_Standing_Expressions_004.fbx","expression\\M_Standing_Expressions_005.fbx","expression\\M_Standing_Expressions_006.fbx","expression\\M_Standing_Expressions_007.fbx","expression\\M_Standing_Expressions_008.fbx","expression\\M_Standing_Expressions_009.fbx","expression\\M_Standing_Expressions_010.fbx","expression\\M_Standing_Expressions_011.fbx","expression\\M_Standing_Expressions_012.fbx","expression\\M_Standing_Expressions_013.fbx","expression\\M_Standing_Expressions_014.fbx","expression\\M_Standing_Expressions_015.fbx"],locomotion:["locomotion\\M_CrouchedWalk_Backwards_002.fbx","locomotion\\M_Falling_Idle_002.fbx","locomotion\\M_Jog_001.fbx","locomotion\\M_Jog_003.fbx","locomotion\\M_Jog_Backwards_001.fbx","locomotion\\M_Jog_Jump_001.fbx","locomotion\\M_Jog_Jump_002.fbx","locomotion\\M_Jog_Strafe_Left_001.fbx","locomotion\\M_Jog_Strafe_Right_001.fbx","locomotion\\M_Run_001.fbx","locomotion\\M_Run_Backwards_002.fbx","locomotion\\M_Run_Jump_001.fbx","locomotion\\M_Run_Jump_002.fbx","locomotion\\M_Run_Strafe_Left_002.fbx","locomotion\\M_Run_Strafe_Right_002.fbx","locomotion\\M_Walk_001.fbx","locomotion\\M_Walk_002.fbx","locomotion\\M_Walk_Backwards_001.fbx","locomotion\\M_Walk_Jump_001.fbx","locomotion\\M_Walk_Jump_002.fbx","locomotion\\M_Walk_Jump_003.fbx","locomotion\\M_Walk_Strafe_Left_002.fbx","locomotion\\M_Walk_Strafe_Right_002.fbx","locomotion\\F_Crouch_Strafe_Left.fbx","locomotion\\F_Crouch_Strafe_Right.fbx","locomotion\\F_Crouch_Walk_001.fbx","locomotion\\F_CrouchedWalk_Backwards_001.fbx","locomotion\\F_Falling_Idle_000.fbx","locomotion\\F_Falling_Idle_001.fbx","locomotion\\F_Jog_001.fbx","locomotion\\F_Jog_Backwards_001.fbx","locomotion\\F_Jog_Jump_Small_001.fbx","locomotion\\F_Jog_Strafe_Left_002.fbx","locomotion\\F_Jog_Strafe_Right_002.fbx","locomotion\\F_Run_001.fbx","locomotion\\F_Run_Backwards_001.fbx","locomotion\\F_Run_Jump_001.fbx","locomotion\\F_Run_Strafe_Left_001.fbx","locomotion\\F_Run_Strafe_Right_001.fbx","locomotion\\F_Walk_002.fbx","locomotion\\F_Walk_003.fbx","locomotion\\F_Walk_Backwards_001.fbx","locomotion\\F_Walk_Jump_001.fbx","locomotion\\F_Walk_Jump_002.fbx","locomotion\\F_Walk_Strafe_Left_001.fbx","locomotion\\F_Walk_Strafe_Right_001.fbx","locomotion\\M_Crouch_Strafe_Left_002.fbx","locomotion\\M_Crouch_Strafe_Right_002.fbx","locomotion\\M_Crouch_Walk_003.fbx"],idle:["idle\\M_Standing_Idle_Variations_001.fbx","idle\\M_Standing_Idle_Variations_002.fbx","idle\\M_Standing_Idle_Variations_003.fbx","idle\\M_Standing_Idle_Variations_004.fbx","idle\\M_Standing_Idle_Variations_005.fbx","idle\\M_Standing_Idle_Variations_006.fbx","idle\\M_Standing_Idle_Variations_007.fbx","idle\\M_Standing_Idle_Variations_008.fbx","idle\\M_Standing_Idle_Variations_009.fbx","idle\\M_Standing_Idle_Variations_010.fbx","idle\\F_Standing_Idle_001.fbx","idle\\F_Standing_Idle_Variations_001.fbx","idle\\F_Standing_Idle_Variations_002.fbx","idle\\F_Standing_Idle_Variations_003.fbx","idle\\F_Standing_Idle_Variations_004.fbx","idle\\F_Standing_Idle_Variations_005.fbx","idle\\F_Standing_Idle_Variations_006.fbx","idle\\F_Standing_Idle_Variations_007.fbx","idle\\F_Standing_Idle_Variations_008.fbx","idle\\F_Standing_Idle_Variations_009.fbx","idle\\M_Standing_Idle_001.fbx","idle\\M_Standing_Idle_002.fbx"]};function s(t){return t&&0!==t.length?t[Math.floor(Math.random()*t.length)]:null}function o(t,e,...i){return t.filter((t=>!!t.includes(`${e}_`)&&i.every((e=>t.includes(e)))))}const r=["eyeBlinkLeft","eyeLookDownLeft","eyeLookInLeft","eyeLookOutLeft","eyeLookUpLeft","eyeSquintLeft","eyeWideLeft","eyeBlinkRight","eyeLookDownRight","eyeLookInRight","eyeLookOutRight","eyeLookUpRight","eyeSquintRight","eyeWideRight","jawForward","jawLeft","jawRight","jawOpen","mouthClose","mouthFunnel","mouthPucker","mouthLeft","mouthRight","mouthSmileLeft","mouthSmileRight","mouthFrownLeft","mouthFrownRight","mouthDimpleLeft","mouthDimpleRight","mouthStretchLeft","mouthStretchRight","mouthRollLower","mouthRollUpper","mouthShrugLower","mouthShrugUpper","mouthPressLeft","mouthPressRight","mouthLowerDownLeft","mouthLowerDownRight","mouthUpperUpLeft","mouthUpperUpRight","browDownLeft","browDownRight","browInnerUp","browOuterUpLeft","browOuterUpRight","cheekPuff","cheekSquintLeft","cheekSquintRight","noseSneerLeft","noseSneerRight","tongueOut","headRotateZ"],_=["sil","aa","aa","O","E","RR","I","U","O","O","O","I","kk","RR","nn","SS","CH","TH","FF","DD","kk","PP"];class l extends e{isVideoAvatar=!1;constructor(t,e){super("talkingAvatar"),this.bus=t,this.avatarOrchestrator=e,this.talkingAvatar=null,this.isFullBody=!0,this.bodyGender="M",this.resetSpeakData(),this.prevViseme=null,this.frameDuration=1e3/i.constants.FRAME_RATE,this.currentTurnId=null,this.isStoppingSpeaking=!1,this._endedTurns=new Set,this.conversationStreamActive=!1,this._pendingEndReason=null,this._audioStartSent=!1,this._busHandlers=[],this.liveCaptions=new a}resetSpeakData(){this.speak={audio:[],visemes:[],vtimes:[],vdurations:[],words:[],wtimes:[],wdurations:[],markers:[],mtimes:[],anim:{}},this.azureBlendShapes={frames:[],sbuffer:[],orderBuffer:{}},this.prevViseme=null}finalizeTurn(){this.handlePendingVisemes(),this.talkingAvatar.streamNotifyEnd(),this.resetSpeakData()}async init(e,i){try{this.talkingAvatar=new t(i,{ttsEndpoint:"/gtts/",cameraZoomEnable:!1,cameraPanEnable:!1,cameraRotateEnable:!1,cameraView:"full",cameraY:.25,cameraDistance:.5,avatarMood:"happy"});const a="male"===e.gender?"M":"F";this.bodyGender=a,this.currentAvatarConfig={url:e.url,body:a},await this.talkingAvatar.showAvatar(this.currentAvatarConfig),this.addEventListeners(),this.setConnected(),this.lipsyncType=e.lipsyncType}catch(a){throw this.setFailed(),new Error("Error initializing TalkingAvatar: "+a)}}isRenderingActive(){return!!this.talkingAvatar?.isRunning}async suspendRendering(t="hidden"){if(this.isRenderingActive()){this.suspendTime=Date.now();try{this.talkingAvatar?.streamInterrupt?.()}catch(e){}try{this.audioReader?.cancel()}catch(e){}try{this.lipsyncReader?.cancel()}catch(e){}if(this.conversationStreamActive)try{await this.stopConversationStream()}catch(e){}try{this.talkingAvatar?.stop?.()}catch(e){}try{this.liveCaptions?.clearCaptions?.()}catch(e){}try{this.bus?.emit?.("event_command_UI_ClearCaptions")}catch(e){}try{const e=this.isRenderingActive();this.bus?.emit?.("event_status_Avatar_RenderingStateChanged",{running:e,reason:t})}catch(e){}}}async resumeRendering(){if(!this.isRenderingActive()){this.suspendTime&&Date.now()-this.suspendTime>15e3&&this.currentAvatarConfig&&await this.refreshAvatar();try{this.talkingAvatar?.start?.()}catch(t){}try{const t=this.isRenderingActive();this.bus?.emit?.("event_status_Avatar_RenderingStateChanged",{running:t,reason:"resume"})}catch(t){}}}async refreshAvatar(){if(!this.currentAvatarConfig)return!1;try{try{this.talkingAvatar?.streamInterrupt?.()}catch(t){}return await this.talkingAvatar.showAvatar(this.currentAvatarConfig),!0}catch(e){return!1}}resumeAudioContext(){try{const t=this.talkingAvatar?.audioCtx;if(!t)return;"suspended"!==t.state&&"interrupted"!==t.state||t.resume().then((()=>{})).catch((t=>{}))}catch(t){}}getSpeechAnalyzerNode(){return this.talkingAvatar?.audioAnalyzerNode??null}startStreamPump(t){try{this.audioReader=t.readable.getReader()}catch(i){return}const e=this.currentTurnId;(async()=>{try{for(;;){const{value:i,done:a}=await this.audioReader.read();if(a)return;if(this.currentTurnId!==e){try{this.audioReader.cancel()}catch(t){}return}this._notifyAudioStart(e),this.handleSpeechSynthesizingChunk({audio:i})}}catch(i){"AbortError"===i.name||i.message.includes("cancel")}})().catch((t=>{}))}startLipsyncPump(t){this.lipsyncReader=t.readable.getReader();const e=this.currentTurnId;(async()=>{try{for(;;){const{value:i,done:a}=await this.lipsyncReader.read();if(a)break;if(this.currentTurnId!==e){try{this.lipsyncReader.cancel()}catch(t){}break}switch(i.type){case"viseme":this.handleAddVisemeToStreaming(i);break;case"word":this.handleReceivedWordBoundaryEvent(i);break;case"blend":this.handleAddBlendShapestoStreaming(i)}}}catch(i){"AbortError"===i.name||i.message.includes("cancel")}})().catch((t=>{}))}handleAudioEndOnce(t,e){const i=t??"__null__";this._endedTurns.has(i)||(this._endedTurns.add(i),this.avatarOrchestrator.sendEvent("AUDIO_END",{turnId:t,reason:e}))}async startConversationStream(){if(this.isRenderingActive()&&!this.conversationStreamActive)try{await this.talkingAvatar.streamStart({lipsyncType:this.lipsyncType,sampleRate:24e3},(({turnId:t,audioStartTime:e}={})=>{const i=t??this.currentTurnId;this._notifyAudioStart(i,e)}),(()=>{const t=this._pendingEndReason||"completed";this._pendingEndReason=null,this.handleAudioEndOnce(this.currentTurnId,t),this.currentTurnId&&(this.currentTurnId=null)})),this.conversationStreamActive=!0}catch(t){throw this.conversationStreamActive=!1,t}}async stopConversationStream(){if(this.conversationStreamActive)try{this.talkingAvatar.streamStop(),this.conversationStreamActive=!1}catch(t){this.conversationStreamActive=!1}}addEventListeners(){const t=(t,e)=>{this.bus.on(t,e),this._busHandlers.push([t,e])};t("event_command_Avatar_SetAvatarView",(t=>{this.setView(t.view)})),t("event_command_Avatar_SetAvatarMood",(t=>{this.talkingAvatar.setMood(t.mood)})),t("event_command_Avatar_PlayOrStopGesture",(t=>{"stop"!==t.gesture?this.talkingAvatar.playGesture(t.gesture,t.duration,t.mirror,t.ms):this.talkingAvatar.stopGesture()})),t("event_command_Avatar_PlayOrStopAnimation",(t=>{if("stop"===t.animation)return void this.talkingAvatar.stopAnimation();const e=function(t,e="M"){let i=[];switch(t){case"dance":i=o(n.dance,e,"Dances");break;case"expression_talking":i=o(n.expression,e,"Talking_Variations");break;case"expression_standing":i=o(n.expression,e,"Standing_Expressions");break;case"idle_standing":i=o(n.idle,e,"Standing_Idle");break;case"locomotion_walk":i=o(n.locomotion,e,"Walk_");break;case"locomotion_walk_backwards":i=o(n.locomotion,e,"Walk_Backwards");break;case"locomotion_walk_jump":i=o(n.locomotion,e,"Walk_Jump");break;case"locomotion_walk_strafe_left":i=o(n.locomotion,e,"Walk_Strafe_Left");break;case"locomotion_walk_strafe_right":i=o(n.locomotion,e,"Walk_Strafe_Right");break;case"locomotion_run":i=o(n.locomotion,e,"Run_");break;case"locomotion_run_backwards":i=o(n.locomotion,e,"Run_Backwards");break;case"locomotion_run_jump":i=o(n.locomotion,e,"Run_Jump");break;case"locomotion_run_strafe_left":i=o(n.locomotion,e,"Run_Strafe_Left");break;case"locomotion_run_strafe_right":i=o(n.locomotion,e,"Run_Strafe_Right");break;case"locomotion_jog":i=o(n.locomotion,e,"Jog_");break;case"locomotion_jog_backwards":i=o(n.locomotion,e,"Jog_Backwards");break;case"locomotion_jog_jump":i=o(n.locomotion,e,"Jog_Jump");break;case"locomotion_jog_strafe_left":i=o(n.locomotion,e,"Jog_Strafe_Left");break;case"locomotion_jog_strafe_right":i=o(n.locomotion,e,"Jog_Strafe_Right");break;case"locomotion_crouch_walk":i=o(n.locomotion,e,"Crouch_Walk");break;case"locomotion_crouch_strafe_left":i=o(n.locomotion,e,"Crouch_Strafe_Left");break;case"locomotion_crouch_strafe_right":i=o(n.locomotion,e,"Crouch_Strafe_Right");break;case"locomotion_crouchedwalk_backwards":i=o(n.locomotion,e,"CrouchedWalk_Backwards");break;case"locomotion_falling_idle":i=o(n.locomotion,e,"Falling_Idle");break;default:i=[]}return s(i)||s(n.locomotion.filter((t=>t.includes(`${e}_Walk_`))))||"locomotion\\M_Walk_001.fbx"}(t.animation,this.bodyGender);this.playAnimation(e,t.dur)})),t("event_command_Avatar_ControlAvatarLookAt",(t=>{"ahead"!==t.target?"point"!==t.target?"camera"!==t.target?"eye_contact"!==t.target||this.talkingAvatar.makeEyeContact(t.t):this.talkingAvatar.lookAtCamera(t.t):this.talkingAvatar.lookAt(t.x,t.y,t.t):this.talkingAvatar.lookAhead(t.t)})),t("event_command_UI_ClearCaptions",(()=>{try{this.liveCaptions?.clearCaptions?.()}catch(t){}}))}onResize(){this.talkingAvatar&&this.talkingAvatar.onResize()}handleSpeechSynthesizingChunk(t){switch(this.lipsyncType){case"blendshapes":this.talkingAvatar.streamAudio({audio:t.audio,anims:this.azureBlendShapes?.sbuffer.splice(0,this.azureBlendShapes?.sbuffer.length)});break;case"visemes":this.talkingAvatar.streamAudio({audio:t.audio,visemes:this.speak.visemes.splice(0,this.speak.visemes.length),vtimes:this.speak.vtimes.splice(0,this.speak.vtimes.length),vdurations:this.speak.vdurations.splice(0,this.speak.vdurations.length)});break;case"words":this.talkingAvatar.streamAudio({audio:t.audio,words:this.speak.words.splice(0,this.speak.words.length),wtimes:this.speak.wtimes.splice(0,this.speak.wtimes.length),wdurations:this.speak.wdurations.splice(0,this.speak.wdurations.length)})}}handleAddVisemeToStreaming(t){const e=_[t?.visemeId||0],i=t?.audioOffset||0;if(this.prevViseme){const t=this.prevViseme;let e=i-t.vtime;e<40&&(e=40),this.speak.visemes.push(t.viseme),this.speak.vtimes.push(t.vtime),this.speak.vdurations.push(e)}this.prevViseme={viseme:e,vtime:i}}handleAddBlendShapestoStreaming(t){const e=t?.BlendShapes;if(!e||0===e.length)return;const i=this._getBlendColumns(),a=e.length,n=Object.create(null);for(let o=0;o<i.length;o++){const[t,s]=i[o],r=new Float32Array(a);for(let i=0;i<a;i++){const a=e[i];r[i]=Array.isArray(a)||ArrayBuffer.isView(a)?a[t]??0:0}n[s]=r}const s=null!=t?.AudioOffset?Math.round(t.AudioOffset/1e4):(t?.FrameIndex||0)*this.frameDuration;this.azureBlendShapes.sbuffer.push({name:"blendshapes",delay:s,dt:this._getDtArray(a),vs:n})}handleReceivedWordBoundaryEvent(t){try{this.liveCaptions.handleWordBoundaryEvent(t)}catch(s){}const e=this.speak,i=t.text,a=t.audioOffset,n=t.duration;"SpeechSynthesisBoundaryType.Punctuation"===t.boundaryType&&e.words.length?e.words[e.words.length-1]+=i:"SpeechSynthesisBoundaryType.Word"===t.boundaryType||"SpeechSynthesisBoundaryType.Punctuation"===t.boundaryType?(e.words.push(i),e.wtimes.push(a),e.wdurations.push(n)):"SpeechSynthesisBoundaryType.Sentence"===t.boundaryType&&a>500&&(e.markers.push((()=>{this.talkingAvatar.lookAtCamera(500)})),e.mtimes.push(a-500))}handlePendingVisemes(t=null){if("visemes"===this.lipsyncType&&this.prevViseme){const e=this.prevViseme;t||(t=100),this.speak.visemes.push(e.viseme),this.speak.vtimes.push(e.vtime),this.speak.vdurations.push(t),this.prevViseme=null}"visemes"===this.lipsyncType&&this.speak.visemes.length&&this.talkingAvatar.streamAudio({visemes:this.speak.visemes.splice(0,this.speak.visemes.length),vtimes:this.speak.vtimes.splice(0,this.speak.vtimes.length),vdurations:this.speak.vdurations.splice(0,this.speak.vdurations.length)}),"blendshapes"===this.lipsyncType&&this.azureBlendShapes.sbuffer.length&&this.talkingAvatar.streamAudio({anims:this.azureBlendShapes.sbuffer.splice(0,this.azureBlendShapes.sbuffer.length)})}async startStreaming(t,e,i){if(this.currentTurnId=i,this.isStoppingSpeaking=!1,this._audioStartSent=!1,!this.isRenderingActive()){try{t?.cancel?.()}catch(n){}try{e?.cancel?.()}catch(n){}return this.handleAudioEndOnce(i,"suppressed"),void(this.currentTurnId=null)}const a=i;this._endedTurns.delete(a??"__null__");try{this.startStreamPump(t),this.startLipsyncPump(e),this.conversationStreamActive||await this.startConversationStream()}catch(s){this.handleAudioEndOnce(a,"error"),this.currentTurnId===a&&(this.currentTurnId=null),this.isStoppingSpeaking=!1}}_notifyAudioStart(t,e=null){if(this._audioStartSent)return;this._audioStartSent=!0;const i=e??("undefined"!=typeof performance?performance.now():Date.now()),a=t??this.currentTurnId,n=a||0===a?{turnId:a,audioStartTime:i}:{audioStartTime:i},s=()=>{try{this.avatarOrchestrator?.sendEvent("AUDIO_START",n)}catch(t){}};"function"==typeof queueMicrotask?queueMicrotask(s):setTimeout(s,0)}interruptSpeaking(){if(!this.isStoppingSpeaking){this.isStoppingSpeaking=!0,this.conversationStreamActive&&this.talkingAvatar.streamInterrupt(),this.audioReader?.cancel(),this.lipsyncReader?.cancel(),this._pendingEndReason="interrupted";try{this.liveCaptions?.clearCaptions?.()}catch(t){}try{this.bus?.emit?.("event_command_UI_ClearCaptions")}catch(t){}this.isStoppingSpeaking=!1}}setView(t){switch(t){case"full":this.talkingAvatar.setView("full");break;case"mid":this.talkingAvatar.setView("mid");break;case"upper":this.talkingAvatar.setView("upper");break;case"head":this.talkingAvatar.setView("head")}}playAnimation(t,e){const i=`https://sentifydfrontend.blob.core.windows.net/animationclips/${t}`;this.setView("full"),this.talkingAvatar.playAnimation(i,null,e)}reconnect(){}async destroy(){for(const[t,e]of this._busHandlers)try{this.bus.off(t,e)}catch{}this._busHandlers.length=0,this.isStoppingSpeaking=!1,this.conversationStreamActive&&await this.stopConversationStream(),this.talkingAvatar?.stop(),this.talkingAvatar=null}_getBlendColumns(){if(!this._blendCols){this._blendCols=[];for(let t=0;t<r.length;t++){const e=r[t];e&&this._blendCols.push([t,e])}}return this._blendCols}_getDtArray(t){this._dtCache||(this._dtCache=new Map);let e=this._dtCache.get(t);return e||(e=new Array(t).fill(this.frameDuration),this._dtCache.set(t,e)),e}}export{l as TalkingAvatar};
|