@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sage-rsc/talking-head-react",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "A reusable React component for 3D talking avatars with lip-sync and text-to-speech",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -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
- // If still speaking and same group, play next animation from queue
478
- if (isSpeakingRef.current && currentAnimationGroupRef.current === groupName) {
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 if (onFinished) {
484
- onFinished();
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]);