@sage-rsc/talking-head-react 1.0.63 → 1.0.65
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 +191 -185
- package/package.json +1 -1
- package/src/components/TalkingHeadAvatar.jsx +61 -47
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxs as Ee, jsx as
|
|
2
|
-
import { forwardRef as Ie, useRef as
|
|
1
|
+
import { jsxs as Ee, jsx as ce } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Ie, useRef as Z, useState as pe, useEffect as ge, useCallback as E, useImperativeHandle as Le, useLayoutEffect as We } from "react";
|
|
3
3
|
import * as f from "three";
|
|
4
4
|
import { OrbitControls as Ve } from "three/addons/controls/OrbitControls.js";
|
|
5
5
|
import { GLTFLoader as Ge } from "three/addons/loaders/GLTFLoader.js";
|
|
@@ -7,12 +7,12 @@ import { DRACOLoader as Ze } from "three/addons/loaders/DRACOLoader.js";
|
|
|
7
7
|
import { FBXLoader as ze } from "three/addons/loaders/FBXLoader.js";
|
|
8
8
|
import { RoomEnvironment as Xe } from "three/addons/environments/RoomEnvironment.js";
|
|
9
9
|
import Ye from "three/addons/libs/stats.module.js";
|
|
10
|
-
let m,
|
|
10
|
+
let m, K, $;
|
|
11
11
|
const A = [0, 0, 0, 0], k = new f.Vector3(), be = new f.Vector3(), Q = new f.Vector3(), ve = new f.Vector3();
|
|
12
12
|
new f.Plane();
|
|
13
13
|
new f.Ray();
|
|
14
14
|
new f.Euler();
|
|
15
|
-
const q = new f.Quaternion(), Ce = new f.Quaternion(),
|
|
15
|
+
const q = new f.Quaternion(), Ce = new f.Quaternion(), ae = new f.Matrix4(), re = new f.Matrix4();
|
|
16
16
|
new f.Vector3();
|
|
17
17
|
const Re = new f.Vector3(0, 0, 1), je = new f.Vector3(1, 0, 0), Qe = new f.Vector3(0, 1, 0), qe = new f.Vector3(0, 0, 1);
|
|
18
18
|
class _e {
|
|
@@ -356,14 +356,14 @@ class _e {
|
|
|
356
356
|
for (this.timerMs += t, t > 1e3 && (this.timerMs = 0), t /= 1e3, e = 0, i = this.objectsUpdate.length; e < i; e++)
|
|
357
357
|
o = this.objectsUpdate[e], o.updateMatrix(), o.parent === null ? o.matrixWorld.copy(o.matrix) : o.matrixWorld.multiplyMatrices(o.parent.matrixWorld, o.matrix), o.matrixWorldNeedsUpdate = !1;
|
|
358
358
|
for (e = 0, i = this.data.length; e < i; e++) {
|
|
359
|
-
if (o = this.data[e], k.copy(o.vWorld),
|
|
359
|
+
if (o = this.data[e], k.copy(o.vWorld), ae.copy(o.boneParent.matrixWorld), re.copy(ae).invert(), o.vWorld.setFromMatrixPosition(ae), k.applyMatrix4(re), k.length() > 0.5 && (console.info("Info: Unrealistic jump of " + k.length().toFixed(2) + " meters."), k.setLength(0.5)), k.applyQuaternion(o.bone.quaternion), A[0] = k.x, A[1] = k.y, A[2] = -k.z, A[3] = k.length() / 3, o.children)
|
|
360
360
|
for (n = 0, s = o.children.length; n < s; n++)
|
|
361
361
|
m = o.children[n], A[0] -= m.v[0] * t / 3, A[1] -= m.v[1] * t / 3, A[2] += m.v[2] * t / 3, A[3] -= m.v[3] * t / 3;
|
|
362
362
|
if (m = this.opt.sensitivityFactor, A[0] *= o.ext * m, A[1] *= o.ext * m, A[2] *= o.ext * m, A[3] *= o.ext * m, o.isX && (m = A[0] / t, o.ea[0] = (m - o.ev[0]) / t, o.ev[0] = m, o.a[0] = -o.k[0] * o.p[0] - o.c[0] * o.v[0] - o.ea[0], o.p[0] += o.v[0] * t + o.a[0] * t * t / 2 + A[0], m = o.v[0] + o.a[0] * t / 2, m = -o.k[0] * o.p[0] - o.c[0] * m - o.ea[0], o.v[0] = o.v[0] + (m + o.a[0]) * t / 2), o.isY && (m = A[1] / t, o.ea[1] = (m - o.ev[1]) / t, o.ev[1] = m, o.a[1] = -o.k[1] * o.p[1] - o.c[1] * o.v[1] - o.ea[1], o.p[1] += o.v[1] * t + o.a[1] * t * t / 2 + A[1], m = o.v[1] + o.a[1] * t / 2, m = -o.k[1] * o.p[1] - o.c[1] * m - o.ea[1], o.v[1] = o.v[1] + (m + o.a[1]) * t / 2), o.isZ && (m = A[2] / t, o.ea[2] = (m - o.ev[2]) / t, o.ev[2] = m, o.a[2] = -o.k[2] * o.p[2] - o.c[2] * o.v[2] - o.ea[2], o.p[2] += o.v[2] * t + o.a[2] * t * t / 2 + A[2], m = o.v[2] + o.a[2] * t / 2, m = -o.k[2] * o.p[2] - o.c[2] * m - o.ea[2], o.v[2] = o.v[2] + (m + o.a[2]) * t / 2), o.isT && (m = A[3] / t, o.ea[3] = (m - o.ev[3]) / t, o.ev[3] = m, o.a[3] = -o.k[3] * o.p[3] - o.c[3] * o.v[3] - o.ea[3], o.p[3] += o.v[3] * t + o.a[3] * t * t / 2 + A[3], m = o.v[3] + o.a[3] * t / 2, m = -o.k[3] * o.p[3] - o.c[3] * m - o.ea[3], o.v[3] = o.v[3] + (m + o.a[3]) * t / 2), this.timerMs < this.opt.warmupMs && (o.v[0] *= 1e-4, o.p[0] *= 1e-4, o.v[1] *= 1e-4, o.p[1] *= 1e-4, o.v[2] *= 1e-4, o.p[2] *= 1e-4, o.v[3] *= 1e-4, o.p[3] *= 1e-4), A[0] = o.p[0], A[1] = o.p[1], A[2] = o.p[2], A[3] = o.p[3], m = this.opt.movementFactor, A[0] *= m, A[1] *= m, A[2] *= m, A[3] *= m, o.dl && (m = o.dl, A[0] += m[0], A[1] += m[1], A[2] += m[2]), o.dw && (m = o.dw, k.set(
|
|
363
363
|
o.vBasis.x + A[0],
|
|
364
364
|
o.vBasis.y + A[1],
|
|
365
365
|
o.vBasis.z + A[2]
|
|
366
|
-
), k.applyMatrix4(
|
|
366
|
+
), k.applyMatrix4(ae), k.x += m[0], k.y += m[1], k.z += m[2], k.applyMatrix4(re), A[0] += k.x - o.vBasis.x, A[1] += k.y - o.vBasis.y, A[2] += k.z - o.vBasis.z), o.limits && this.opt.isLimits && (m = o.limits, m[0] && (m[0][0] !== null && A[0] < m[0][0] && (A[0] = m[0][0]), m[0][1] !== null && A[0] > m[0][1] && (A[0] = m[0][1])), m[1] && (m[1][0] !== null && A[1] < m[1][0] && (A[1] = m[1][0]), m[1][1] !== null && A[1] > m[1][1] && (A[1] = m[1][1])), m[2] && (m[2][0] !== null && A[2] < m[2][0] && (A[2] = m[2][0]), m[2][1] !== null && A[2] > m[2][1] && (A[2] = m[2][1])), m[3] && (m[3][0] !== null && A[3] < m[3][0] && (A[3] = m[3][0]), m[3][1] !== null && A[3] > m[3][1] && (A[3] = m[3][1]))), o.isPoint)
|
|
367
367
|
o.bone.position.set(
|
|
368
368
|
o.vBasis.x + A[0],
|
|
369
369
|
o.vBasis.y + A[1],
|
|
@@ -371,7 +371,7 @@ class _e {
|
|
|
371
371
|
);
|
|
372
372
|
else if (o.boneParent.quaternion.copy(o.qBasis), o.pivot && this.opt.isPivots && (o.boneParent.updateWorldMatrix(!1, !1), o.boneParent.matrixWorld.decompose(k, q, Q), k.copy(Re).applyQuaternion(q).setY(0).normalize(), q.premultiply(Ce.setFromUnitVectors(Re, k).invert()).normalize(), o.boneParent.quaternion.multiply(q.invert()), o.boneParent.quaternion.multiply(o.qWorldInverseYaw)), o.isZ && (m = Math.atan(A[0] / o.l), q.setFromAxisAngle(qe, -m), o.boneParent.quaternion.multiply(q)), o.isY && (m = o.l / 3, m = m * Math.tanh(A[1] / m), o.bone.position.setLength(o.l + m)), o.isX && (m = Math.atan(A[2] / o.l), q.setFromAxisAngle(je, -m), o.boneParent.quaternion.multiply(q)), o.isT && (m = 1.5 * Math.tanh(A[3] * 1.5), q.setFromAxisAngle(Qe, -m), o.boneParent.quaternion.multiply(q)), o.boneParent.updateWorldMatrix(!1, !0), o.excludes && this.opt.isExcludes)
|
|
373
373
|
for (n = 0, s = o.excludes.length; n < s; n++)
|
|
374
|
-
m = o.excludes[n], Q.set(0, 0, 0), m.deltaLocal && (Q.x += m.deltaLocal[0], Q.y += m.deltaLocal[1], Q.z += m.deltaLocal[2]), Q.applyMatrix4(m.bone.matrixWorld),
|
|
374
|
+
m = o.excludes[n], Q.set(0, 0, 0), m.deltaLocal && (Q.x += m.deltaLocal[0], Q.y += m.deltaLocal[1], Q.z += m.deltaLocal[2]), Q.applyMatrix4(m.bone.matrixWorld), re.copy(o.boneParent.matrixWorld).invert(), Q.applyMatrix4(re), k.copy(o.bone.position), !(k.distanceToSquared(Q) >= m.radiusSq) && ($ = k.length(), K = Q.length(), !(K > m.radius + $) && (K < Math.abs(m.radius - $) || (K = (K * K + $ * $ - m.radiusSq) / (2 * K), Q.normalize(), ve.copy(Q).multiplyScalar(K), K = Math.sqrt($ * $ - K * K), k.subVectors(k, ve).projectOnPlane(Q).normalize().multiplyScalar(K), be.subVectors(o.vBasis, ve).projectOnPlane(Q).normalize(), $ = be.dot(k), $ < 0 && ($ = Math.sqrt(K * K - $ * $), be.multiplyScalar($), k.add(be)), k.add(ve).normalize(), Q.copy(o.bone.position).normalize(), q.setFromUnitVectors(Q, k), o.boneParent.quaternion.premultiply(q), o.boneParent.updateWorldMatrix(!1, !0))));
|
|
375
375
|
}
|
|
376
376
|
this.helpers.isActive && this.updateHelpers();
|
|
377
377
|
}
|
|
@@ -442,17 +442,17 @@ class _e {
|
|
|
442
442
|
*/
|
|
443
443
|
updateHelpers() {
|
|
444
444
|
if (m = this.helpers.points, m.bones.length) {
|
|
445
|
-
|
|
445
|
+
re.copy(this.armature.matrixWorld).invert();
|
|
446
446
|
const t = m.object.geometry.getAttribute("position");
|
|
447
447
|
for (let e = 0, n = m.bones.length; e < n; e++)
|
|
448
|
-
|
|
448
|
+
ae.multiplyMatrices(re, m.bones[e].matrixWorld), k.setFromMatrixPosition(ae), t.setXYZ(e, k.x, k.y, k.z);
|
|
449
449
|
t.needsUpdate = !0, m.object.updateMatrixWorld();
|
|
450
450
|
}
|
|
451
451
|
if (m = this.helpers.lines, m.bones.length) {
|
|
452
|
-
|
|
452
|
+
re.copy(this.armature.matrixWorld).invert();
|
|
453
453
|
const t = m.object.geometry.getAttribute("position");
|
|
454
454
|
for (let e = 0, n = 0, i = m.bones.length; e < i; e++, n += 2)
|
|
455
|
-
|
|
455
|
+
ae.multiplyMatrices(re, m.bones[e].matrixWorld), k.setFromMatrixPosition(ae), t.setXYZ(n, k.x, k.y, k.z), ae.multiplyMatrices(re, m.bones[e].parent.matrixWorld), k.setFromMatrixPosition(ae), t.setXYZ(n + 1, k.x, k.y, k.z);
|
|
456
456
|
t.needsUpdate = !0, m.object.updateMatrixWorld();
|
|
457
457
|
}
|
|
458
458
|
}
|
|
@@ -2629,7 +2629,7 @@ const rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
2629
2629
|
fr: it,
|
|
2630
2630
|
fi: st,
|
|
2631
2631
|
lt: rt
|
|
2632
|
-
}, W = new f.Quaternion(), F = new f.Euler(),
|
|
2632
|
+
}, W = new f.Quaternion(), F = new f.Euler(), he = new f.Vector3(), ue = new f.Vector3(), Te = new f.Box3();
|
|
2633
2633
|
new f.Matrix4();
|
|
2634
2634
|
new f.Matrix4();
|
|
2635
2635
|
new f.Vector3();
|
|
@@ -5180,7 +5180,7 @@ class Fe {
|
|
|
5180
5180
|
eyeLookOutRight: [null, 0],
|
|
5181
5181
|
eyeContact: [0]
|
|
5182
5182
|
}
|
|
5183
|
-
})))), e > 2 * this.animFrameDur && (e = 2 * this.animFrameDur), (this.viewName !== "full" || this.isAvatarOnly) && (n = this.mtRandomized[Math.floor(Math.random() * this.mtRandomized.length)], i = this.mtAvatar[n], i.needsUpdate || Object.assign(i, { base: (this.mood.baseline[n] || 0) + (1 + l / 255) * Math.random() / 5, needsUpdate: !0 })), this.updatePoseBase(this.animClock), this.mixer && this.mixer.update(e / 1e3 * this.mixer.timeScale), this.updatePoseDelta(), (this.isSpeaking || this.isListening) && u ? l > this.volumeMax ? (this.volumeHeadBase = 0.05, Math.random() > 0.6 && (this.volumeHeadTarget = -0.05 - Math.random() / 15), this.volumeMax = l) : (this.volumeMax *= 0.92, this.volumeHeadTarget = this.volumeHeadBase - 0.9 * (this.volumeHeadBase - this.volumeHeadTarget)) : (this.volumeHeadTarget = 0, this.volumeMax = 0), n = this.volumeHeadTarget - this.volumeHeadCurrent, i = Math.abs(n), i > 1e-4 && (o = i * (this.volumeHeadEasing(Math.min(1, this.volumeHeadVelocity * e / 1e3 / i) / 2 + 0.5) - 0.5), this.volumeHeadCurrent += Math.sign(n) * Math.min(i, o)), Math.abs(this.volumeHeadCurrent) > 1e-4 && (W.setFromAxisAngle(ht, this.volumeHeadCurrent), this.objectNeck.quaternion.multiply(W)), Te.setFromObject(this.armature), this.objectLeftToeBase.getWorldPosition(
|
|
5183
|
+
})))), e > 2 * this.animFrameDur && (e = 2 * this.animFrameDur), (this.viewName !== "full" || this.isAvatarOnly) && (n = this.mtRandomized[Math.floor(Math.random() * this.mtRandomized.length)], i = this.mtAvatar[n], i.needsUpdate || Object.assign(i, { base: (this.mood.baseline[n] || 0) + (1 + l / 255) * Math.random() / 5, needsUpdate: !0 })), this.updatePoseBase(this.animClock), this.mixer && this.mixer.update(e / 1e3 * this.mixer.timeScale), this.updatePoseDelta(), (this.isSpeaking || this.isListening) && u ? l > this.volumeMax ? (this.volumeHeadBase = 0.05, Math.random() > 0.6 && (this.volumeHeadTarget = -0.05 - Math.random() / 15), this.volumeMax = l) : (this.volumeMax *= 0.92, this.volumeHeadTarget = this.volumeHeadBase - 0.9 * (this.volumeHeadBase - this.volumeHeadTarget)) : (this.volumeHeadTarget = 0, this.volumeMax = 0), n = this.volumeHeadTarget - this.volumeHeadCurrent, i = Math.abs(n), i > 1e-4 && (o = i * (this.volumeHeadEasing(Math.min(1, this.volumeHeadVelocity * e / 1e3 / i) / 2 + 0.5) - 0.5), this.volumeHeadCurrent += Math.sign(n) * Math.min(i, o)), Math.abs(this.volumeHeadCurrent) > 1e-4 && (W.setFromAxisAngle(ht, this.volumeHeadCurrent), this.objectNeck.quaternion.multiply(W)), Te.setFromObject(this.armature), this.objectLeftToeBase.getWorldPosition(he), he.sub(this.armature.position), this.objectRightToeBase.getWorldPosition(ue), ue.sub(this.armature.position), this.objectHips.position.y -= Te.min.y / 2, this.objectHips.position.x -= (he.x + ue.x) / 4, this.objectHips.position.z -= (he.z + ue.z) / 2, this.dynamicbones.update(e), this.fbxAnimationLoader && this.fbxAnimationLoader.update(), this.opt.update && this.opt.update(e), this.updateMorphTargets(e), this.isAvatarOnly)
|
|
5184
5184
|
this.stats && this.stats.end();
|
|
5185
5185
|
else {
|
|
5186
5186
|
if (this.cameraClock !== null && this.cameraClock < 1e3) {
|
|
@@ -5267,12 +5267,12 @@ class Fe {
|
|
|
5267
5267
|
}), h = ""), r.length)) {
|
|
5268
5268
|
const R = this.lipsyncWordsToVisemes(r, a);
|
|
5269
5269
|
if (R && R.visemes && R.visemes.length) {
|
|
5270
|
-
const
|
|
5270
|
+
const T = R.times[R.visemes.length - 1] + R.durations[R.visemes.length - 1];
|
|
5271
5271
|
for (let P = 0; P < R.visemes.length; P++)
|
|
5272
5272
|
g.push({
|
|
5273
5273
|
mark: c,
|
|
5274
5274
|
template: { name: "viseme" },
|
|
5275
|
-
ts: [(R.times[P] - 0.6) /
|
|
5275
|
+
ts: [(R.times[P] - 0.6) / T, (R.times[P] + 0.5) / T, (R.times[P] + R.durations[P] + 0.5) / T],
|
|
5276
5276
|
vs: {
|
|
5277
5277
|
["viseme_" + R.visemes[P]]: [null, R.visemes[P] === "PP" || R.visemes[P] === "FF" ? 0.9 : 0.6, 0]
|
|
5278
5278
|
}
|
|
@@ -5486,7 +5486,7 @@ class Fe {
|
|
|
5486
5486
|
if (x && x.visemes && x.visemes.length > 0) {
|
|
5487
5487
|
const p = x.times[x.visemes.length - 1] + x.durations[x.visemes.length - 1];
|
|
5488
5488
|
for (let H = 0; H < x.visemes.length; H++) {
|
|
5489
|
-
const z = x.visemes[H], R = x.times[H] / p,
|
|
5489
|
+
const z = x.visemes[H], R = x.times[H] / p, T = x.durations[H] / p, P = R * c, ee = T * c;
|
|
5490
5490
|
I.push({
|
|
5491
5491
|
template: { name: "viseme" },
|
|
5492
5492
|
ts: [P - Math.min(60, 2 * ee / 3), P + Math.min(25, ee / 2), P + ee + Math.min(60, ee / 2)],
|
|
@@ -6133,7 +6133,7 @@ class Fe {
|
|
|
6133
6133
|
*/
|
|
6134
6134
|
lookAtCamera(t) {
|
|
6135
6135
|
let e;
|
|
6136
|
-
if (this.speakTo && (e = new f.Vector3(), this.speakTo.objectLeftEye?.isObject3D ? (this.speakTo.armature.objectHead, this.speakTo.objectLeftEye.updateMatrixWorld(!0), this.speakTo.objectRightEye.updateMatrixWorld(!0),
|
|
6136
|
+
if (this.speakTo && (e = new f.Vector3(), this.speakTo.objectLeftEye?.isObject3D ? (this.speakTo.armature.objectHead, this.speakTo.objectLeftEye.updateMatrixWorld(!0), this.speakTo.objectRightEye.updateMatrixWorld(!0), he.setFromMatrixPosition(this.speakTo.objectLeftEye.matrixWorld), ue.setFromMatrixPosition(this.speakTo.objectRightEye.matrixWorld), e.addVectors(he, ue).divideScalar(2)) : this.speakTo.isObject3D ? this.speakTo.getWorldPosition(e) : this.speakTo.isVector3 ? e.set(this.speakTo) : this.speakTo.x && this.speakTo.y && this.speakTo.z && e.set(this.speakTo.x, this.speakTo.y, this.speakTo.z)), !e) {
|
|
6137
6137
|
if (this.avatar.hasOwnProperty("avatarIgnoreCamera")) {
|
|
6138
6138
|
if (this.avatar.avatarIgnoreCamera) {
|
|
6139
6139
|
this.lookAhead(t);
|
|
@@ -6146,8 +6146,8 @@ class Fe {
|
|
|
6146
6146
|
this.lookAt(null, null, t);
|
|
6147
6147
|
return;
|
|
6148
6148
|
}
|
|
6149
|
-
this.objectLeftEye.updateMatrixWorld(!0), this.objectRightEye.updateMatrixWorld(!0),
|
|
6150
|
-
const n = new f.Vector3().subVectors(e,
|
|
6149
|
+
this.objectLeftEye.updateMatrixWorld(!0), this.objectRightEye.updateMatrixWorld(!0), he.setFromMatrixPosition(this.objectLeftEye.matrixWorld), ue.setFromMatrixPosition(this.objectRightEye.matrixWorld), he.add(ue).divideScalar(2), W.copy(this.armature.quaternion), W.multiply(this.poseTarget.props["Hips.quaternion"]), W.multiply(this.poseTarget.props["Spine.quaternion"]), W.multiply(this.poseTarget.props["Spine1.quaternion"]), W.multiply(this.poseTarget.props["Spine2.quaternion"]), W.multiply(this.poseTarget.props["Neck.quaternion"]), W.multiply(this.poseTarget.props["Head.quaternion"]);
|
|
6150
|
+
const n = new f.Vector3().subVectors(e, he).normalize(), i = Math.atan2(n.x, n.z), s = Math.asin(-n.y);
|
|
6151
6151
|
F.set(s, i, 0, "YXZ");
|
|
6152
6152
|
const l = new f.Quaternion().setFromEuler(F), u = new f.Quaternion().copy(l).multiply(W.clone().invert());
|
|
6153
6153
|
F.setFromQuaternion(u, "YXZ");
|
|
@@ -6685,26 +6685,26 @@ const Pe = Ie(({
|
|
|
6685
6685
|
style: y = {},
|
|
6686
6686
|
animations: x = {}
|
|
6687
6687
|
}, I) => {
|
|
6688
|
-
const D =
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
}, [j]),
|
|
6688
|
+
const D = Z(null), p = Z(null), H = Z(a), z = Z(null), R = Z(null), T = Z(!1), P = Z({ remainingText: null, originalText: null, options: null }), [ee, le] = pe(!0), [S, N] = pe(null), [X, Y] = pe(!1), [j, _] = pe(!1);
|
|
6689
|
+
ge(() => {
|
|
6690
|
+
T.current = j;
|
|
6691
|
+
}, [j]), ge(() => {
|
|
6692
6692
|
H.current = a;
|
|
6693
6693
|
}, [a]);
|
|
6694
|
-
const te = Ae(),
|
|
6694
|
+
const te = Ae(), de = i || te.service;
|
|
6695
6695
|
let oe;
|
|
6696
|
-
|
|
6696
|
+
de === "browser" ? oe = {
|
|
6697
6697
|
service: "browser",
|
|
6698
6698
|
endpoint: "",
|
|
6699
6699
|
apiKey: null,
|
|
6700
6700
|
defaultVoice: "Google US English"
|
|
6701
|
-
} :
|
|
6701
|
+
} : de === "elevenlabs" ? oe = {
|
|
6702
6702
|
service: "elevenlabs",
|
|
6703
6703
|
endpoint: "https://api.elevenlabs.io/v1/text-to-speech",
|
|
6704
6704
|
apiKey: o || te.apiKey,
|
|
6705
6705
|
defaultVoice: s || te.defaultVoice || ye.defaultVoice,
|
|
6706
6706
|
voices: te.voices || ye.voices
|
|
6707
|
-
} :
|
|
6707
|
+
} : de === "deepgram" ? oe = {
|
|
6708
6708
|
service: "deepgram",
|
|
6709
6709
|
endpoint: "https://api.deepgram.com/v1/speak",
|
|
6710
6710
|
apiKey: o || te.apiKey,
|
|
@@ -6715,11 +6715,11 @@ const Pe = Ie(({
|
|
|
6715
6715
|
// Override API key if provided via props
|
|
6716
6716
|
apiKey: o !== null ? o : te.apiKey
|
|
6717
6717
|
};
|
|
6718
|
-
const
|
|
6718
|
+
const me = {
|
|
6719
6719
|
url: O,
|
|
6720
6720
|
body: t,
|
|
6721
6721
|
avatarMood: e,
|
|
6722
|
-
ttsLang:
|
|
6722
|
+
ttsLang: de === "browser" ? "en-US" : n,
|
|
6723
6723
|
ttsVoice: s || oe.defaultVoice,
|
|
6724
6724
|
lipsyncLang: "en",
|
|
6725
6725
|
showFullAvatar: a,
|
|
@@ -6728,29 +6728,29 @@ const Pe = Ie(({
|
|
|
6728
6728
|
}, J = {
|
|
6729
6729
|
ttsEndpoint: oe.endpoint,
|
|
6730
6730
|
ttsApikey: oe.apiKey,
|
|
6731
|
-
ttsService:
|
|
6731
|
+
ttsService: de,
|
|
6732
6732
|
lipsyncModules: ["en"],
|
|
6733
6733
|
cameraView: h
|
|
6734
|
-
}, b =
|
|
6734
|
+
}, b = E(async () => {
|
|
6735
6735
|
if (!(!D.current || p.current))
|
|
6736
6736
|
try {
|
|
6737
|
-
if (
|
|
6738
|
-
if (
|
|
6739
|
-
const
|
|
6740
|
-
c(
|
|
6737
|
+
if (le(!0), N(null), p.current = new Fe(D.current, J), p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1), x && Object.keys(x).length > 0 && (p.current.customAnimations = x), await p.current.showAvatar(me, (G) => {
|
|
6738
|
+
if (G.lengthComputable) {
|
|
6739
|
+
const M = Math.min(100, Math.round(G.loaded / G.total * 100));
|
|
6740
|
+
c(M);
|
|
6741
6741
|
}
|
|
6742
|
-
}), await new Promise((
|
|
6743
|
-
const
|
|
6744
|
-
p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ?
|
|
6742
|
+
}), await new Promise((G) => {
|
|
6743
|
+
const M = () => {
|
|
6744
|
+
p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? G() : setTimeout(M, 100);
|
|
6745
6745
|
};
|
|
6746
|
-
|
|
6746
|
+
M();
|
|
6747
6747
|
}), p.current && p.current.setShowFullAvatar)
|
|
6748
6748
|
try {
|
|
6749
6749
|
p.current.setShowFullAvatar(a);
|
|
6750
|
-
} catch (
|
|
6751
|
-
console.warn("Error setting full body mode on initialization:",
|
|
6750
|
+
} catch (G) {
|
|
6751
|
+
console.warn("Error setting full body mode on initialization:", G);
|
|
6752
6752
|
}
|
|
6753
|
-
p.current && p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1, p.current.controls.update()),
|
|
6753
|
+
p.current && p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1, p.current.controls.update()), le(!1), Y(!0), r(p.current);
|
|
6754
6754
|
const B = () => {
|
|
6755
6755
|
document.visibilityState === "visible" ? p.current?.start() : p.current?.stop();
|
|
6756
6756
|
};
|
|
@@ -6758,15 +6758,15 @@ const Pe = Ie(({
|
|
|
6758
6758
|
document.removeEventListener("visibilitychange", B);
|
|
6759
6759
|
};
|
|
6760
6760
|
} catch (L) {
|
|
6761
|
-
console.error("Error initializing TalkingHead:", L), N(L.message || "Failed to initialize avatar"),
|
|
6761
|
+
console.error("Error initializing TalkingHead:", L), N(L.message || "Failed to initialize avatar"), le(!1), d(L);
|
|
6762
6762
|
}
|
|
6763
6763
|
}, [O, t, e, n, i, s, o, a, l, u, h]);
|
|
6764
|
-
|
|
6764
|
+
ge(() => (b(), () => {
|
|
6765
6765
|
p.current && (p.current.stop(), p.current.dispose(), p.current = null);
|
|
6766
|
-
}), [b]),
|
|
6766
|
+
}), [b]), ge(() => {
|
|
6767
6767
|
if (!D.current || !p.current) return;
|
|
6768
|
-
const L = new ResizeObserver((
|
|
6769
|
-
for (const
|
|
6768
|
+
const L = new ResizeObserver((G) => {
|
|
6769
|
+
for (const M of G)
|
|
6770
6770
|
p.current && p.current.onResize && p.current.onResize();
|
|
6771
6771
|
});
|
|
6772
6772
|
L.observe(D.current);
|
|
@@ -6776,32 +6776,32 @@ const Pe = Ie(({
|
|
|
6776
6776
|
return window.addEventListener("resize", B), () => {
|
|
6777
6777
|
L.disconnect(), window.removeEventListener("resize", B);
|
|
6778
6778
|
};
|
|
6779
|
-
}, [
|
|
6780
|
-
const v =
|
|
6779
|
+
}, [X]);
|
|
6780
|
+
const v = E(async () => {
|
|
6781
6781
|
if (p.current && p.current.audioCtx)
|
|
6782
6782
|
try {
|
|
6783
6783
|
(p.current.audioCtx.state === "suspended" || p.current.audioCtx.state === "interrupted") && (await p.current.audioCtx.resume(), console.log("Audio context resumed"));
|
|
6784
6784
|
} catch (L) {
|
|
6785
6785
|
console.warn("Failed to resume audio context:", L);
|
|
6786
6786
|
}
|
|
6787
|
-
}, []), w =
|
|
6788
|
-
if (p.current &&
|
|
6787
|
+
}, []), w = E(async (L, B = {}) => {
|
|
6788
|
+
if (p.current && X)
|
|
6789
6789
|
try {
|
|
6790
|
-
R.current && (clearInterval(R.current), R.current = null), z.current = { text: L, options: B }, P.current = { remainingText: null, originalText: null, options: null },
|
|
6791
|
-
const
|
|
6790
|
+
R.current && (clearInterval(R.current), R.current = null), z.current = { text: L, options: B }, P.current = { remainingText: null, originalText: null, options: null }, _(!1), T.current = !1, await v();
|
|
6791
|
+
const G = {
|
|
6792
6792
|
...B,
|
|
6793
|
-
lipsyncLang: B.lipsyncLang ||
|
|
6793
|
+
lipsyncLang: B.lipsyncLang || me.lipsyncLang || "en"
|
|
6794
6794
|
};
|
|
6795
6795
|
if (B.onSpeechEnd && p.current) {
|
|
6796
|
-
const
|
|
6797
|
-
let
|
|
6796
|
+
const M = p.current;
|
|
6797
|
+
let U = null, se = 0;
|
|
6798
6798
|
const ke = 1200;
|
|
6799
6799
|
let xe = !1;
|
|
6800
|
-
|
|
6801
|
-
if (
|
|
6800
|
+
U = setInterval(() => {
|
|
6801
|
+
if (se++, T.current)
|
|
6802
6802
|
return;
|
|
6803
|
-
if (
|
|
6804
|
-
if (
|
|
6803
|
+
if (se > ke) {
|
|
6804
|
+
if (U && (clearInterval(U), U = null, R.current = null), !xe && !T.current) {
|
|
6805
6805
|
xe = !0;
|
|
6806
6806
|
try {
|
|
6807
6807
|
B.onSpeechEnd();
|
|
@@ -6811,10 +6811,10 @@ const Pe = Ie(({
|
|
|
6811
6811
|
}
|
|
6812
6812
|
return;
|
|
6813
6813
|
}
|
|
6814
|
-
const Oe = !
|
|
6815
|
-
|
|
6816
|
-
if (
|
|
6817
|
-
xe = !0,
|
|
6814
|
+
const Oe = !M.speechQueue || M.speechQueue.length === 0, Ne = !M.audioPlaylist || M.audioPlaylist.length === 0;
|
|
6815
|
+
M && M.isSpeaking === !1 && Oe && Ne && M.isAudioPlaying === !1 && !xe && !T.current && setTimeout(() => {
|
|
6816
|
+
if (M && !T.current && M.isSpeaking === !1 && (!M.speechQueue || M.speechQueue.length === 0) && (!M.audioPlaylist || M.audioPlaylist.length === 0) && M.isAudioPlaying === !1 && !xe && !T.current) {
|
|
6817
|
+
xe = !0, U && (clearInterval(U), U = null, R.current = null);
|
|
6818
6818
|
try {
|
|
6819
6819
|
B.onSpeechEnd();
|
|
6820
6820
|
} catch (Ue) {
|
|
@@ -6822,92 +6822,98 @@ const Pe = Ie(({
|
|
|
6822
6822
|
}
|
|
6823
6823
|
}
|
|
6824
6824
|
}, 100);
|
|
6825
|
-
}, 100), R.current =
|
|
6825
|
+
}, 100), R.current = U;
|
|
6826
6826
|
}
|
|
6827
|
-
p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L,
|
|
6828
|
-
await v(), p.current && p.current.lipsync && (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L,
|
|
6827
|
+
p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L, G)) : setTimeout(async () => {
|
|
6828
|
+
await v(), p.current && p.current.lipsync && (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L, G));
|
|
6829
6829
|
}, 100);
|
|
6830
|
-
} catch (
|
|
6831
|
-
console.error("Error speaking text:",
|
|
6830
|
+
} catch (G) {
|
|
6831
|
+
console.error("Error speaking text:", G), N(G.message || "Failed to speak text");
|
|
6832
6832
|
}
|
|
6833
|
-
}, [
|
|
6834
|
-
p.current && (p.current.stopSpeaking(), p.current.setSlowdownRate && p.current.setSlowdownRate(1), z.current = null,
|
|
6835
|
-
}, []), V =
|
|
6833
|
+
}, [X, v, me.lipsyncLang]), C = E(() => {
|
|
6834
|
+
p.current && (p.current.stopSpeaking(), p.current.setSlowdownRate && p.current.setSlowdownRate(1), z.current = null, _(!1));
|
|
6835
|
+
}, []), V = E(() => {
|
|
6836
6836
|
if (p.current && p.current.pauseSpeaking) {
|
|
6837
6837
|
const L = p.current;
|
|
6838
6838
|
if (L.isSpeaking || L.audioPlaylist && L.audioPlaylist.length > 0 || L.speechQueue && L.speechQueue.length > 0) {
|
|
6839
6839
|
R.current && (clearInterval(R.current), R.current = null);
|
|
6840
|
-
let
|
|
6841
|
-
if (L.speechQueue && L.speechQueue.length > 0) {
|
|
6842
|
-
const
|
|
6843
|
-
|
|
6840
|
+
let G = "";
|
|
6841
|
+
if (L.speechQueue && L.speechQueue.length > 0 && z.current) {
|
|
6842
|
+
const M = L.speechQueue.filter((U) => U && U.text && Array.isArray(U.text) && U.text.length > 0).map((U) => U.text.map((se) => se.word || "").filter((se) => se.length > 0).join(" ")).filter((U) => U.length > 0).join(" ");
|
|
6843
|
+
M && M.trim() && (G = M.trim());
|
|
6844
6844
|
}
|
|
6845
|
-
|
|
6846
|
-
remainingText:
|
|
6845
|
+
z.current && (P.current = {
|
|
6846
|
+
remainingText: G || null,
|
|
6847
6847
|
originalText: z.current.text,
|
|
6848
6848
|
options: z.current.options
|
|
6849
|
-
}), L.speechQueue && (L.speechQueue.length = 0), p.current.pauseSpeaking(),
|
|
6849
|
+
}), L.speechQueue && (L.speechQueue.length = 0), p.current.pauseSpeaking(), T.current = !0, _(!0);
|
|
6850
6850
|
}
|
|
6851
6851
|
}
|
|
6852
|
-
}, []), ne =
|
|
6853
|
-
if (p.current
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
...B,
|
|
6864
|
-
lipsyncLang: B.lipsyncLang || pe.lipsyncLang || "en"
|
|
6865
|
-
};
|
|
6866
|
-
p.current.lipsync && Object.keys(p.current.lipsync).length > 0 && (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), await w(L, U));
|
|
6852
|
+
}, []), ne = E(async () => {
|
|
6853
|
+
if (!p.current || !j)
|
|
6854
|
+
return;
|
|
6855
|
+
let L = "", B = {};
|
|
6856
|
+
if (P.current && P.current.remainingText)
|
|
6857
|
+
L = P.current.remainingText, B = P.current.options || {}, P.current = { remainingText: null, originalText: null, options: null };
|
|
6858
|
+
else if (z.current && z.current.text)
|
|
6859
|
+
L = z.current.text, B = z.current.options || {};
|
|
6860
|
+
else {
|
|
6861
|
+
console.warn("Resume called but no paused speech found"), _(!1), T.current = !1;
|
|
6862
|
+
return;
|
|
6867
6863
|
}
|
|
6868
|
-
|
|
6864
|
+
_(!1), T.current = !1, await v();
|
|
6865
|
+
const G = {
|
|
6866
|
+
...B,
|
|
6867
|
+
lipsyncLang: B.lipsyncLang || me.lipsyncLang || "en"
|
|
6868
|
+
};
|
|
6869
|
+
try {
|
|
6870
|
+
await w(L, G);
|
|
6871
|
+
} catch (M) {
|
|
6872
|
+
console.error("Error resuming speech:", M), _(!1), T.current = !1;
|
|
6873
|
+
}
|
|
6874
|
+
}, [v, j, w, me]), ie = E((L) => {
|
|
6869
6875
|
p.current && p.current.setMood(L);
|
|
6870
|
-
}, []), fe =
|
|
6876
|
+
}, []), fe = E((L) => {
|
|
6871
6877
|
p.current && p.current.setSlowdownRate && p.current.setSlowdownRate(L);
|
|
6872
|
-
}, []), Se =
|
|
6878
|
+
}, []), Se = E((L, B = !1) => {
|
|
6873
6879
|
if (p.current && p.current.playAnimation) {
|
|
6874
6880
|
if (x && x[L] && (L = x[L]), p.current.setShowFullAvatar)
|
|
6875
6881
|
try {
|
|
6876
6882
|
p.current.setShowFullAvatar(H.current);
|
|
6877
|
-
} catch (
|
|
6878
|
-
console.warn("Error setting full body mode:",
|
|
6883
|
+
} catch (M) {
|
|
6884
|
+
console.warn("Error setting full body mode:", M);
|
|
6879
6885
|
}
|
|
6880
6886
|
if (L.includes("."))
|
|
6881
6887
|
try {
|
|
6882
6888
|
p.current.playAnimation(L, null, 10, 0, 0.01, B);
|
|
6883
|
-
} catch (
|
|
6884
|
-
console.warn(`Failed to play ${L}:`,
|
|
6889
|
+
} catch (M) {
|
|
6890
|
+
console.warn(`Failed to play ${L}:`, M);
|
|
6885
6891
|
try {
|
|
6886
6892
|
p.current.setBodyMovement("idle");
|
|
6887
|
-
} catch (
|
|
6888
|
-
console.warn("Fallback animation also failed:",
|
|
6893
|
+
} catch (U) {
|
|
6894
|
+
console.warn("Fallback animation also failed:", U);
|
|
6889
6895
|
}
|
|
6890
6896
|
}
|
|
6891
6897
|
else {
|
|
6892
|
-
const
|
|
6893
|
-
let
|
|
6894
|
-
for (const
|
|
6898
|
+
const M = [".fbx", ".glb", ".gltf"];
|
|
6899
|
+
let U = !1;
|
|
6900
|
+
for (const se of M)
|
|
6895
6901
|
try {
|
|
6896
|
-
p.current.playAnimation(L +
|
|
6902
|
+
p.current.playAnimation(L + se, null, 10, 0, 0.01, B), U = !0;
|
|
6897
6903
|
break;
|
|
6898
6904
|
} catch {
|
|
6899
6905
|
}
|
|
6900
|
-
if (!
|
|
6906
|
+
if (!U) {
|
|
6901
6907
|
console.warn("Animation not found:", L);
|
|
6902
6908
|
try {
|
|
6903
6909
|
p.current.setBodyMovement("idle");
|
|
6904
|
-
} catch (
|
|
6905
|
-
console.warn("Fallback animation also failed:",
|
|
6910
|
+
} catch (se) {
|
|
6911
|
+
console.warn("Fallback animation also failed:", se);
|
|
6906
6912
|
}
|
|
6907
6913
|
}
|
|
6908
6914
|
}
|
|
6909
6915
|
}
|
|
6910
|
-
}, [x]), De =
|
|
6916
|
+
}, [x]), De = E(() => {
|
|
6911
6917
|
p.current && p.current.onResize && p.current.onResize();
|
|
6912
6918
|
}, []);
|
|
6913
6919
|
return Le(I, () => ({
|
|
@@ -6919,7 +6925,7 @@ const Pe = Ie(({
|
|
|
6919
6925
|
setMood: ie,
|
|
6920
6926
|
setTimingAdjustment: fe,
|
|
6921
6927
|
playAnimation: Se,
|
|
6922
|
-
isReady:
|
|
6928
|
+
isReady: X,
|
|
6923
6929
|
isPaused: j,
|
|
6924
6930
|
talkingHead: p.current,
|
|
6925
6931
|
handleResize: De,
|
|
@@ -6991,7 +6997,7 @@ const Pe = Ie(({
|
|
|
6991
6997
|
...y
|
|
6992
6998
|
},
|
|
6993
6999
|
children: [
|
|
6994
|
-
/* @__PURE__ */
|
|
7000
|
+
/* @__PURE__ */ ce(
|
|
6995
7001
|
"div",
|
|
6996
7002
|
{
|
|
6997
7003
|
ref: D,
|
|
@@ -7003,7 +7009,7 @@ const Pe = Ie(({
|
|
|
7003
7009
|
}
|
|
7004
7010
|
}
|
|
7005
7011
|
),
|
|
7006
|
-
ee && /* @__PURE__ */
|
|
7012
|
+
ee && /* @__PURE__ */ ce("div", { className: "loading-overlay", style: {
|
|
7007
7013
|
position: "absolute",
|
|
7008
7014
|
top: "50%",
|
|
7009
7015
|
left: "50%",
|
|
@@ -7012,7 +7018,7 @@ const Pe = Ie(({
|
|
|
7012
7018
|
fontSize: "18px",
|
|
7013
7019
|
zIndex: 10
|
|
7014
7020
|
}, children: "Loading avatar..." }),
|
|
7015
|
-
S && /* @__PURE__ */
|
|
7021
|
+
S && /* @__PURE__ */ ce("div", { className: "error-overlay", style: {
|
|
7016
7022
|
position: "absolute",
|
|
7017
7023
|
top: "50%",
|
|
7018
7024
|
left: "50%",
|
|
@@ -7041,7 +7047,7 @@ const ut = Ie(({
|
|
|
7041
7047
|
style: s = {},
|
|
7042
7048
|
avatarConfig: o = {}
|
|
7043
7049
|
}, l) => {
|
|
7044
|
-
const u =
|
|
7050
|
+
const u = Z(null), a = Z(null), [h, r] = pe(!0), [c, d] = pe(null), [g, y] = pe(!1), x = Ae(), I = o.ttsService || x.service, D = I === "browser" ? {
|
|
7045
7051
|
endpoint: "",
|
|
7046
7052
|
apiKey: null,
|
|
7047
7053
|
defaultVoice: "Google US English"
|
|
@@ -7071,30 +7077,30 @@ const ut = Ie(({
|
|
|
7071
7077
|
ttsService: I,
|
|
7072
7078
|
lipsyncModules: ["en"],
|
|
7073
7079
|
cameraView: "upper"
|
|
7074
|
-
}, z =
|
|
7080
|
+
}, z = E(async () => {
|
|
7075
7081
|
if (!(!u.current || a.current))
|
|
7076
7082
|
try {
|
|
7077
|
-
if (r(!0), d(null), a.current = new Fe(u.current, H), await a.current.showAvatar(p, (
|
|
7078
|
-
if (
|
|
7079
|
-
const
|
|
7080
|
-
t(
|
|
7083
|
+
if (r(!0), d(null), a.current = new Fe(u.current, H), await a.current.showAvatar(p, (X) => {
|
|
7084
|
+
if (X.lengthComputable) {
|
|
7085
|
+
const Y = Math.min(100, Math.round(X.loaded / X.total * 100));
|
|
7086
|
+
t(Y);
|
|
7081
7087
|
}
|
|
7082
7088
|
}), a.current.morphs && a.current.morphs.length > 0) {
|
|
7083
|
-
const
|
|
7084
|
-
console.log("Available morph targets:", Object.keys(
|
|
7085
|
-
const
|
|
7086
|
-
console.log("Viseme morph targets found:",
|
|
7089
|
+
const X = a.current.morphs[0].morphTargetDictionary;
|
|
7090
|
+
console.log("Available morph targets:", Object.keys(X));
|
|
7091
|
+
const Y = Object.keys(X).filter((j) => j.startsWith("viseme_"));
|
|
7092
|
+
console.log("Viseme morph targets found:", Y), Y.length === 0 && (console.warn("No viseme morph targets found! Lip-sync will not work properly."), console.log("Expected viseme targets: viseme_aa, viseme_E, viseme_I, viseme_O, viseme_U, viseme_PP, viseme_SS, viseme_TH, viseme_DD, viseme_FF, viseme_kk, viseme_nn, viseme_RR, viseme_CH, viseme_sil"));
|
|
7087
7093
|
}
|
|
7088
|
-
if (await new Promise((
|
|
7089
|
-
const
|
|
7090
|
-
a.current.lipsync && Object.keys(a.current.lipsync).length > 0 ? (console.log("Lip-sync modules loaded:", Object.keys(a.current.lipsync)),
|
|
7094
|
+
if (await new Promise((X) => {
|
|
7095
|
+
const Y = () => {
|
|
7096
|
+
a.current.lipsync && Object.keys(a.current.lipsync).length > 0 ? (console.log("Lip-sync modules loaded:", Object.keys(a.current.lipsync)), X()) : (console.log("Waiting for lip-sync modules to load..."), setTimeout(Y, 100));
|
|
7091
7097
|
};
|
|
7092
|
-
|
|
7098
|
+
Y();
|
|
7093
7099
|
}), a.current && a.current.setShowFullAvatar)
|
|
7094
7100
|
try {
|
|
7095
7101
|
a.current.setShowFullAvatar(!0), console.log("Avatar initialized in full body mode");
|
|
7096
|
-
} catch (
|
|
7097
|
-
console.warn("Error setting full body mode on initialization:",
|
|
7102
|
+
} catch (X) {
|
|
7103
|
+
console.warn("Error setting full body mode on initialization:", X);
|
|
7098
7104
|
}
|
|
7099
7105
|
r(!1), y(!0), n(a.current);
|
|
7100
7106
|
const N = () => {
|
|
@@ -7107,10 +7113,10 @@ const ut = Ie(({
|
|
|
7107
7113
|
console.error("Error initializing TalkingHead:", S), d(S.message || "Failed to initialize avatar"), r(!1), e(S);
|
|
7108
7114
|
}
|
|
7109
7115
|
}, []);
|
|
7110
|
-
|
|
7116
|
+
ge(() => (z(), () => {
|
|
7111
7117
|
a.current && (a.current.stop(), a.current.dispose(), a.current = null);
|
|
7112
7118
|
}), [z]);
|
|
7113
|
-
const R =
|
|
7119
|
+
const R = E((S) => {
|
|
7114
7120
|
if (a.current && g)
|
|
7115
7121
|
try {
|
|
7116
7122
|
console.log("Speaking text:", S), console.log("Avatar config:", p), console.log("TalkingHead instance:", a.current), a.current.lipsync && Object.keys(a.current.lipsync).length > 0 ? (console.log("Lip-sync modules loaded:", Object.keys(a.current.lipsync)), a.current.setSlowdownRate && (a.current.setSlowdownRate(1.05), console.log("Applied timing adjustment for better lip-sync")), a.current.speakText(S)) : (console.warn("Lip-sync modules not ready, waiting..."), setTimeout(() => {
|
|
@@ -7121,25 +7127,25 @@ const ut = Ie(({
|
|
|
7121
7127
|
}
|
|
7122
7128
|
else
|
|
7123
7129
|
console.warn("Avatar not ready for speaking. isReady:", g, "talkingHeadRef:", !!a.current);
|
|
7124
|
-
}, [g, p]),
|
|
7130
|
+
}, [g, p]), T = E(() => {
|
|
7125
7131
|
a.current && (a.current.stopSpeaking(), a.current.setSlowdownRate && (a.current.setSlowdownRate(1), console.log("Reset timing to normal")));
|
|
7126
|
-
}, []), P =
|
|
7132
|
+
}, []), P = E((S) => {
|
|
7127
7133
|
a.current && a.current.setMood(S);
|
|
7128
|
-
}, []), ee =
|
|
7134
|
+
}, []), ee = E((S) => {
|
|
7129
7135
|
a.current && a.current.setSlowdownRate && (a.current.setSlowdownRate(S), console.log("Timing adjustment set to:", S));
|
|
7130
|
-
}, []),
|
|
7136
|
+
}, []), le = E((S, N = !1) => {
|
|
7131
7137
|
if (a.current && a.current.playAnimation) {
|
|
7132
7138
|
if (a.current.setShowFullAvatar)
|
|
7133
7139
|
try {
|
|
7134
7140
|
a.current.setShowFullAvatar(!0);
|
|
7135
|
-
} catch (
|
|
7136
|
-
console.warn("Error setting full body mode:",
|
|
7141
|
+
} catch (Y) {
|
|
7142
|
+
console.warn("Error setting full body mode:", Y);
|
|
7137
7143
|
}
|
|
7138
7144
|
if (S.includes("."))
|
|
7139
7145
|
try {
|
|
7140
7146
|
a.current.playAnimation(S, null, 10, 0, 0.01, N), console.log("Playing animation:", S);
|
|
7141
|
-
} catch (
|
|
7142
|
-
console.log(`Failed to play ${S}:`,
|
|
7147
|
+
} catch (Y) {
|
|
7148
|
+
console.log(`Failed to play ${S}:`, Y);
|
|
7143
7149
|
try {
|
|
7144
7150
|
a.current.setBodyMovement("idle"), console.log("Fallback to idle animation");
|
|
7145
7151
|
} catch (j) {
|
|
@@ -7147,21 +7153,21 @@ const ut = Ie(({
|
|
|
7147
7153
|
}
|
|
7148
7154
|
}
|
|
7149
7155
|
else {
|
|
7150
|
-
const
|
|
7156
|
+
const Y = [".fbx", ".glb", ".gltf"];
|
|
7151
7157
|
let j = !1;
|
|
7152
|
-
for (const
|
|
7158
|
+
for (const _ of Y)
|
|
7153
7159
|
try {
|
|
7154
|
-
a.current.playAnimation(S +
|
|
7160
|
+
a.current.playAnimation(S + _, null, 10, 0, 0.01, N), console.log("Playing animation:", S + _), j = !0;
|
|
7155
7161
|
break;
|
|
7156
7162
|
} catch {
|
|
7157
|
-
console.log(`Failed to play ${S}${
|
|
7163
|
+
console.log(`Failed to play ${S}${_}, trying next format...`);
|
|
7158
7164
|
}
|
|
7159
7165
|
if (!j) {
|
|
7160
7166
|
console.warn("Animation system not available or animation not found:", S);
|
|
7161
7167
|
try {
|
|
7162
7168
|
a.current.setBodyMovement("idle"), console.log("Fallback to idle animation");
|
|
7163
|
-
} catch (
|
|
7164
|
-
console.warn("Fallback animation also failed:",
|
|
7169
|
+
} catch (_) {
|
|
7170
|
+
console.warn("Fallback animation also failed:", _);
|
|
7165
7171
|
}
|
|
7166
7172
|
}
|
|
7167
7173
|
}
|
|
@@ -7170,10 +7176,10 @@ const ut = Ie(({
|
|
|
7170
7176
|
}, []);
|
|
7171
7177
|
return Le(l, () => ({
|
|
7172
7178
|
speakText: R,
|
|
7173
|
-
stopSpeaking:
|
|
7179
|
+
stopSpeaking: T,
|
|
7174
7180
|
setMood: P,
|
|
7175
7181
|
setTimingAdjustment: ee,
|
|
7176
|
-
playAnimation:
|
|
7182
|
+
playAnimation: le,
|
|
7177
7183
|
isReady: g,
|
|
7178
7184
|
talkingHead: a.current,
|
|
7179
7185
|
setBodyMovement: (S) => {
|
|
@@ -7234,7 +7240,7 @@ const ut = Ie(({
|
|
|
7234
7240
|
}
|
|
7235
7241
|
}
|
|
7236
7242
|
})), /* @__PURE__ */ Ee("div", { className: `talking-head-container ${i}`, style: s, children: [
|
|
7237
|
-
/* @__PURE__ */
|
|
7243
|
+
/* @__PURE__ */ ce(
|
|
7238
7244
|
"div",
|
|
7239
7245
|
{
|
|
7240
7246
|
ref: u,
|
|
@@ -7246,7 +7252,7 @@ const ut = Ie(({
|
|
|
7246
7252
|
}
|
|
7247
7253
|
}
|
|
7248
7254
|
),
|
|
7249
|
-
h && /* @__PURE__ */
|
|
7255
|
+
h && /* @__PURE__ */ ce("div", { className: "loading-overlay", style: {
|
|
7250
7256
|
position: "absolute",
|
|
7251
7257
|
top: "50%",
|
|
7252
7258
|
left: "50%",
|
|
@@ -7255,7 +7261,7 @@ const ut = Ie(({
|
|
|
7255
7261
|
fontSize: "18px",
|
|
7256
7262
|
zIndex: 10
|
|
7257
7263
|
}, children: "Loading avatar..." }),
|
|
7258
|
-
c && /* @__PURE__ */
|
|
7264
|
+
c && /* @__PURE__ */ ce("div", { className: "error-overlay", style: {
|
|
7259
7265
|
position: "absolute",
|
|
7260
7266
|
top: "50%",
|
|
7261
7267
|
left: "50%",
|
|
@@ -7286,7 +7292,7 @@ const ct = Ie(({
|
|
|
7286
7292
|
},
|
|
7287
7293
|
autoStart: u = !1
|
|
7288
7294
|
}, a) => {
|
|
7289
|
-
const h =
|
|
7295
|
+
const h = Z(null), r = Z({
|
|
7290
7296
|
currentModuleIndex: 0,
|
|
7291
7297
|
currentLessonIndex: 0,
|
|
7292
7298
|
currentQuestionIndex: 0,
|
|
@@ -7296,18 +7302,18 @@ const ct = Ie(({
|
|
|
7296
7302
|
curriculumCompleted: !1,
|
|
7297
7303
|
score: 0,
|
|
7298
7304
|
totalQuestions: 0
|
|
7299
|
-
}), c =
|
|
7305
|
+
}), c = Z({
|
|
7300
7306
|
onLessonStart: n,
|
|
7301
7307
|
onLessonComplete: i,
|
|
7302
7308
|
onQuestionAnswer: s,
|
|
7303
7309
|
onCurriculumComplete: o,
|
|
7304
7310
|
onCustomAction: l
|
|
7305
|
-
}), d =
|
|
7311
|
+
}), d = Z(null), g = Z(null), y = Z(null), x = Z(null), I = Z(null), D = Z(null), p = Z(null), H = Z(O?.curriculum || {
|
|
7306
7312
|
title: "Default Curriculum",
|
|
7307
7313
|
description: "No curriculum data provided",
|
|
7308
7314
|
language: "en",
|
|
7309
7315
|
modules: []
|
|
7310
|
-
}), z =
|
|
7316
|
+
}), z = Z({
|
|
7311
7317
|
avatarUrl: t.avatarUrl || "/avatars/brunette.glb",
|
|
7312
7318
|
avatarBody: t.avatarBody || "F",
|
|
7313
7319
|
mood: t.mood || "happy",
|
|
@@ -7321,7 +7327,7 @@ const ct = Ie(({
|
|
|
7321
7327
|
animations: e,
|
|
7322
7328
|
lipsyncLang: "en"
|
|
7323
7329
|
});
|
|
7324
|
-
|
|
7330
|
+
ge(() => {
|
|
7325
7331
|
c.current = {
|
|
7326
7332
|
onLessonStart: n,
|
|
7327
7333
|
onLessonComplete: i,
|
|
@@ -7329,7 +7335,7 @@ const ct = Ie(({
|
|
|
7329
7335
|
onCurriculumComplete: o,
|
|
7330
7336
|
onCustomAction: l
|
|
7331
7337
|
};
|
|
7332
|
-
}, [n, i, s, o, l]),
|
|
7338
|
+
}, [n, i, s, o, l]), ge(() => {
|
|
7333
7339
|
H.current = O?.curriculum || {
|
|
7334
7340
|
title: "Default Curriculum",
|
|
7335
7341
|
description: "No curriculum data provided",
|
|
@@ -7350,7 +7356,7 @@ const ct = Ie(({
|
|
|
7350
7356
|
lipsyncLang: "en"
|
|
7351
7357
|
};
|
|
7352
7358
|
}, [O, t, e]);
|
|
7353
|
-
const R =
|
|
7359
|
+
const R = E(() => (H.current || { modules: [] }).modules[r.current.currentModuleIndex]?.lessons[r.current.currentLessonIndex], []), T = E(() => R()?.questions[r.current.currentQuestionIndex], [R]), P = E((b, v) => v.type === "multiple_choice" || v.type === "true_false" ? b === v.answer : v.type === "code_test" && typeof b == "object" && b !== null ? b.passed === !0 : !1, []), ee = E(() => {
|
|
7354
7360
|
r.current.lessonCompleted = !0, r.current.isQuestionMode = !1;
|
|
7355
7361
|
const b = r.current.totalQuestions > 0 ? Math.round(r.current.score / r.current.totalQuestions * 100) : 100;
|
|
7356
7362
|
let v = "Congratulations! You've completed this lesson";
|
|
@@ -7390,7 +7396,7 @@ const ct = Ie(({
|
|
|
7390
7396
|
}
|
|
7391
7397
|
});
|
|
7392
7398
|
}
|
|
7393
|
-
}, [e.lessonComplete]),
|
|
7399
|
+
}, [e.lessonComplete]), le = E(() => {
|
|
7394
7400
|
r.current.curriculumCompleted = !0;
|
|
7395
7401
|
const b = H.current || { modules: [] };
|
|
7396
7402
|
if (c.current.onCurriculumComplete({
|
|
@@ -7406,10 +7412,10 @@ const ct = Ie(({
|
|
|
7406
7412
|
const v = z.current || { lipsyncLang: "en" };
|
|
7407
7413
|
h.current.speakText("Amazing! You've completed the entire curriculum! You're now ready to move on to more advanced topics. Well done!", { lipsyncLang: v.lipsyncLang });
|
|
7408
7414
|
}
|
|
7409
|
-
}, [e.curriculumComplete]), S =
|
|
7415
|
+
}, [e.curriculumComplete]), S = E(() => {
|
|
7410
7416
|
const b = R();
|
|
7411
7417
|
r.current.isQuestionMode = !0, r.current.currentQuestionIndex = 0, r.current.totalQuestions = b?.questions?.length || 0, r.current.score = 0;
|
|
7412
|
-
const v =
|
|
7418
|
+
const v = T();
|
|
7413
7419
|
v && c.current.onCustomAction({
|
|
7414
7420
|
type: "questionStart",
|
|
7415
7421
|
moduleIndex: r.current.currentModuleIndex,
|
|
@@ -7443,11 +7449,11 @@ const ct = Ie(({
|
|
|
7443
7449
|
clearInterval(C);
|
|
7444
7450
|
}, 5e3);
|
|
7445
7451
|
}
|
|
7446
|
-
}, [e.questionStart, R,
|
|
7452
|
+
}, [e.questionStart, R, T]), N = E(() => {
|
|
7447
7453
|
const b = R();
|
|
7448
7454
|
if (r.current.currentQuestionIndex < (b?.questions?.length || 0) - 1) {
|
|
7449
7455
|
h.current && h.current.stopSpeaking && h.current.stopSpeaking(), r.current.currentQuestionIndex += 1;
|
|
7450
|
-
const v =
|
|
7456
|
+
const v = T();
|
|
7451
7457
|
v && c.current.onCustomAction({
|
|
7452
7458
|
type: "nextQuestion",
|
|
7453
7459
|
moduleIndex: r.current.currentModuleIndex,
|
|
@@ -7494,7 +7500,7 @@ const ct = Ie(({
|
|
|
7494
7500
|
totalQuestions: r.current.totalQuestions,
|
|
7495
7501
|
score: r.current.score
|
|
7496
7502
|
});
|
|
7497
|
-
}, [e.nextQuestion, R,
|
|
7503
|
+
}, [e.nextQuestion, R, T]), X = E(() => {
|
|
7498
7504
|
const b = H.current || { modules: [] }, v = b.modules[r.current.currentModuleIndex];
|
|
7499
7505
|
if (r.current.currentLessonIndex < (v?.lessons?.length || 0) - 1) {
|
|
7500
7506
|
r.current.currentLessonIndex += 1, r.current.currentQuestionIndex = 0, r.current.lessonCompleted = !1, r.current.isQuestionMode = !1, r.current.isTeaching = !1, r.current.score = 0, r.current.totalQuestions = 0;
|
|
@@ -7524,7 +7530,7 @@ const ct = Ie(({
|
|
|
7524
7530
|
}), h.current && (h.current.setMood("happy"), h.current.setBodyMovement("idle"));
|
|
7525
7531
|
} else
|
|
7526
7532
|
I.current && I.current();
|
|
7527
|
-
}, []),
|
|
7533
|
+
}, []), Y = E(() => {
|
|
7528
7534
|
const b = R();
|
|
7529
7535
|
let v = null;
|
|
7530
7536
|
if (b?.avatar_script && b?.body) {
|
|
@@ -7565,8 +7571,8 @@ const ct = Ie(({
|
|
|
7565
7571
|
}
|
|
7566
7572
|
});
|
|
7567
7573
|
}
|
|
7568
|
-
}, [e.teaching, R]), j =
|
|
7569
|
-
const v =
|
|
7574
|
+
}, [e.teaching, R]), j = E((b) => {
|
|
7575
|
+
const v = T(), w = P(b, v);
|
|
7570
7576
|
if (w && (r.current.score += 1), c.current.onQuestionAnswer({
|
|
7571
7577
|
moduleIndex: r.current.currentModuleIndex,
|
|
7572
7578
|
lessonIndex: r.current.currentLessonIndex,
|
|
@@ -7640,8 +7646,8 @@ const ct = Ie(({
|
|
|
7640
7646
|
avatarNotReady: !0
|
|
7641
7647
|
});
|
|
7642
7648
|
}
|
|
7643
|
-
}, [e.correct, e.incorrect,
|
|
7644
|
-
const v =
|
|
7649
|
+
}, [e.correct, e.incorrect, T, R, P]), _ = E((b) => {
|
|
7650
|
+
const v = T();
|
|
7645
7651
|
if (!b || typeof b != "object") {
|
|
7646
7652
|
console.error("Invalid code test result format. Expected object with {passed: boolean, ...}");
|
|
7647
7653
|
return;
|
|
@@ -7668,10 +7674,10 @@ const ct = Ie(({
|
|
|
7668
7674
|
testResult: w,
|
|
7669
7675
|
question: v
|
|
7670
7676
|
}), p.current && p.current(w);
|
|
7671
|
-
}, [
|
|
7677
|
+
}, [T, P]), te = E(() => {
|
|
7672
7678
|
if (r.current.currentQuestionIndex > 0) {
|
|
7673
7679
|
r.current.currentQuestionIndex -= 1;
|
|
7674
|
-
const b =
|
|
7680
|
+
const b = T();
|
|
7675
7681
|
b && c.current.onCustomAction({
|
|
7676
7682
|
type: "questionStart",
|
|
7677
7683
|
moduleIndex: r.current.currentModuleIndex,
|
|
@@ -7702,7 +7708,7 @@ const ct = Ie(({
|
|
|
7702
7708
|
}, 5e3);
|
|
7703
7709
|
}
|
|
7704
7710
|
}
|
|
7705
|
-
}, [
|
|
7711
|
+
}, [T]), de = E(() => {
|
|
7706
7712
|
const b = H.current || { modules: [] };
|
|
7707
7713
|
if (b.modules[r.current.currentModuleIndex], r.current.currentLessonIndex > 0)
|
|
7708
7714
|
r.current.currentLessonIndex -= 1, r.current.currentQuestionIndex = 0, r.current.lessonCompleted = !1, r.current.isQuestionMode = !1, r.current.isTeaching = !1, r.current.score = 0, r.current.totalQuestions = 0, c.current.onCustomAction({
|
|
@@ -7726,9 +7732,9 @@ const ct = Ie(({
|
|
|
7726
7732
|
lesson: R()
|
|
7727
7733
|
}), h.current && (h.current.setMood("happy"), h.current.setBodyMovement("idle"));
|
|
7728
7734
|
}
|
|
7729
|
-
}, [R]), oe =
|
|
7735
|
+
}, [R]), oe = E(() => {
|
|
7730
7736
|
r.current.currentModuleIndex = 0, r.current.currentLessonIndex = 0, r.current.currentQuestionIndex = 0, r.current.isTeaching = !1, r.current.isQuestionMode = !1, r.current.lessonCompleted = !1, r.current.curriculumCompleted = !1, r.current.score = 0, r.current.totalQuestions = 0;
|
|
7731
|
-
}, []),
|
|
7737
|
+
}, []), me = E((b) => {
|
|
7732
7738
|
console.log("Avatar is ready!", b);
|
|
7733
7739
|
const v = R(), w = v?.avatar_script || v?.body;
|
|
7734
7740
|
u && w && setTimeout(() => {
|
|
@@ -7736,22 +7742,22 @@ const ct = Ie(({
|
|
|
7736
7742
|
}, 10);
|
|
7737
7743
|
}, [u, R]);
|
|
7738
7744
|
We(() => {
|
|
7739
|
-
d.current =
|
|
7745
|
+
d.current = Y, g.current = X, y.current = ee, x.current = N, I.current = le, D.current = S, p.current = j;
|
|
7740
7746
|
}), Le(a, () => ({
|
|
7741
7747
|
// Curriculum control methods
|
|
7742
|
-
startTeaching:
|
|
7748
|
+
startTeaching: Y,
|
|
7743
7749
|
startQuestions: S,
|
|
7744
7750
|
handleAnswerSelect: j,
|
|
7745
|
-
handleCodeTestResult:
|
|
7751
|
+
handleCodeTestResult: _,
|
|
7746
7752
|
nextQuestion: N,
|
|
7747
7753
|
previousQuestion: te,
|
|
7748
|
-
nextLesson:
|
|
7749
|
-
previousLesson:
|
|
7754
|
+
nextLesson: X,
|
|
7755
|
+
previousLesson: de,
|
|
7750
7756
|
completeLesson: ee,
|
|
7751
|
-
completeCurriculum:
|
|
7757
|
+
completeCurriculum: le,
|
|
7752
7758
|
resetCurriculum: oe,
|
|
7753
7759
|
getState: () => ({ ...r.current }),
|
|
7754
|
-
getCurrentQuestion: () =>
|
|
7760
|
+
getCurrentQuestion: () => T(),
|
|
7755
7761
|
getCurrentLesson: () => R(),
|
|
7756
7762
|
// Direct access to avatar ref (always returns current value)
|
|
7757
7763
|
getAvatarRef: () => h.current,
|
|
@@ -7803,7 +7809,7 @@ const ct = Ie(({
|
|
|
7803
7809
|
handleResize: () => h.current?.handleResize(),
|
|
7804
7810
|
// Avatar readiness check (always returns current value)
|
|
7805
7811
|
isAvatarReady: () => h.current?.isReady || !1
|
|
7806
|
-
}), [
|
|
7812
|
+
}), [Y, S, j, _, N, X, ee, le, oe, T, R]);
|
|
7807
7813
|
const J = z.current || {
|
|
7808
7814
|
avatarUrl: "/avatars/brunette.glb",
|
|
7809
7815
|
avatarBody: "F",
|
|
@@ -7817,7 +7823,7 @@ const ct = Ie(({
|
|
|
7817
7823
|
showFullAvatar: !1,
|
|
7818
7824
|
animations: e
|
|
7819
7825
|
};
|
|
7820
|
-
return /* @__PURE__ */
|
|
7826
|
+
return /* @__PURE__ */ ce("div", { style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ ce(
|
|
7821
7827
|
Pe,
|
|
7822
7828
|
{
|
|
7823
7829
|
ref: h,
|
|
@@ -7833,7 +7839,7 @@ const ct = Ie(({
|
|
|
7833
7839
|
showFullAvatar: J.showFullAvatar,
|
|
7834
7840
|
cameraView: "upper",
|
|
7835
7841
|
animations: J.animations,
|
|
7836
|
-
onReady:
|
|
7842
|
+
onReady: me,
|
|
7837
7843
|
onLoading: () => {
|
|
7838
7844
|
},
|
|
7839
7845
|
onError: (b) => {
|