@sage-rsc/talking-head-react 1.0.57 → 1.0.58
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 +2 -2
- package/dist/index.js +150 -147
- package/package.json +1 -1
- package/src/components/CurriculumLearning.jsx +6 -1
- package/src/components/TalkingHeadAvatar.jsx +24 -9
package/package.json
CHANGED
|
@@ -994,7 +994,12 @@ const CurriculumLearning = forwardRef(({
|
|
|
994
994
|
stopSpeaking: () => avatarRef.current?.stopSpeaking(),
|
|
995
995
|
pauseSpeaking: () => avatarRef.current?.pauseSpeaking(),
|
|
996
996
|
resumeSpeaking: async () => await avatarRef.current?.resumeSpeaking(),
|
|
997
|
-
isPaused: () =>
|
|
997
|
+
isPaused: () => {
|
|
998
|
+
if (avatarRef.current && typeof avatarRef.current.isPaused !== 'undefined') {
|
|
999
|
+
return avatarRef.current.isPaused;
|
|
1000
|
+
}
|
|
1001
|
+
return false;
|
|
1002
|
+
},
|
|
998
1003
|
setMood: (mood) => avatarRef.current?.setMood(mood),
|
|
999
1004
|
playAnimation: (animationName, disablePositionLock) => avatarRef.current?.playAnimation(animationName, disablePositionLock),
|
|
1000
1005
|
setBodyMovement: (movement) => avatarRef.current?.setBodyMovement(movement),
|
|
@@ -399,8 +399,19 @@ const TalkingHeadAvatar = forwardRef(({
|
|
|
399
399
|
|
|
400
400
|
const pauseSpeaking = useCallback(() => {
|
|
401
401
|
if (talkingHeadRef.current && talkingHeadRef.current.pauseSpeaking) {
|
|
402
|
-
//
|
|
403
|
-
|
|
402
|
+
// Check if avatar is currently speaking
|
|
403
|
+
const talkingHead = talkingHeadRef.current;
|
|
404
|
+
const isCurrentlySpeaking = talkingHead.isSpeaking ||
|
|
405
|
+
(talkingHead.audioPlaylist && talkingHead.audioPlaylist.length > 0) ||
|
|
406
|
+
(talkingHead.speechQueue && talkingHead.speechQueue.length > 0);
|
|
407
|
+
|
|
408
|
+
// Only pause if avatar is actually speaking
|
|
409
|
+
if (isCurrentlySpeaking && pausedSpeechRef.current && pausedSpeechRef.current.text) {
|
|
410
|
+
talkingHeadRef.current.pauseSpeaking();
|
|
411
|
+
setIsPaused(true);
|
|
412
|
+
} else if (isCurrentlySpeaking) {
|
|
413
|
+
// If speaking but no paused speech stored, try to pause anyway
|
|
414
|
+
// This handles cases where speech started before we could track it
|
|
404
415
|
talkingHeadRef.current.pauseSpeaking();
|
|
405
416
|
setIsPaused(true);
|
|
406
417
|
}
|
|
@@ -408,16 +419,17 @@ const TalkingHeadAvatar = forwardRef(({
|
|
|
408
419
|
}, []);
|
|
409
420
|
|
|
410
421
|
const resumeSpeaking = useCallback(async () => {
|
|
411
|
-
if (talkingHeadRef.current &&
|
|
422
|
+
if (talkingHeadRef.current && isPaused) {
|
|
412
423
|
setIsPaused(false);
|
|
413
|
-
const pausedSpeech = pausedSpeechRef.current;
|
|
414
|
-
pausedSpeechRef.current = null;
|
|
415
424
|
|
|
416
425
|
// Resume audio context
|
|
417
426
|
await resumeAudioContext();
|
|
418
427
|
|
|
419
|
-
// Re-speak the paused text
|
|
420
|
-
if (
|
|
428
|
+
// Re-speak the paused text if we have it stored
|
|
429
|
+
if (pausedSpeechRef.current && pausedSpeechRef.current.text) {
|
|
430
|
+
const pausedSpeech = pausedSpeechRef.current;
|
|
431
|
+
pausedSpeechRef.current = null; // Clear after getting the text
|
|
432
|
+
|
|
421
433
|
const speakOptions = {
|
|
422
434
|
...pausedSpeech.options,
|
|
423
435
|
lipsyncLang: pausedSpeech.options.lipsyncLang || defaultAvatarConfig.lipsyncLang || 'en'
|
|
@@ -429,9 +441,12 @@ const TalkingHeadAvatar = forwardRef(({
|
|
|
429
441
|
}
|
|
430
442
|
talkingHeadRef.current.speakText(pausedSpeech.text, speakOptions);
|
|
431
443
|
}
|
|
444
|
+
} else {
|
|
445
|
+
// If no paused speech stored, just clear the pause state
|
|
446
|
+
pausedSpeechRef.current = null;
|
|
432
447
|
}
|
|
433
448
|
}
|
|
434
|
-
}, [resumeAudioContext]);
|
|
449
|
+
}, [resumeAudioContext, isPaused]);
|
|
435
450
|
|
|
436
451
|
const setMood = useCallback((mood) => {
|
|
437
452
|
if (talkingHeadRef.current) {
|
|
@@ -517,7 +532,7 @@ const TalkingHeadAvatar = forwardRef(({
|
|
|
517
532
|
setTimingAdjustment,
|
|
518
533
|
playAnimation,
|
|
519
534
|
isReady,
|
|
520
|
-
isPaused,
|
|
535
|
+
isPaused: isPaused,
|
|
521
536
|
talkingHead: talkingHeadRef.current,
|
|
522
537
|
handleResize,
|
|
523
538
|
setBodyMovement: (movement) => {
|