Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(speech): add positional audio connection and cleanup in ElevenLabsTTS

nirholas9871b7f86fc8
diff --git a/src/CLAUDE.md b/src/CLAUDE.md
index d290e309f..736005de9 100644
--- a/src/CLAUDE.md
+++ b/src/CLAUDE.md
@@ -101,10 +101,11 @@ Continuous weighted blend of `{ neutral, concern, celebration, patience, curiosi
| patience | 0.035 | ~20s |
| curiosity | 0.12 | ~6s |
| empathy | 0.055 | ~13s |
+| uncertain | 0.10 | ~7s |
### Stimulus rules (protocol → emotion)
-- `speak`: valence > 0.3 → celebration; < -0.2 → concern; arousal > 0.5 → curiosity
+- `speak`: valence > 0.3 → celebration; < -0.2 → concern; arousal > 0.5 → curiosity; hedge vocab → uncertain (capped 0.8)
- `skill-done`: `result.sentiment` > 0.3 → celebration; < -0.2 → concern
- `skill-error`: concern + empathy (scaled by error streak × 0.25)
- `load-start`: patience + curiosity
@@ -118,6 +119,7 @@ Continuous weighted blend of `{ neutral, concern, celebration, patience, curiosi
- empathy → eyeSquint 0.4, browInnerUp 0.5
- curiosity → browOuterUp 0.7/0.5
- patience → eyesClosed 0.15 (subtle)
+- uncertain → mouthPressLeft/Right 0.35, browInnerUp max(concern×0.6, uncertain×0.45, empathy×0.5); also scales idle hip-drift amplitude (base 0.018 rad + bias×0.025 rad)
### Head transform
diff --git a/src/agent-avatar.js b/src/agent-avatar.js
index b8a0c13b6..df713ce74 100644
--- a/src/agent-avatar.js
+++ b/src/agent-avatar.js
@@ -20,8 +20,9 @@
*/
import { ACTION_TYPES } from './agent-protocol.js';
-import { Vector3, Box3, MathUtils } from 'three';
+import { Vector3, Box3, MathUtils, PositionalAudio } from 'three';
import { resolveSlot, DEFAULT_ANIMATION_MAP } from './runtime/animation-slots.js';
+import { ElevenLabsTTS } from './runtime/speech.js';
// BEGIN:IDLE_LOOP_IMPORT
import { IdleAnimation } from './idle-animation.js';
// END:IDLE_LOOP_IMPORT
diff --git a/src/runtime/speech.js b/src/runtime/speech.js
index 4f01f4c5f..bb5617328 100644
--- a/src/runtime/speech.js
+++ b/src/runtime/speech.js
@@ -419,6 +419,7 @@ export class ElevenLabsTTS {
audio.addEventListener('playing', onStart, { once: true });
audio.addEventListener('ended', () => this._onEnd?.(), { once: true });
audio.addEventListener('error', () => onError?.(), { once: true });
+ this._connectPositionalAudio(audio);
await audio.play();
} catch (err) {
if (err.name !== 'AbortError') onError?.();
@@ -426,6 +427,10 @@ export class ElevenLabsTTS {
}
_cleanupAudio() {
+ if (this._positionalAudio?.source) {
+ try { this._positionalAudio.source.disconnect(); } catch {}
+ this._positionalAudio.source = null;
+ }
if (this._audio) {
try {
this._audio.pause();