@sage-rsc/talking-head-react 1.7.2 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.js +411 -407
- package/package.json +1 -1
- package/src/components/SimpleTalkingAvatar.jsx +33 -4
package/package.json
CHANGED
|
@@ -474,14 +474,26 @@ const SimpleTalkingAvatar = forwardRef(({
|
|
|
474
474
|
|
|
475
475
|
// Create callback that will play next animation if still speaking
|
|
476
476
|
const animationFinishedCallback = () => {
|
|
477
|
-
//
|
|
478
|
-
|
|
477
|
+
// Check if avatar is still speaking (check both ref and TalkingHead's internal state)
|
|
478
|
+
const isStillSpeaking = isSpeakingRef.current &&
|
|
479
|
+
currentAnimationGroupRef.current === groupName &&
|
|
480
|
+
talkingHeadRef.current &&
|
|
481
|
+
(talkingHeadRef.current.isSpeaking ||
|
|
482
|
+
(talkingHeadRef.current.audioPlaylist && talkingHeadRef.current.audioPlaylist.length > 0) ||
|
|
483
|
+
(talkingHeadRef.current.speechQueue && talkingHeadRef.current.speechQueue.length > 0));
|
|
484
|
+
|
|
485
|
+
if (isStillSpeaking) {
|
|
479
486
|
// Small delay for smooth transition
|
|
480
487
|
setTimeout(() => {
|
|
481
488
|
playRandomAnimation(groupName, disablePositionLock, onFinished);
|
|
482
489
|
}, 100);
|
|
483
|
-
} else
|
|
484
|
-
|
|
490
|
+
} else {
|
|
491
|
+
// Speech has ended, stop animations
|
|
492
|
+
isSpeakingRef.current = false;
|
|
493
|
+
currentAnimationGroupRef.current = null;
|
|
494
|
+
if (onFinished) {
|
|
495
|
+
onFinished();
|
|
496
|
+
}
|
|
485
497
|
}
|
|
486
498
|
};
|
|
487
499
|
|
|
@@ -493,6 +505,23 @@ const SimpleTalkingAvatar = forwardRef(({
|
|
|
493
505
|
console.error(`Failed to play animation:`, error);
|
|
494
506
|
return null;
|
|
495
507
|
}
|
|
508
|
+
} else {
|
|
509
|
+
// No more animations in queue, but check if we should reshuffle and continue
|
|
510
|
+
const isStillSpeaking = isSpeakingRef.current &&
|
|
511
|
+
currentAnimationGroupRef.current === groupName &&
|
|
512
|
+
talkingHeadRef.current &&
|
|
513
|
+
(talkingHeadRef.current.isSpeaking ||
|
|
514
|
+
(talkingHeadRef.current.audioPlaylist && talkingHeadRef.current.audioPlaylist.length > 0) ||
|
|
515
|
+
(talkingHeadRef.current.speechQueue && talkingHeadRef.current.speechQueue.length > 0));
|
|
516
|
+
|
|
517
|
+
if (isStillSpeaking) {
|
|
518
|
+
// Queue is empty but still speaking, reshuffle and continue
|
|
519
|
+
animationQueueRef.current = [];
|
|
520
|
+
playedAnimationsRef.current = [];
|
|
521
|
+
setTimeout(() => {
|
|
522
|
+
playRandomAnimation(groupName, disablePositionLock, onFinished);
|
|
523
|
+
}, 100);
|
|
524
|
+
}
|
|
496
525
|
}
|
|
497
526
|
return null;
|
|
498
527
|
}, [getNextAnimation, getAnimationName]);
|