@escapeaihq/client-core 0.49.1 → 0.138.0
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/README.md +445 -153
- package/dist/adapters/capabilities.d.ts +20 -3
- package/dist/adapters/capabilities.d.ts.map +1 -1
- package/dist/adapters/directorAdapter.d.ts +5 -4
- package/dist/adapters/directorAdapter.d.ts.map +1 -1
- package/dist/adapters/directorAdapter.js +5 -4
- package/dist/adapters/directorAdapter.js.map +1 -1
- package/dist/adapters/experienceModelCatalog.d.ts +382 -0
- package/dist/adapters/experienceModelCatalog.d.ts.map +1 -0
- package/dist/adapters/experienceModelCatalog.js +401 -0
- package/dist/adapters/experienceModelCatalog.js.map +1 -0
- package/dist/adapters/extractionAdapter.d.ts +81 -0
- package/dist/adapters/extractionAdapter.d.ts.map +1 -0
- package/dist/adapters/extractionAdapter.js +98 -0
- package/dist/adapters/extractionAdapter.js.map +1 -0
- package/dist/adapters/imageAdapter.d.ts +5 -1
- package/dist/adapters/imageAdapter.d.ts.map +1 -1
- package/dist/adapters/imageAdapter.js +5 -1
- package/dist/adapters/imageAdapter.js.map +1 -1
- package/dist/adapters/index.d.ts +54 -16
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +62 -11
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/momentDirective.d.ts +66 -0
- package/dist/adapters/momentDirective.d.ts.map +1 -0
- package/dist/adapters/momentDirective.js +78 -0
- package/dist/adapters/momentDirective.js.map +1 -0
- package/dist/adapters/momentPolicy.d.ts +132 -0
- package/dist/adapters/momentPolicy.d.ts.map +1 -0
- package/dist/adapters/momentPolicy.js +165 -0
- package/dist/adapters/momentPolicy.js.map +1 -0
- package/dist/adapters/registry.d.ts +1 -1
- package/dist/adapters/registry.d.ts.map +1 -1
- package/dist/adapters/videoGenAdapter.d.ts +55 -0
- package/dist/adapters/videoGenAdapter.d.ts.map +1 -0
- package/dist/adapters/videoGenAdapter.js +78 -0
- package/dist/adapters/videoGenAdapter.js.map +1 -0
- package/dist/adapters/worldAdapter.d.ts +132 -11
- package/dist/adapters/worldAdapter.d.ts.map +1 -1
- package/dist/adapters/worldAdapter.js +127 -11
- package/dist/adapters/worldAdapter.js.map +1 -1
- package/dist/adapters/worldModelPreference.d.ts +173 -0
- package/dist/adapters/worldModelPreference.d.ts.map +1 -0
- package/dist/adapters/worldModelPreference.js +209 -0
- package/dist/adapters/worldModelPreference.js.map +1 -0
- package/dist/adapters/worldModelTradeoffs.d.ts +120 -0
- package/dist/adapters/worldModelTradeoffs.d.ts.map +1 -0
- package/dist/adapters/worldModelTradeoffs.js +154 -0
- package/dist/adapters/worldModelTradeoffs.js.map +1 -0
- package/dist/admin.d.ts +545 -0
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +230 -16
- package/dist/admin.js.map +1 -1
- package/dist/api.d.ts +10281 -2216
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +4174 -1240
- package/dist/api.js.map +1 -1
- package/dist/arcBoardJoin.d.ts +38 -0
- package/dist/arcBoardJoin.d.ts.map +1 -0
- package/dist/arcBoardJoin.js +37 -0
- package/dist/arcBoardJoin.js.map +1 -0
- package/dist/arcPreview.d.ts +49 -0
- package/dist/arcPreview.d.ts.map +1 -0
- package/dist/arcPreview.js +65 -0
- package/dist/arcPreview.js.map +1 -0
- package/dist/audio.d.ts +259 -16
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +605 -114
- package/dist/audio.js.map +1 -1
- package/dist/audioDsp.d.ts +45 -0
- package/dist/audioDsp.d.ts.map +1 -0
- package/dist/audioDsp.js +108 -0
- package/dist/audioDsp.js.map +1 -0
- package/dist/audioProtocol.d.ts +160 -0
- package/dist/audioProtocol.d.ts.map +1 -1
- package/dist/audioProtocol.js +99 -0
- package/dist/audioProtocol.js.map +1 -1
- package/dist/beatTitles.d.ts +33 -0
- package/dist/beatTitles.d.ts.map +1 -0
- package/dist/beatTitles.js +39 -0
- package/dist/beatTitles.js.map +1 -0
- package/dist/castProjection.d.ts +204 -1
- package/dist/castProjection.d.ts.map +1 -1
- package/dist/castProjection.js +202 -0
- package/dist/castProjection.js.map +1 -1
- package/dist/characterGrounding.d.ts +369 -0
- package/dist/characterGrounding.d.ts.map +1 -0
- package/dist/characterGrounding.js +408 -0
- package/dist/characterGrounding.js.map +1 -0
- package/dist/conversation/binding.d.ts +41 -1
- package/dist/conversation/binding.d.ts.map +1 -1
- package/dist/conversation/binding.js +12 -0
- package/dist/conversation/binding.js.map +1 -1
- package/dist/conversation/chatSessionStore.d.ts +178 -0
- package/dist/conversation/chatSessionStore.d.ts.map +1 -0
- package/dist/conversation/chatSessionStore.js +196 -0
- package/dist/conversation/chatSessionStore.js.map +1 -0
- package/dist/conversation/controller.d.ts +60 -0
- package/dist/conversation/controller.d.ts.map +1 -1
- package/dist/conversation/controller.js +104 -3
- package/dist/conversation/controller.js.map +1 -1
- package/dist/conversation/index.d.ts +2 -0
- package/dist/conversation/index.d.ts.map +1 -1
- package/dist/conversation/index.js +2 -0
- package/dist/conversation/index.js.map +1 -1
- package/dist/conversation/participant.d.ts +16 -0
- package/dist/conversation/participant.d.ts.map +1 -1
- package/dist/conversation/readSequencer.d.ts +38 -0
- package/dist/conversation/readSequencer.d.ts.map +1 -0
- package/dist/conversation/readSequencer.js +42 -0
- package/dist/conversation/readSequencer.js.map +1 -0
- package/dist/conversation/roster.d.ts +5 -1
- package/dist/conversation/roster.d.ts.map +1 -1
- package/dist/conversation/roster.js.map +1 -1
- package/dist/conversation/rosterProjection.d.ts +74 -1
- package/dist/conversation/rosterProjection.d.ts.map +1 -1
- package/dist/conversation/rosterProjection.js +135 -1
- package/dist/conversation/rosterProjection.js.map +1 -1
- package/dist/conversation/runtime.d.ts +20 -3
- package/dist/conversation/runtime.d.ts.map +1 -1
- package/dist/conversation/runtime.js +66 -7
- package/dist/conversation/runtime.js.map +1 -1
- package/dist/conversation/types.d.ts +43 -4
- package/dist/conversation/types.d.ts.map +1 -1
- package/dist/conversation/voice.d.ts +290 -13
- package/dist/conversation/voice.d.ts.map +1 -1
- package/dist/conversation/voice.js +565 -42
- package/dist/conversation/voice.js.map +1 -1
- package/dist/creatorCuration.d.ts +134 -0
- package/dist/creatorCuration.d.ts.map +1 -0
- package/dist/creatorCuration.js +228 -0
- package/dist/creatorCuration.js.map +1 -0
- package/dist/creatorDashboard.d.ts +155 -0
- package/dist/creatorDashboard.d.ts.map +1 -0
- package/dist/creatorDashboard.js +237 -0
- package/dist/creatorDashboard.js.map +1 -0
- package/dist/creatorUniverse.d.ts +95 -0
- package/dist/creatorUniverse.d.ts.map +1 -0
- package/dist/creatorUniverse.js +136 -0
- package/dist/creatorUniverse.js.map +1 -0
- package/dist/curationWrite.d.ts +76 -0
- package/dist/curationWrite.d.ts.map +1 -0
- package/dist/curationWrite.js +106 -0
- package/dist/curationWrite.js.map +1 -0
- package/dist/designTokens.d.ts +64 -0
- package/dist/designTokens.d.ts.map +1 -0
- package/dist/designTokens.js +117 -0
- package/dist/designTokens.js.map +1 -0
- package/dist/dialogAttribution.d.ts +79 -0
- package/dist/dialogAttribution.d.ts.map +1 -0
- package/dist/dialogAttribution.js +144 -0
- package/dist/dialogAttribution.js.map +1 -0
- package/dist/dmRunWorldReadiness.d.ts +605 -0
- package/dist/dmRunWorldReadiness.d.ts.map +1 -0
- package/dist/dmRunWorldReadiness.js +775 -0
- package/dist/dmRunWorldReadiness.js.map +1 -0
- package/dist/domains/access.d.ts +32 -0
- package/dist/domains/access.d.ts.map +1 -0
- package/dist/domains/access.js +43 -0
- package/dist/domains/access.js.map +1 -0
- package/dist/domains/adventureDefinitions.d.ts +159 -0
- package/dist/domains/adventureDefinitions.d.ts.map +1 -0
- package/dist/domains/adventureDefinitions.js +168 -0
- package/dist/domains/adventureDefinitions.js.map +1 -0
- package/dist/domains/adventures.d.ts +329 -0
- package/dist/domains/adventures.d.ts.map +1 -0
- package/dist/domains/adventures.js +359 -0
- package/dist/domains/adventures.js.map +1 -0
- package/dist/domains/arcs.d.ts +146 -0
- package/dist/domains/arcs.d.ts.map +1 -0
- package/dist/domains/arcs.js +202 -0
- package/dist/domains/arcs.js.map +1 -0
- package/dist/domains/artifacts.d.ts +259 -0
- package/dist/domains/artifacts.d.ts.map +1 -0
- package/dist/domains/artifacts.js +125 -0
- package/dist/domains/artifacts.js.map +1 -0
- package/dist/domains/chat.d.ts +158 -0
- package/dist/domains/chat.d.ts.map +1 -0
- package/dist/domains/chat.js +224 -0
- package/dist/domains/chat.js.map +1 -0
- package/dist/domains/decisions.d.ts +31 -0
- package/dist/domains/decisions.d.ts.map +1 -0
- package/dist/domains/decisions.js +42 -0
- package/dist/domains/decisions.js.map +1 -0
- package/dist/domains/documents.d.ts +218 -0
- package/dist/domains/documents.d.ts.map +1 -0
- package/dist/domains/documents.js +252 -0
- package/dist/domains/documents.js.map +1 -0
- package/dist/domains/enhancements.d.ts +106 -0
- package/dist/domains/enhancements.d.ts.map +1 -0
- package/dist/domains/enhancements.js +160 -0
- package/dist/domains/enhancements.js.map +1 -0
- package/dist/domains/graph.d.ts +454 -0
- package/dist/domains/graph.d.ts.map +1 -0
- package/dist/domains/graph.js +648 -0
- package/dist/domains/graph.js.map +1 -0
- package/dist/domains/images.d.ts +220 -0
- package/dist/domains/images.d.ts.map +1 -0
- package/dist/domains/images.js +307 -0
- package/dist/domains/images.js.map +1 -0
- package/dist/domains/ingestion.d.ts +312 -0
- package/dist/domains/ingestion.d.ts.map +1 -0
- package/dist/domains/ingestion.js +495 -0
- package/dist/domains/ingestion.js.map +1 -0
- package/dist/domains/me.d.ts +21 -0
- package/dist/domains/me.d.ts.map +1 -0
- package/dist/domains/me.js +23 -0
- package/dist/domains/me.js.map +1 -0
- package/dist/domains/orgs.d.ts +47 -0
- package/dist/domains/orgs.d.ts.map +1 -0
- package/dist/domains/orgs.js +75 -0
- package/dist/domains/orgs.js.map +1 -0
- package/dist/domains/personas.d.ts +135 -0
- package/dist/domains/personas.d.ts.map +1 -0
- package/dist/domains/personas.js +316 -0
- package/dist/domains/personas.js.map +1 -0
- package/dist/domains/projects.d.ts +53 -0
- package/dist/domains/projects.d.ts.map +1 -0
- package/dist/domains/projects.js +94 -0
- package/dist/domains/projects.js.map +1 -0
- package/dist/domains/quests.d.ts +431 -0
- package/dist/domains/quests.d.ts.map +1 -0
- package/dist/domains/quests.js +61 -0
- package/dist/domains/quests.js.map +1 -0
- package/dist/domains/reactor.d.ts +98 -0
- package/dist/domains/reactor.d.ts.map +1 -0
- package/dist/domains/reactor.js +131 -0
- package/dist/domains/reactor.js.map +1 -0
- package/dist/domains/showcase.d.ts +28 -0
- package/dist/domains/showcase.d.ts.map +1 -0
- package/dist/domains/showcase.js +28 -0
- package/dist/domains/showcase.js.map +1 -0
- package/dist/domains/storyboards.d.ts +1253 -0
- package/dist/domains/storyboards.d.ts.map +1 -0
- package/dist/domains/storyboards.js +781 -0
- package/dist/domains/storyboards.js.map +1 -0
- package/dist/domains/studioSettings.d.ts +39 -0
- package/dist/domains/studioSettings.d.ts.map +1 -0
- package/dist/domains/studioSettings.js +80 -0
- package/dist/domains/studioSettings.js.map +1 -0
- package/dist/domains/universes.d.ts +191 -0
- package/dist/domains/universes.d.ts.map +1 -0
- package/dist/domains/universes.js +276 -0
- package/dist/domains/universes.js.map +1 -0
- package/dist/domains/userDefaults.d.ts +18 -0
- package/dist/domains/userDefaults.d.ts.map +1 -0
- package/dist/domains/userDefaults.js +27 -0
- package/dist/domains/userDefaults.js.map +1 -0
- package/dist/domains/visemeBundles.d.ts +262 -0
- package/dist/domains/visemeBundles.d.ts.map +1 -0
- package/dist/domains/visemeBundles.js +373 -0
- package/dist/domains/visemeBundles.js.map +1 -0
- package/dist/domains/workflows.d.ts +142 -0
- package/dist/domains/workflows.d.ts.map +1 -0
- package/dist/domains/workflows.js +245 -0
- package/dist/domains/workflows.js.map +1 -0
- package/dist/enhancementDiff.d.ts +56 -0
- package/dist/enhancementDiff.d.ts.map +1 -0
- package/dist/enhancementDiff.js +110 -0
- package/dist/enhancementDiff.js.map +1 -0
- package/dist/generated/contract.d.ts +372 -0
- package/dist/generated/contract.d.ts.map +1 -0
- package/dist/generated/contract.js +390 -0
- package/dist/generated/contract.js.map +1 -0
- package/dist/graphSchema.d.ts +36 -5
- package/dist/graphSchema.d.ts.map +1 -1
- package/dist/graphSchema.js +88 -2
- package/dist/graphSchema.js.map +1 -1
- package/dist/http.d.ts +70 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +263 -11
- package/dist/http.js.map +1 -1
- package/dist/identity.d.ts +81 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +65 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -1
- package/dist/messageContent.d.ts +174 -0
- package/dist/messageContent.d.ts.map +1 -0
- package/dist/messageContent.js +405 -0
- package/dist/messageContent.js.map +1 -0
- package/dist/mutationEpoch.d.ts +83 -0
- package/dist/mutationEpoch.d.ts.map +1 -0
- package/dist/mutationEpoch.js +109 -0
- package/dist/mutationEpoch.js.map +1 -0
- package/dist/obo.d.ts +144 -0
- package/dist/obo.d.ts.map +1 -0
- package/dist/obo.js +135 -0
- package/dist/obo.js.map +1 -0
- package/dist/opusTransport.d.ts +113 -0
- package/dist/opusTransport.d.ts.map +1 -0
- package/dist/opusTransport.js +170 -0
- package/dist/opusTransport.js.map +1 -0
- package/dist/pagination.d.ts +18 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +26 -0
- package/dist/pagination.js.map +1 -0
- package/dist/platformAssistant.d.ts +55 -1
- package/dist/platformAssistant.d.ts.map +1 -1
- package/dist/platformAssistant.js +39 -1
- package/dist/platformAssistant.js.map +1 -1
- package/dist/pollUtils.d.ts +19 -0
- package/dist/pollUtils.d.ts.map +1 -0
- package/dist/pollUtils.js +35 -0
- package/dist/pollUtils.js.map +1 -0
- package/dist/questLog.d.ts +232 -0
- package/dist/questLog.d.ts.map +1 -0
- package/dist/questLog.js +522 -0
- package/dist/questLog.js.map +1 -0
- package/dist/reactor/dmDirectiveToExperience.d.ts +300 -0
- package/dist/reactor/dmDirectiveToExperience.d.ts.map +1 -0
- package/dist/reactor/dmDirectiveToExperience.js +401 -0
- package/dist/reactor/dmDirectiveToExperience.js.map +1 -0
- package/dist/reactor/dmSceneControlPrompt.d.ts +40 -0
- package/dist/reactor/dmSceneControlPrompt.d.ts.map +1 -0
- package/dist/reactor/dmSceneControlPrompt.js +145 -0
- package/dist/reactor/dmSceneControlPrompt.js.map +1 -0
- package/dist/reactor/dmWorldEntry.d.ts +1278 -0
- package/dist/reactor/dmWorldEntry.d.ts.map +1 -0
- package/dist/reactor/dmWorldEntry.js +1396 -0
- package/dist/reactor/dmWorldEntry.js.map +1 -0
- package/dist/reactor/framePromptCompaction.d.ts +223 -0
- package/dist/reactor/framePromptCompaction.d.ts.map +1 -0
- package/dist/reactor/framePromptCompaction.js +393 -0
- package/dist/reactor/framePromptCompaction.js.map +1 -0
- package/dist/reactor/frameWorldBind.d.ts +86 -0
- package/dist/reactor/frameWorldBind.d.ts.map +1 -0
- package/dist/reactor/frameWorldBind.js +79 -0
- package/dist/reactor/frameWorldBind.js.map +1 -0
- package/dist/reactor/happyOysterSeed.d.ts +166 -0
- package/dist/reactor/happyOysterSeed.d.ts.map +1 -0
- package/dist/reactor/happyOysterSeed.js +233 -0
- package/dist/reactor/happyOysterSeed.js.map +1 -0
- package/dist/reactor/happyOysterWalk.d.ts +274 -0
- package/dist/reactor/happyOysterWalk.d.ts.map +1 -0
- package/dist/reactor/happyOysterWalk.js +407 -0
- package/dist/reactor/happyOysterWalk.js.map +1 -0
- package/dist/reactor/happyOysterWorld.d.ts +718 -0
- package/dist/reactor/happyOysterWorld.d.ts.map +1 -0
- package/dist/reactor/happyOysterWorld.js +826 -0
- package/dist/reactor/happyOysterWorld.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/heliosCommandDispatcher.js +5 -2
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
- package/dist/reactor/hiddenWorldLifecycle.d.ts +101 -0
- package/dist/reactor/hiddenWorldLifecycle.d.ts.map +1 -0
- package/dist/reactor/hiddenWorldLifecycle.js +119 -0
- package/dist/reactor/hiddenWorldLifecycle.js.map +1 -0
- package/dist/reactor/imageCanvas.d.ts +15 -0
- package/dist/reactor/imageCanvas.d.ts.map +1 -0
- package/dist/reactor/imageCanvas.js +33 -0
- package/dist/reactor/imageCanvas.js.map +1 -0
- package/dist/reactor/index.d.ts +20 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +81 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.d.ts +23 -8
- package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.js +16 -4
- package/dist/reactor/longLiveCommandDispatcher.js.map +1 -1
- package/dist/reactor/longLiveSceneEntry.d.ts +203 -0
- package/dist/reactor/longLiveSceneEntry.d.ts.map +1 -0
- package/dist/reactor/longLiveSceneEntry.js +280 -0
- package/dist/reactor/longLiveSceneEntry.js.map +1 -0
- package/dist/reactor/momentCut.d.ts +153 -0
- package/dist/reactor/momentCut.d.ts.map +1 -0
- package/dist/reactor/momentCut.js +142 -0
- package/dist/reactor/momentCut.js.map +1 -0
- package/dist/reactor/promptAddonRegistry.d.ts +39 -3
- package/dist/reactor/promptAddonRegistry.d.ts.map +1 -1
- package/dist/reactor/promptAddonRegistry.js +44 -5
- package/dist/reactor/promptAddonRegistry.js.map +1 -1
- package/dist/reactor/promptTemplatePreview.d.ts +97 -0
- package/dist/reactor/promptTemplatePreview.d.ts.map +1 -0
- package/dist/reactor/promptTemplatePreview.js +185 -0
- package/dist/reactor/promptTemplatePreview.js.map +1 -0
- package/dist/reactor/reactorAvailability.d.ts +80 -0
- package/dist/reactor/reactorAvailability.d.ts.map +1 -0
- package/dist/reactor/reactorAvailability.js +121 -0
- package/dist/reactor/reactorAvailability.js.map +1 -0
- package/dist/reactor/reactorSessionRefusal.d.ts +125 -0
- package/dist/reactor/reactorSessionRefusal.d.ts.map +1 -0
- package/dist/reactor/reactorSessionRefusal.js +197 -0
- package/dist/reactor/reactorSessionRefusal.js.map +1 -0
- package/dist/reactor/reactorTokenScope.d.ts +47 -0
- package/dist/reactor/reactorTokenScope.d.ts.map +1 -0
- package/dist/reactor/reactorTokenScope.js +64 -0
- package/dist/reactor/reactorTokenScope.js.map +1 -0
- package/dist/reactor/resolveDirectorBeats.d.ts +65 -0
- package/dist/reactor/resolveDirectorBeats.d.ts.map +1 -0
- package/dist/reactor/resolveDirectorBeats.js +86 -0
- package/dist/reactor/resolveDirectorBeats.js.map +1 -0
- package/dist/reactor/sanaLiveEdit.d.ts +117 -0
- package/dist/reactor/sanaLiveEdit.d.ts.map +1 -0
- package/dist/reactor/sanaLiveEdit.js +105 -0
- package/dist/reactor/sanaLiveEdit.js.map +1 -0
- package/dist/reactor/sceneEntry.d.ts +66 -9
- package/dist/reactor/sceneEntry.d.ts.map +1 -1
- package/dist/reactor/sceneEntry.js +59 -66
- package/dist/reactor/sceneEntry.js.map +1 -1
- package/dist/reactor/sceneSeedImage.d.ts +199 -0
- package/dist/reactor/sceneSeedImage.d.ts.map +1 -0
- package/dist/reactor/sceneSeedImage.js +239 -0
- package/dist/reactor/sceneSeedImage.js.map +1 -0
- package/dist/reactor/seedImageOrchestrator.d.ts +70 -3
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +92 -28
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/reactor/toolPromptAddon.d.ts +37 -28
- package/dist/reactor/toolPromptAddon.d.ts.map +1 -1
- package/dist/reactor/toolPromptAddon.js +63 -101
- package/dist/reactor/toolPromptAddon.js.map +1 -1
- package/dist/reactor/worldMintLoop.d.ts +286 -0
- package/dist/reactor/worldMintLoop.d.ts.map +1 -0
- package/dist/reactor/worldMintLoop.js +381 -0
- package/dist/reactor/worldMintLoop.js.map +1 -0
- package/dist/reactor/worldSteerOutcome.d.ts +98 -0
- package/dist/reactor/worldSteerOutcome.d.ts.map +1 -0
- package/dist/reactor/worldSteerOutcome.js +81 -0
- package/dist/reactor/worldSteerOutcome.js.map +1 -0
- package/dist/retryAfter.d.ts +15 -0
- package/dist/retryAfter.d.ts.map +1 -0
- package/dist/retryAfter.js +75 -0
- package/dist/retryAfter.js.map +1 -0
- package/dist/seriesKey.d.ts +31 -0
- package/dist/seriesKey.d.ts.map +1 -0
- package/dist/seriesKey.js +33 -0
- package/dist/seriesKey.js.map +1 -0
- package/dist/sessionRefresh.d.ts +135 -0
- package/dist/sessionRefresh.d.ts.map +1 -0
- package/dist/sessionRefresh.js +215 -0
- package/dist/sessionRefresh.js.map +1 -0
- package/dist/sharedAudioContext.d.ts +39 -0
- package/dist/sharedAudioContext.d.ts.map +1 -0
- package/dist/sharedAudioContext.js +63 -0
- package/dist/sharedAudioContext.js.map +1 -0
- package/dist/singleFlight.d.ts +51 -0
- package/dist/singleFlight.d.ts.map +1 -0
- package/dist/singleFlight.js +87 -0
- package/dist/singleFlight.js.map +1 -0
- package/dist/storyGraph.d.ts +83 -0
- package/dist/storyGraph.d.ts.map +1 -1
- package/dist/storyGraph.js +169 -4
- package/dist/storyGraph.js.map +1 -1
- package/dist/storyboardMask.d.ts +343 -0
- package/dist/storyboardMask.d.ts.map +1 -0
- package/dist/storyboardMask.js +505 -0
- package/dist/storyboardMask.js.map +1 -0
- package/dist/storyboardTimeline.d.ts +93 -0
- package/dist/storyboardTimeline.d.ts.map +1 -0
- package/dist/storyboardTimeline.js +131 -0
- package/dist/storyboardTimeline.js.map +1 -0
- package/dist/studioAutomation.d.ts +104 -0
- package/dist/studioAutomation.d.ts.map +1 -0
- package/dist/studioAutomation.js +178 -0
- package/dist/studioAutomation.js.map +1 -0
- package/dist/tenantClaim.d.ts +86 -0
- package/dist/tenantClaim.d.ts.map +1 -0
- package/dist/tenantClaim.js +164 -0
- package/dist/tenantClaim.js.map +1 -0
- package/dist/timeFormat.d.ts +25 -0
- package/dist/timeFormat.d.ts.map +1 -1
- package/dist/timeFormat.js +56 -0
- package/dist/timeFormat.js.map +1 -1
- package/dist/toolSchemas.d.ts +53 -10
- package/dist/toolSchemas.d.ts.map +1 -1
- package/dist/toolSchemas.js +36 -9
- package/dist/toolSchemas.js.map +1 -1
- package/dist/transport.d.ts +120 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +282 -0
- package/dist/transport.js.map +1 -0
- package/dist/videoGenFacade.d.ts +63 -0
- package/dist/videoGenFacade.d.ts.map +1 -0
- package/dist/videoGenFacade.js +49 -0
- package/dist/videoGenFacade.js.map +1 -0
- package/dist/visemeScheduler.d.ts +24 -2
- package/dist/visemeScheduler.d.ts.map +1 -1
- package/dist/visemeScheduler.js +31 -2
- package/dist/visemeScheduler.js.map +1 -1
- package/dist/vision/VisionPublisher.d.ts +88 -0
- package/dist/vision/VisionPublisher.d.ts.map +1 -1
- package/dist/vision/VisionPublisher.js +196 -13
- package/dist/vision/VisionPublisher.js.map +1 -1
- package/dist/vision/VisionSourceController.d.ts +67 -1
- package/dist/vision/VisionSourceController.d.ts.map +1 -1
- package/dist/vision/VisionSourceController.js +147 -5
- package/dist/vision/VisionSourceController.js.map +1 -1
- package/dist/vision/index.d.ts +2 -1
- package/dist/vision/index.d.ts.map +1 -1
- package/dist/vision/index.js +2 -1
- package/dist/vision/index.js.map +1 -1
- package/dist/vision/sourceKinds.d.ts +18 -5
- package/dist/vision/sourceKinds.d.ts.map +1 -1
- package/dist/vision/sourceKinds.js +15 -2
- package/dist/vision/sourceKinds.js.map +1 -1
- package/dist/vision/types.d.ts +7 -4
- package/dist/vision/types.d.ts.map +1 -1
- package/dist/vision/visionErrors.d.ts +45 -0
- package/dist/vision/visionErrors.d.ts.map +1 -0
- package/dist/vision/visionErrors.js +66 -0
- package/dist/vision/visionErrors.js.map +1 -0
- package/dist/voiceCloneCaption.d.ts +33 -0
- package/dist/voiceCloneCaption.d.ts.map +1 -0
- package/dist/voiceCloneCaption.js +69 -0
- package/dist/voiceCloneCaption.js.map +1 -0
- package/dist/websocket.d.ts +390 -10
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +152 -0
- package/dist/websocket.js.map +1 -1
- package/dist/workflowAuthoring.d.ts +139 -0
- package/dist/workflowAuthoring.d.ts.map +1 -0
- package/dist/workflowAuthoring.js +557 -0
- package/dist/workflowAuthoring.js.map +1 -0
- package/package.json +15 -5
- package/src/__tests__/adapters-director.test.ts +9 -6
- package/src/__tests__/adapters-extraction.test.ts +175 -0
- package/src/__tests__/adapters-image.test.ts +66 -0
- package/src/__tests__/adapters-momentPolicy.test.ts +218 -0
- package/src/__tests__/adapters-platform.test.ts +110 -4
- package/src/__tests__/adapters-videogen.test.ts +53 -0
- package/src/__tests__/adapters-world.test.ts +117 -7
- package/src/__tests__/admin.enhancement-defaults.test.ts +115 -0
- package/src/__tests__/admin.test.ts +282 -0
- package/src/__tests__/adventures-world-state.test.ts +156 -0
- package/src/__tests__/adventures.test.ts +111 -1
- package/src/__tests__/api-pollers.test.ts +113 -23
- package/src/__tests__/api.adventure-definitions.test.ts +312 -0
- package/src/__tests__/api.anchor-beat.test.ts +75 -0
- package/src/__tests__/api.arc-approval.test.ts +171 -0
- package/src/__tests__/api.arc-beats-floor.test.ts +56 -0
- package/src/__tests__/api.arc-generation.test.ts +168 -0
- package/src/__tests__/api.arc-templates.test.ts +78 -0
- package/src/__tests__/api.assignVideoSeries.test.ts +81 -0
- package/src/__tests__/api.cast-frame-choices.test.ts +141 -0
- package/src/__tests__/api.cutscene-registry.test.ts +148 -0
- package/src/__tests__/api.enhancement-addition-actions.test.ts +137 -0
- package/src/__tests__/api.enrichVideo-serialization.test.ts +116 -0
- package/src/__tests__/api.extraction-base.test.ts +87 -0
- package/src/__tests__/api.generateVideo-cutscene.test.ts +148 -0
- package/src/__tests__/api.job-pipeline-stages.test.ts +128 -0
- package/src/__tests__/api.list-images-filters.test.ts +6 -3
- package/src/__tests__/api.quest-curation.test.ts +169 -0
- package/src/__tests__/api.reprocessVideo.test.ts +71 -0
- package/src/__tests__/api.scene-split-merge.test.ts +129 -0
- package/src/__tests__/api.session-quests.test.ts +184 -0
- package/src/__tests__/api.test.ts +122 -0
- package/src/__tests__/api.transferSeries.test.ts +114 -0
- package/src/__tests__/api.unknown-clusters.test.ts +225 -0
- package/src/__tests__/api.uploadVideo-options.test.ts +156 -0
- package/src/__tests__/arcPreview.test.ts +71 -0
- package/src/__tests__/arcStyleProfile.test.ts +204 -0
- package/src/__tests__/artifacts-delete.test.ts +109 -0
- package/src/__tests__/audio.test.ts +864 -5
- package/src/__tests__/audioDsp.test.ts +196 -0
- package/src/__tests__/audioUnavailable.test.ts +43 -0
- package/src/__tests__/cast.test.ts +10 -1
- package/src/__tests__/castCurationProjection.test.ts +84 -0
- package/src/__tests__/castFramePipelinePending.test.ts +171 -0
- package/src/__tests__/castProjection.test.ts +497 -5
- package/src/__tests__/characterGrounding.test.ts +357 -0
- package/src/__tests__/contract.test.ts +97 -0
- package/src/__tests__/conversation/binding.test.ts +53 -0
- package/src/__tests__/conversation/chatSessionStore.test.ts +243 -0
- package/src/__tests__/conversation/controller.test.ts +328 -0
- package/src/__tests__/conversation/readSequencer.test.ts +52 -0
- package/src/__tests__/conversation/rosterProjection.test.ts +204 -3
- package/src/__tests__/conversation/runtime.test.ts +118 -1
- package/src/__tests__/conversation/voice.test.ts +741 -7
- package/src/__tests__/creatorCuration.test.ts +256 -0
- package/src/__tests__/creatorDashboard.test.ts +444 -0
- package/src/__tests__/creatorUniverse.test.ts +138 -0
- package/src/__tests__/curationWrite.test.ts +179 -0
- package/src/__tests__/decisions.test.ts +89 -0
- package/src/__tests__/designTokens.test.ts +72 -0
- package/src/__tests__/dialogAttribution.test.ts +187 -0
- package/src/__tests__/dmDirectiveToExperience.test.ts +198 -0
- package/src/__tests__/dmWorldEntry.test.ts +2102 -0
- package/src/__tests__/enhancementDiff.test.ts +132 -0
- package/src/__tests__/experienceModelCatalog.test.ts +292 -0
- package/src/__tests__/extractionStageState.test.ts +67 -0
- package/src/__tests__/getVideo.test.ts +95 -0
- package/src/__tests__/graphReadAfterWrite.test.ts +211 -0
- package/src/__tests__/graphSchema.test.ts +55 -4
- package/src/__tests__/happyOysterSeed.test.ts +208 -0
- package/src/__tests__/happyOysterWorld.test.ts +1241 -0
- package/src/__tests__/happyOysterWorldRefusal.test.ts +224 -0
- package/src/__tests__/hiddenWorldLifecycle.test.ts +203 -0
- package/src/__tests__/http.session-refresh.test.ts +424 -0
- package/src/__tests__/http.test.ts +316 -0
- package/src/__tests__/identity.test.ts +132 -0
- package/src/__tests__/loadBundleManifest.test.ts +192 -22
- package/src/__tests__/longLiveSceneEntry.test.ts +371 -0
- package/src/__tests__/me.test.ts +74 -0
- package/src/__tests__/messageContent.test.ts +395 -0
- package/src/__tests__/momentCut.test.ts +229 -0
- package/src/__tests__/mutationEpoch.test.ts +218 -0
- package/src/__tests__/obo.test.ts +159 -0
- package/src/__tests__/opusTransport.test.ts +182 -0
- package/src/__tests__/opusTransportLibopus.test.ts +125 -0
- package/src/__tests__/orgs.test.ts +229 -0
- package/src/__tests__/persona-generation.test.ts +187 -1
- package/src/__tests__/platformAssistant.test.ts +140 -0
- package/src/__tests__/projects.test.ts +338 -0
- package/src/__tests__/promptTemplatePreview.test.ts +160 -0
- package/src/__tests__/reactor/__fixtures__/realFramePromptText.ts +23 -0
- package/src/__tests__/reactor/api-reactor.test.ts +60 -21
- package/src/__tests__/reactor/framePromptCompaction.test.ts +300 -0
- package/src/__tests__/reactor/promptAddonRegistry.test.ts +82 -1
- package/src/__tests__/reactor/reactorTokenScope.test.ts +50 -0
- package/src/__tests__/reactor/resolveDirectorBeats.test.ts +156 -0
- package/src/__tests__/reactor/sceneEntry.test.ts +3 -0
- package/src/__tests__/reactor/sceneSeedImage.test.ts +361 -0
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +43 -5
- package/src/__tests__/reactor/toolPromptAddon.test.ts +34 -42
- package/src/__tests__/reactor-happyOysterWalk.test.ts +294 -0
- package/src/__tests__/reactorAvailability.test.ts +217 -0
- package/src/__tests__/reactorSessionRefusal.test.ts +189 -0
- package/src/__tests__/regeneration.test.ts +9 -9
- package/src/__tests__/reprocessBlockedReason.test.ts +30 -0
- package/src/__tests__/retryAfter.test.ts +65 -0
- package/src/__tests__/roleClaim.test.ts +102 -0
- package/src/__tests__/sanaLiveEdit.test.ts +84 -0
- package/src/__tests__/seriesKey.test.ts +24 -0
- package/src/__tests__/settings-set9.test.ts +238 -0
- package/src/__tests__/singleFlight.test.ts +348 -0
- package/src/__tests__/storyGraph.test.ts +111 -1
- package/src/__tests__/storyboardFrameCutscene.test.ts +115 -0
- package/src/__tests__/storyboardMask.test.ts +527 -0
- package/src/__tests__/storyboardTimeline.test.ts +228 -0
- package/src/__tests__/storyboards.test.ts +639 -0
- package/src/__tests__/studioAutomation.test.ts +325 -0
- package/src/__tests__/toolSchemas.test.ts +11 -18
- package/src/__tests__/transport.test.ts +312 -0
- package/src/__tests__/videoGenFacade.test.ts +141 -0
- package/src/__tests__/videoGraph.test.ts +43 -1
- package/src/__tests__/visemeScheduler.test.ts +55 -1
- package/src/__tests__/visibility.test.ts +143 -0
- package/src/__tests__/voiceCloneCaption.test.ts +80 -0
- package/src/__tests__/voiceFallback.test.ts +55 -0
- package/src/__tests__/websocket-error-turn-ended.test.ts +49 -0
- package/src/__tests__/websocket-session-attach.test.ts +288 -0
- package/src/__tests__/websocket-vision.test.ts +141 -0
- package/src/__tests__/websocket.test.ts +75 -1
- package/src/__tests__/workflowAuthoring.test.ts +187 -0
- package/src/__tests__/workflows.test.ts +640 -0
- package/src/__tests__/worldMintLoop.test.ts +448 -0
- package/src/__tests__/worldModelPreference.test.ts +302 -0
- package/src/__tests__/worldModelTradeoffs.test.ts +89 -0
- package/src/__tests__/worldSteerOutcome.test.ts +62 -0
- package/src/adapters/capabilities.ts +39 -3
- package/src/adapters/directorAdapter.ts +5 -4
- package/src/adapters/experienceModelCatalog.ts +538 -0
- package/src/adapters/extractionAdapter.ts +150 -0
- package/src/adapters/imageAdapter.ts +5 -1
- package/src/adapters/index.ts +104 -17
- package/src/adapters/momentDirective.ts +109 -0
- package/src/adapters/momentPolicy.ts +209 -0
- package/src/adapters/registry.ts +1 -1
- package/src/adapters/videoGenAdapter.ts +124 -0
- package/src/adapters/worldAdapter.ts +221 -16
- package/src/adapters/worldModelPreference.ts +247 -0
- package/src/adapters/worldModelTradeoffs.ts +247 -0
- package/src/admin.ts +842 -16
- package/src/api.ts +12670 -3446
- package/src/arcBoardJoin.ts +46 -0
- package/src/arcPreview.ts +103 -0
- package/src/audio.ts +691 -130
- package/src/audioDsp.ts +132 -0
- package/src/audioProtocol.ts +235 -0
- package/src/beatTitles.ts +51 -0
- package/src/castProjection.ts +311 -0
- package/src/characterGrounding.ts +491 -0
- package/src/conversation/binding.ts +53 -1
- package/src/conversation/chatSessionStore.ts +281 -0
- package/src/conversation/controller.ts +135 -3
- package/src/conversation/index.ts +2 -0
- package/src/conversation/participant.ts +16 -0
- package/src/conversation/readSequencer.ts +55 -0
- package/src/conversation/roster.ts +5 -1
- package/src/conversation/rosterProjection.ts +166 -2
- package/src/conversation/runtime.ts +66 -7
- package/src/conversation/types.ts +43 -4
- package/src/conversation/voice.ts +655 -51
- package/src/creatorCuration.ts +316 -0
- package/src/creatorDashboard.ts +344 -0
- package/src/creatorUniverse.ts +222 -0
- package/src/curationWrite.ts +108 -0
- package/src/designTokens.ts +157 -0
- package/src/dialogAttribution.ts +182 -0
- package/src/dmRunWorldReadiness.ts +1168 -0
- package/src/domains/access.ts +92 -0
- package/src/domains/adventureDefinitions.ts +313 -0
- package/src/domains/adventures.ts +557 -0
- package/src/domains/arcs.ts +350 -0
- package/src/domains/artifacts.ts +349 -0
- package/src/domains/chat.ts +338 -0
- package/src/domains/decisions.ts +62 -0
- package/src/domains/documents.ts +389 -0
- package/src/domains/enhancements.ts +259 -0
- package/src/domains/graph.ts +959 -0
- package/src/domains/images.ts +451 -0
- package/src/domains/ingestion.ts +695 -0
- package/src/domains/me.ts +27 -0
- package/src/domains/orgs.ts +168 -0
- package/src/domains/personas.ts +433 -0
- package/src/domains/projects.ts +177 -0
- package/src/domains/quests.ts +587 -0
- package/src/domains/reactor.ts +163 -0
- package/src/domains/showcase.ts +35 -0
- package/src/domains/storyboards.ts +1698 -0
- package/src/domains/studioSettings.ts +149 -0
- package/src/domains/universes.ts +433 -0
- package/src/domains/userDefaults.ts +37 -0
- package/src/domains/visemeBundles.ts +541 -0
- package/src/domains/workflows.ts +376 -0
- package/src/enhancementDiff.ts +171 -0
- package/src/generated/contract.ts +1011 -0
- package/src/graphSchema.ts +154 -6
- package/src/http.ts +295 -11
- package/src/identity.ts +123 -0
- package/src/index.ts +131 -0
- package/src/messageContent.ts +500 -0
- package/src/mutationEpoch.ts +107 -0
- package/src/obo.ts +201 -0
- package/src/opusTransport.ts +268 -0
- package/src/pagination.ts +29 -0
- package/src/platformAssistant.ts +97 -1
- package/src/pollUtils.ts +35 -0
- package/src/questLog.ts +704 -0
- package/src/reactor/dmDirectiveToExperience.ts +636 -0
- package/src/reactor/dmSceneControlPrompt.ts +152 -0
- package/src/reactor/dmWorldEntry.ts +2226 -0
- package/src/reactor/framePromptCompaction.ts +544 -0
- package/src/reactor/frameWorldBind.ts +133 -0
- package/src/reactor/happyOysterSeed.ts +329 -0
- package/src/reactor/happyOysterWalk.ts +541 -0
- package/src/reactor/happyOysterWorld.ts +1270 -0
- package/src/reactor/heliosCommandDispatcher.ts +5 -1
- package/src/reactor/hiddenWorldLifecycle.ts +182 -0
- package/src/reactor/imageCanvas.ts +38 -0
- package/src/reactor/index.ts +81 -0
- package/src/reactor/longLiveCommandDispatcher.ts +23 -8
- package/src/reactor/longLiveSceneEntry.ts +409 -0
- package/src/reactor/momentCut.ts +219 -0
- package/src/reactor/promptAddonRegistry.ts +83 -5
- package/src/reactor/promptTemplatePreview.ts +240 -0
- package/src/reactor/reactorAvailability.ts +155 -0
- package/src/reactor/reactorSessionRefusal.ts +260 -0
- package/src/reactor/reactorTokenScope.ts +69 -0
- package/src/reactor/resolveDirectorBeats.ts +140 -0
- package/src/reactor/sanaLiveEdit.ts +158 -0
- package/src/reactor/sceneEntry.ts +106 -88
- package/src/reactor/sceneSeedImage.ts +338 -0
- package/src/reactor/seedImageOrchestrator.ts +116 -34
- package/src/reactor/toolPromptAddon.ts +66 -102
- package/src/reactor/worldMintLoop.ts +545 -0
- package/src/reactor/worldSteerOutcome.ts +132 -0
- package/src/retryAfter.ts +71 -0
- package/src/seriesKey.ts +42 -0
- package/src/sessionRefresh.ts +237 -0
- package/src/sharedAudioContext.ts +67 -0
- package/src/singleFlight.ts +91 -0
- package/src/storyGraph.ts +247 -4
- package/src/storyboardMask.ts +756 -0
- package/src/storyboardTimeline.ts +220 -0
- package/src/studioAutomation.ts +208 -0
- package/src/tenantClaim.ts +170 -0
- package/src/timeFormat.ts +51 -0
- package/src/toolSchemas.ts +39 -10
- package/src/transport.ts +327 -0
- package/src/videoGenFacade.ts +90 -0
- package/src/visemeScheduler.ts +36 -3
- package/src/vision/VisionPublisher.ts +204 -14
- package/src/vision/VisionSourceController.ts +187 -6
- package/src/vision/__tests__/VisionPublisher.kvs.test.ts +50 -0
- package/src/vision/__tests__/VisionPublisher.test.ts +291 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +376 -6
- package/src/vision/index.ts +5 -1
- package/src/vision/sourceKinds.ts +19 -5
- package/src/vision/types.ts +7 -4
- package/src/vision/visionErrors.ts +70 -0
- package/src/voiceCloneCaption.ts +77 -0
- package/src/websocket.ts +542 -9
- package/src/workflowAuthoring.ts +664 -0
package/src/audio.ts
CHANGED
|
@@ -18,40 +18,28 @@ import {
|
|
|
18
18
|
type PlaybackPositionMessage,
|
|
19
19
|
} from './audioProtocol';
|
|
20
20
|
import { VisemeScheduler } from './visemeScheduler';
|
|
21
|
+
import { resampleToTarget } from './audioDsp';
|
|
22
|
+
import {
|
|
23
|
+
acquireSharedAudioContext,
|
|
24
|
+
releaseSharedAudioContext,
|
|
25
|
+
} from './sharedAudioContext';
|
|
21
26
|
|
|
22
27
|
const FLOAT_DIVISOR = 32768;
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (sourceRate === targetRate) {
|
|
39
|
-
return floatTo16BitPCM(input);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const ratio = targetRate / sourceRate;
|
|
43
|
-
const targetLength = Math.round(input.length * ratio);
|
|
44
|
-
const output = new Float32Array(targetLength);
|
|
45
|
-
|
|
46
|
-
for (let i = 0; i < targetLength; i += 1) {
|
|
47
|
-
const origin = i / ratio;
|
|
48
|
-
const index = Math.floor(origin);
|
|
49
|
-
const nextIndex = Math.min(index + 1, input.length - 1);
|
|
50
|
-
const weight = origin - index;
|
|
51
|
-
output[i] = input[index] * (1 - weight) + input[nextIndex] * weight;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return floatTo16BitPCM(output);
|
|
29
|
+
/**
|
|
30
|
+
* The ONE mic-capture constraint set (AU.3). `echoCancellation: true` is
|
|
31
|
+
* LOAD-BEARING for auto barge-in: the server treats any Deepgram
|
|
32
|
+
* `StartOfTurn` during assistant speech as the user interrupting, so the
|
|
33
|
+
* persona's own TTS leaking into the mic would self-trigger barge-ins.
|
|
34
|
+
* Pinned by a unit test — do not weaken without re-testing auto barge-in
|
|
35
|
+
* on speakerphone/laptop-speaker setups.
|
|
36
|
+
*/
|
|
37
|
+
export const MIC_AUDIO_CONSTRAINTS: MediaTrackConstraints = {
|
|
38
|
+
echoCancellation: true,
|
|
39
|
+
noiseSuppression: true,
|
|
40
|
+
channelCount: 1,
|
|
41
|
+
sampleRate: SAMPLE_RATE,
|
|
42
|
+
sampleSize: BYTES_PER_SAMPLE * 8,
|
|
55
43
|
};
|
|
56
44
|
|
|
57
45
|
export class MicrophoneRecorder {
|
|
@@ -81,11 +69,12 @@ export class MicrophoneRecorder {
|
|
|
81
69
|
* `start()`'s own internal `prime()` runs after the gesture has
|
|
82
70
|
* unwound and iOS leaves the context in `suspended` state.
|
|
83
71
|
*
|
|
84
|
-
* No I/O, no awaits, no permission prompts — just
|
|
85
|
-
*
|
|
72
|
+
* No I/O, no awaits, no permission prompts — just an acquire of the shared
|
|
73
|
+
* page-singleton context (AU.2a: iOS caps a page at 4 live AudioContexts;
|
|
74
|
+
* the recorder and player now SHARE one) and a fire-and-forget `resume()`. */
|
|
86
75
|
prime(): void {
|
|
87
76
|
if (this.audioContext) return;
|
|
88
|
-
this.audioContext =
|
|
77
|
+
this.audioContext = acquireSharedAudioContext();
|
|
89
78
|
void this.audioContext.resume();
|
|
90
79
|
}
|
|
91
80
|
|
|
@@ -107,20 +96,14 @@ export class MicrophoneRecorder {
|
|
|
107
96
|
|
|
108
97
|
try {
|
|
109
98
|
this.mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
110
|
-
audio:
|
|
111
|
-
echoCancellation: true,
|
|
112
|
-
noiseSuppression: true,
|
|
113
|
-
channelCount: 1,
|
|
114
|
-
sampleRate: SAMPLE_RATE,
|
|
115
|
-
sampleSize: BYTES_PER_SAMPLE * 8,
|
|
116
|
-
},
|
|
99
|
+
audio: MIC_AUDIO_CONSTRAINTS,
|
|
117
100
|
});
|
|
118
101
|
} catch (err) {
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
102
|
+
// Release our hold on the shared context so a permission denial
|
|
103
|
+
// doesn't leak a refcount, and a retry from a fresh user gesture
|
|
104
|
+
// starts clean (the singleton itself is retained for reuse — AU.2a).
|
|
122
105
|
if (this.audioContext) {
|
|
123
|
-
|
|
106
|
+
releaseSharedAudioContext();
|
|
124
107
|
this.audioContext = null;
|
|
125
108
|
}
|
|
126
109
|
const message = err instanceof Error ? err.message : 'Microphone permission denied';
|
|
@@ -149,9 +132,19 @@ export class MicrophoneRecorder {
|
|
|
149
132
|
|
|
150
133
|
if (useWorklet) {
|
|
151
134
|
this.workletNode = new AudioWorkletNode(this.audioContext, 'mic-processor');
|
|
152
|
-
this.workletNode.port.onmessage = (
|
|
135
|
+
this.workletNode.port.onmessage = (
|
|
136
|
+
event: MessageEvent<Float32Array | Int16Array>,
|
|
137
|
+
) => {
|
|
153
138
|
// Guard: worklet message can arrive after stop() has nulled the context
|
|
154
139
|
if (!this.audioContext) return;
|
|
140
|
+
// AU.2c — an updated worklet processor resamples + anti-alias filters
|
|
141
|
+
// OFF the main thread and posts wire-ready Int16 PCM. A stale cached
|
|
142
|
+
// processor (or a host app serving the old asset) still posts raw
|
|
143
|
+
// Float32 at the context rate; keep the main-thread fallback for it.
|
|
144
|
+
if (event.data instanceof Int16Array) {
|
|
145
|
+
this.enqueueSamples(event.data);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
155
148
|
const pcm = resampleToTarget(event.data, this.audioContext.sampleRate);
|
|
156
149
|
this.enqueueSamples(pcm);
|
|
157
150
|
};
|
|
@@ -198,7 +191,9 @@ export class MicrophoneRecorder {
|
|
|
198
191
|
this.source = null;
|
|
199
192
|
}
|
|
200
193
|
if (this.audioContext) {
|
|
201
|
-
|
|
194
|
+
// AU.2a: release the shared singleton (suspended at refcount 0, never
|
|
195
|
+
// closed) instead of closing a per-recorder context.
|
|
196
|
+
releaseSharedAudioContext();
|
|
202
197
|
this.audioContext = null;
|
|
203
198
|
}
|
|
204
199
|
if (this.mediaStream) {
|
|
@@ -225,46 +220,229 @@ export class MicrophoneRecorder {
|
|
|
225
220
|
}
|
|
226
221
|
}
|
|
227
222
|
|
|
223
|
+
/** Default RMS threshold (normalized 0..1) above which a mic frame counts as
|
|
224
|
+
* voiced. Post-echoCancellation TTS residue and room noise sit well below
|
|
225
|
+
* this; normal speech at conversational distance sits well above. */
|
|
226
|
+
const MIC_VAD_DEFAULT_THRESHOLD = 0.015;
|
|
227
|
+
/** Consecutive voiced frames (20 ms each) required before `speaking` flips
|
|
228
|
+
* true — the AU.3 VAD-assist DEBOUNCE (~100 ms) so clicks/pops don't flash
|
|
229
|
+
* the "listening/interrupting" affordance. */
|
|
230
|
+
const MIC_VAD_DEFAULT_ATTACK_FRAMES = 5;
|
|
231
|
+
/** Consecutive silent frames before `speaking` flips false (~500 ms hangover
|
|
232
|
+
* so natural inter-word gaps don't flicker the affordance). */
|
|
233
|
+
const MIC_VAD_DEFAULT_RELEASE_FRAMES = 25;
|
|
234
|
+
|
|
235
|
+
export interface MicVadOptions {
|
|
236
|
+
threshold?: number;
|
|
237
|
+
attackFrames?: number;
|
|
238
|
+
releaseFrames?: number;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* AU.3 — tiny energy-based voice-activity detector over the outbound mic
|
|
243
|
+
* frames (the same tagged PCM16 frames `MicrophoneRecorder` emits). CLIENT
|
|
244
|
+
* AFFORDANCE ONLY: the authoritative barge-in decision is server-side
|
|
245
|
+
* (Deepgram StartOfTurn); this just debounces a local "the user is speaking"
|
|
246
|
+
* signal so hosts can show a listening/interrupting indicator without a
|
|
247
|
+
* server round-trip. Framework-agnostic, no audio-graph dependency.
|
|
248
|
+
*/
|
|
249
|
+
export class MicVad {
|
|
250
|
+
private voicedRun = 0;
|
|
251
|
+
|
|
252
|
+
private silentRun = 0;
|
|
253
|
+
|
|
254
|
+
private isSpeaking = false;
|
|
255
|
+
|
|
256
|
+
private readonly threshold: number;
|
|
257
|
+
|
|
258
|
+
private readonly attackFrames: number;
|
|
259
|
+
|
|
260
|
+
private readonly releaseFrames: number;
|
|
261
|
+
|
|
262
|
+
constructor(
|
|
263
|
+
private readonly onChange: (speaking: boolean) => void,
|
|
264
|
+
options: MicVadOptions = {},
|
|
265
|
+
) {
|
|
266
|
+
this.threshold = options.threshold ?? MIC_VAD_DEFAULT_THRESHOLD;
|
|
267
|
+
this.attackFrames = options.attackFrames ?? MIC_VAD_DEFAULT_ATTACK_FRAMES;
|
|
268
|
+
this.releaseFrames = options.releaseFrames ?? MIC_VAD_DEFAULT_RELEASE_FRAMES;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
get speaking(): boolean {
|
|
272
|
+
return this.isSpeaking;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Feed one outbound mic frame (tag byte + PCM16LE, as produced by
|
|
276
|
+
* `encodeAudioFrame(TAG_MIC, …)`). Fires `onChange` on debounced
|
|
277
|
+
* speech-start/speech-end transitions. */
|
|
278
|
+
push(frame: Uint8Array): void {
|
|
279
|
+
// Skip the 1-byte tag; read aligned PCM16LE samples.
|
|
280
|
+
const byteLength = frame.byteLength - 1;
|
|
281
|
+
const sampleCount = Math.floor(byteLength / 2);
|
|
282
|
+
if (sampleCount <= 0) return;
|
|
283
|
+
const view = new DataView(frame.buffer, frame.byteOffset + 1, sampleCount * 2);
|
|
284
|
+
let sumSquares = 0;
|
|
285
|
+
for (let i = 0; i < sampleCount; i += 1) {
|
|
286
|
+
const s = view.getInt16(i * 2, true) / 32768;
|
|
287
|
+
sumSquares += s * s;
|
|
288
|
+
}
|
|
289
|
+
const rms = Math.sqrt(sumSquares / sampleCount);
|
|
290
|
+
if (rms >= this.threshold) {
|
|
291
|
+
this.voicedRun += 1;
|
|
292
|
+
this.silentRun = 0;
|
|
293
|
+
if (!this.isSpeaking && this.voicedRun >= this.attackFrames) {
|
|
294
|
+
this.isSpeaking = true;
|
|
295
|
+
this.onChange(true);
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
this.silentRun += 1;
|
|
299
|
+
this.voicedRun = 0;
|
|
300
|
+
if (this.isSpeaking && this.silentRun >= this.releaseFrames) {
|
|
301
|
+
this.isSpeaking = false;
|
|
302
|
+
this.onChange(false);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Reset all state (session stop/teardown). Fires `onChange(false)` if a
|
|
308
|
+
* speaking run was open so hosts never strand the affordance. */
|
|
309
|
+
reset(): void {
|
|
310
|
+
this.voicedRun = 0;
|
|
311
|
+
this.silentRun = 0;
|
|
312
|
+
if (this.isSpeaking) {
|
|
313
|
+
this.isSpeaking = false;
|
|
314
|
+
this.onChange(false);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Persona-TTS gain while a visual TAKEOVER owns the surface (§Q DM.1) — a
|
|
321
|
+
* cutscene clip or a HappyOyster world stream. Those play un-muted and carry
|
|
322
|
+
* their own music/SFX mux, so without a duck the DM and the takeover talk over
|
|
323
|
+
* each other at full volume.
|
|
324
|
+
*
|
|
325
|
+
* 0.25 keeps the DM audible under the takeover rather than cutting it: the DM
|
|
326
|
+
* is still narrating the moment, so muting is wrong and full volume is wrong.
|
|
327
|
+
*/
|
|
328
|
+
export const AUDIO_TAKEOVER_DUCK_GAIN = 0.25;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Time constant for the duck ramp, in seconds. A gain step is a click; ~30 ms
|
|
332
|
+
* of `setTargetAtTime` is inaudible as a transition and still fast enough that
|
|
333
|
+
* the duck lands under the takeover's first frame.
|
|
334
|
+
*/
|
|
335
|
+
export const AUDIO_DUCK_RAMP_TIME_CONSTANT_S = 0.03;
|
|
336
|
+
|
|
228
337
|
export class AudioFramePlayer {
|
|
229
338
|
private context: AudioContext;
|
|
230
339
|
|
|
231
340
|
private gainNode: GainNode;
|
|
232
341
|
|
|
342
|
+
/** Current output gain (1 = un-ducked). Tracked as a field because the ramp
|
|
343
|
+
* schedules the value rather than assigning `gain.value`, so the param is
|
|
344
|
+
* not a reliable readback of what was REQUESTED. */
|
|
345
|
+
private duckGain = 1;
|
|
346
|
+
|
|
233
347
|
private activeSources = new Set<AudioBufferSourceNode>();
|
|
234
348
|
|
|
235
349
|
private queuedTime = 0;
|
|
236
350
|
|
|
237
|
-
/**
|
|
238
|
-
|
|
351
|
+
/** Internal origin sentinel: `null` = no frame scheduled yet. A `null`
|
|
352
|
+
* sentinel (not `0`) so a legitimate `AudioContext.currentTime` of exactly
|
|
353
|
+
* 0 at first-frame time still counts as initialized (debt internal-#90). */
|
|
354
|
+
private originTime: number | null = null;
|
|
239
355
|
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
|
|
356
|
+
/** Timestamp (AudioContext.currentTime) when the first frame started
|
|
357
|
+
* playing; 0 when no frame has played yet.
|
|
358
|
+
*
|
|
359
|
+
* Published-compat accessor pair over the null-sentinel `originTime`:
|
|
360
|
+
* external consumers (e.g. `VoiceSession.resetTurn`) read a plain number
|
|
361
|
+
* and write `0` to mean "reset for the next turn" — the setter maps that
|
|
362
|
+
* reset back onto the internal `null` sentinel. */
|
|
363
|
+
get playbackOrigin(): number {
|
|
364
|
+
return this.originTime ?? 0;
|
|
365
|
+
}
|
|
243
366
|
|
|
244
|
-
|
|
367
|
+
set playbackOrigin(value: number) {
|
|
368
|
+
this.originTime = value === 0 ? null : value;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Start time of the first audio frame in the current chunk; `null` = no
|
|
372
|
+
* frame has set it yet (same #90 null-sentinel rationale as `originTime`).
|
|
373
|
+
* Reset each time getChunkStartTime() is called (consumed by viseme scheduler). */
|
|
374
|
+
private chunkStartTime: number | null = null;
|
|
375
|
+
|
|
376
|
+
// ── AU.2b adaptive jitter buffer ──────────────────────────────────────
|
|
377
|
+
// Frames used to be scheduled at `max(currentTime, queuedTime)`: the very
|
|
378
|
+
// first frame of a run started IMMEDIATELY, so any 20–40 ms of network
|
|
379
|
+
// jitter on the next frame produced an audible gap (spec-K Fault B #2).
|
|
380
|
+
// Now every run start (first frame of a turn, or a restart after an
|
|
381
|
+
// underrun) is scheduled `jitterLeadS` in the future, buying that much
|
|
382
|
+
// jitter absorption; steady-state frames still chain at `queuedTime`.
|
|
383
|
+
// Each mid-stream underrun ADAPTIVELY grows the lead (bad network ⇒ more
|
|
384
|
+
// buffer, at the cost of latency), capped at MAX_JITTER_LEAD_S.
|
|
385
|
+
static readonly INITIAL_JITTER_LEAD_S = 0.06;
|
|
386
|
+
|
|
387
|
+
private jitterLeadS = AudioFramePlayer.INITIAL_JITTER_LEAD_S;
|
|
388
|
+
|
|
389
|
+
static readonly JITTER_LEAD_STEP_S = 0.02;
|
|
390
|
+
|
|
391
|
+
static readonly MAX_JITTER_LEAD_S = 0.2;
|
|
392
|
+
|
|
393
|
+
// ── AU.2d AudioBuffer pool ────────────────────────────────────────────
|
|
394
|
+
// TTS frames are fixed-size (SAMPLES_PER_FRAME) at 50 Hz; allocating a
|
|
395
|
+
// fresh AudioBuffer per frame churns ~50 allocations/s through the GC
|
|
396
|
+
// (spec-K Fault B #3). Finished sources return their buffer here for
|
|
397
|
+
// reuse; only exact-size buffers are pooled.
|
|
398
|
+
private bufferPool: AudioBuffer[] = [];
|
|
399
|
+
|
|
400
|
+
private static readonly MAX_POOLED_BUFFERS = 32;
|
|
401
|
+
|
|
402
|
+
/** statechange listener kept as a field so stop() can detach it — the
|
|
403
|
+
* context is the SHARED page singleton (AU.2a), so an orphaned listener
|
|
404
|
+
* from a stopped player must not keep firing. */
|
|
405
|
+
private readonly onStateChange = (): void => {
|
|
406
|
+
if (
|
|
407
|
+
this.context.state === 'running' &&
|
|
408
|
+
this.queuedTime < this.context.currentTime
|
|
409
|
+
) {
|
|
410
|
+
this.queuedTime = this.context.currentTime;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
245
413
|
|
|
246
414
|
constructor() {
|
|
247
|
-
|
|
415
|
+
// AU.2a: acquire the shared page-singleton context (iOS max-4 pool)
|
|
416
|
+
// instead of creating a per-player one.
|
|
417
|
+
this.context = acquireSharedAudioContext();
|
|
248
418
|
this.gainNode = this.context.createGain();
|
|
249
419
|
this.gainNode.connect(this.context.destination);
|
|
250
420
|
|
|
251
421
|
// Re-anchor queuedTime on AudioContext resume so post-suspension
|
|
252
422
|
// frames aren't scheduled in the past (mobile lock screen / tab
|
|
253
423
|
// background recovery). See docs/features/2026-05-10-audio-pipeline-safety-net.md.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
this.queuedTime < this.context.currentTime
|
|
258
|
-
) {
|
|
259
|
-
this.queuedTime = this.context.currentTime;
|
|
260
|
-
}
|
|
261
|
-
};
|
|
424
|
+
// addEventListener (not `onstatechange = …`) because the context is
|
|
425
|
+
// shared — assignment would clobber other listeners on the singleton.
|
|
426
|
+
this.context.addEventListener?.('statechange', this.onStateChange);
|
|
262
427
|
}
|
|
263
428
|
|
|
264
|
-
/** Return the playback time elapsed since the first frame was scheduled.
|
|
429
|
+
/** Return the playback time elapsed since the first frame was scheduled.
|
|
430
|
+
*
|
|
431
|
+
* §Q PLYR.5 — NEVER negative. `originTime` is the *scheduled* start of the
|
|
432
|
+
* turn's first frame, which can sit in the FUTURE, so the raw
|
|
433
|
+
* `currentTime - originTime` can go negative; staging captured a live
|
|
434
|
+
* session streaming `-61.148, -61.052, -60.948…` at ~10 Hz. Until the
|
|
435
|
+
* turn's audio is actually audible, the playhead INTO that turn is 0 —
|
|
436
|
+
* which is what the server's `is_speech_active` / `get_words_spoken_until`
|
|
437
|
+
* arithmetic (`api/chat/ws.py`) needs to stay truthful.
|
|
438
|
+
*
|
|
439
|
+
* §Q PLYR.6 removed the DRIVER of the big negatives (a new turn no longer
|
|
440
|
+
* chains behind the previous turn's backlog — `AudioPipeline.resetTurn`
|
|
441
|
+
* flushes it), leaving only the jitter lead in the future. The clamp stays
|
|
442
|
+
* as the floor: `startTime` is always `>= currentTime` by construction. */
|
|
265
443
|
getPlaybackTime(): number {
|
|
266
|
-
if (this.
|
|
267
|
-
return this.context.currentTime - this.
|
|
444
|
+
if (this.originTime === null) return 0;
|
|
445
|
+
return Math.max(0, this.context.currentTime - this.originTime);
|
|
268
446
|
}
|
|
269
447
|
|
|
270
448
|
/**
|
|
@@ -272,11 +450,36 @@ export class AudioFramePlayer {
|
|
|
272
450
|
* or 0 if no frame has played yet. Used by `AudioPipeline` to convert
|
|
273
451
|
* absolute chunk start times into the relative coordinate frame the
|
|
274
452
|
* playback tracker uses for word timestamps.
|
|
453
|
+
*
|
|
454
|
+
* NOTE: a return of 0 is ambiguous (unset vs a legitimate origin of
|
|
455
|
+
* exactly 0). Callers that need to distinguish must use
|
|
456
|
+
* {@link getPlaybackOriginOrNull} — this method stays for the published
|
|
457
|
+
* numeric surface.
|
|
275
458
|
*/
|
|
276
459
|
getPlaybackOrigin(): number {
|
|
277
460
|
return this.playbackOrigin;
|
|
278
461
|
}
|
|
279
462
|
|
|
463
|
+
/**
|
|
464
|
+
* Null-aware origin read (debt internal-#90): `null` = no frame has been
|
|
465
|
+
* scheduled yet; a `number` (including a legitimate `0`) = the recorded
|
|
466
|
+
* origin. `AudioPipeline.processAudioMetadata` uses this so an origin of
|
|
467
|
+
* exactly 0 is not conflated with "unset" in the word-timestamp math.
|
|
468
|
+
*/
|
|
469
|
+
getPlaybackOriginOrNull(): number | null {
|
|
470
|
+
return this.originTime;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Explicitly reset the playback origin for a new turn. Preferred over the
|
|
475
|
+
* legacy `playbackOrigin = 0` write (which the setter maps to the same
|
|
476
|
+
* reset) — this name states the intent and cannot collide with a
|
|
477
|
+
* legitimate computed origin of 0.
|
|
478
|
+
*/
|
|
479
|
+
resetPlaybackOrigin(): void {
|
|
480
|
+
this.originTime = null;
|
|
481
|
+
}
|
|
482
|
+
|
|
280
483
|
/** Expose the AudioContext for external time queries. */
|
|
281
484
|
getContext(): AudioContext {
|
|
282
485
|
return this.context;
|
|
@@ -291,9 +494,8 @@ export class AudioFramePlayer {
|
|
|
291
494
|
* Call this from the audio_metadata handler to schedule visemes at the
|
|
292
495
|
* correct time. Resets after each call so the next chunk gets a fresh start. */
|
|
293
496
|
getChunkStartTime(): number {
|
|
294
|
-
const t = this.chunkStartTime
|
|
295
|
-
this.chunkStartTime =
|
|
296
|
-
this.chunkStartTimeSet = false;
|
|
497
|
+
const t = this.chunkStartTime ?? this.getNextFrameStartTime();
|
|
498
|
+
this.chunkStartTime = null;
|
|
297
499
|
return t;
|
|
298
500
|
}
|
|
299
501
|
|
|
@@ -303,7 +505,7 @@ export class AudioFramePlayer {
|
|
|
303
505
|
* without binary, `getChunkStartTime()` falls back to `currentTime`,
|
|
304
506
|
* which anchors visemes to "now" instead of the actual chunk start. */
|
|
305
507
|
hasChunkStart(): boolean {
|
|
306
|
-
return this.
|
|
508
|
+
return this.chunkStartTime !== null;
|
|
307
509
|
}
|
|
308
510
|
|
|
309
511
|
async resume(): Promise<void> {
|
|
@@ -312,6 +514,45 @@ export class AudioFramePlayer {
|
|
|
312
514
|
}
|
|
313
515
|
}
|
|
314
516
|
|
|
517
|
+
/**
|
|
518
|
+
* Duck (or restore) persona TTS on the shared output gain — the mix point the
|
|
519
|
+
* player has always owned but never exposed.
|
|
520
|
+
*
|
|
521
|
+
* Hosts call `setDuck(AUDIO_TAKEOVER_DUCK_GAIN)` when a cutscene / world
|
|
522
|
+
* takeover becomes visible and `clearDuck()` when it is dismissed. The duck is
|
|
523
|
+
* a MIX setting, not playback state: it survives `clearQueue()`/`resetTurn()`
|
|
524
|
+
* so a barge-in or a turn boundary mid-takeover cannot silently restore full
|
|
525
|
+
* volume underneath a playing clip.
|
|
526
|
+
*
|
|
527
|
+
* @param gain clamped to `[0, 1]`; a non-finite value is ignored.
|
|
528
|
+
*/
|
|
529
|
+
setDuck(gain: number): void {
|
|
530
|
+
if (!Number.isFinite(gain)) return;
|
|
531
|
+
const target = Math.min(1, Math.max(0, gain));
|
|
532
|
+
this.duckGain = target;
|
|
533
|
+
const param = this.gainNode.gain;
|
|
534
|
+
const now = this.context.currentTime;
|
|
535
|
+
// Ramp when the platform offers one; fall back through the schedulers a
|
|
536
|
+
// minimal/mocked AudioParam may implement before assigning outright.
|
|
537
|
+
if (typeof param.setTargetAtTime === 'function') {
|
|
538
|
+
param.setTargetAtTime(target, now, AUDIO_DUCK_RAMP_TIME_CONSTANT_S);
|
|
539
|
+
} else if (typeof param.setValueAtTime === 'function') {
|
|
540
|
+
param.setValueAtTime(target, now);
|
|
541
|
+
} else {
|
|
542
|
+
param.value = target;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** Restore full persona-TTS volume — the takeover was dismissed. */
|
|
547
|
+
clearDuck(): void {
|
|
548
|
+
this.setDuck(1);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** The gain last requested via {@link setDuck} (1 = un-ducked). */
|
|
552
|
+
getDuck(): number {
|
|
553
|
+
return this.duckGain;
|
|
554
|
+
}
|
|
555
|
+
|
|
315
556
|
/** Immediately silence and stop all scheduled/playing audio. */
|
|
316
557
|
clearQueue(): void {
|
|
317
558
|
// Stopping each source is sufficient to silence playback — the
|
|
@@ -325,17 +566,37 @@ export class AudioFramePlayer {
|
|
|
325
566
|
}
|
|
326
567
|
this.activeSources.clear();
|
|
327
568
|
this.queuedTime = this.context.currentTime;
|
|
328
|
-
this.
|
|
329
|
-
this.chunkStartTime =
|
|
330
|
-
this.chunkStartTimeSet = false;
|
|
569
|
+
this.originTime = null;
|
|
570
|
+
this.chunkStartTime = null;
|
|
331
571
|
}
|
|
332
572
|
|
|
333
573
|
async stop(): Promise<void> {
|
|
334
574
|
// Reuse clearQueue so the source-stop loop only lives in one place,
|
|
335
|
-
// then zero out the queuedTime watermark and
|
|
575
|
+
// then zero out the queuedTime watermark and RELEASE the shared context
|
|
576
|
+
// (AU.2a — suspended at refcount 0, kept for reuse; closing a shared
|
|
577
|
+
// singleton would kill the mic and burn an iOS context slot).
|
|
336
578
|
this.clearQueue();
|
|
337
579
|
this.queuedTime = 0;
|
|
338
|
-
|
|
580
|
+
this.bufferPool = [];
|
|
581
|
+
this.context.removeEventListener?.('statechange', this.onStateChange);
|
|
582
|
+
releaseSharedAudioContext();
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** Pop a pooled AudioBuffer of exactly `length` frames, or allocate one. */
|
|
586
|
+
private acquireBuffer(length: number): AudioBuffer {
|
|
587
|
+
const pooled = this.bufferPool.pop();
|
|
588
|
+
if (pooled && pooled.length === length) {
|
|
589
|
+
return pooled;
|
|
590
|
+
}
|
|
591
|
+
// Wrong-size pooled buffer (shouldn't happen — frames are fixed-size):
|
|
592
|
+
// discard it and allocate fresh.
|
|
593
|
+
return this.context.createBuffer(1, length, SAMPLE_RATE);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
private recycleBuffer(buffer: AudioBuffer): void {
|
|
597
|
+
if (this.bufferPool.length < AudioFramePlayer.MAX_POOLED_BUFFERS) {
|
|
598
|
+
this.bufferPool.push(buffer);
|
|
599
|
+
}
|
|
339
600
|
}
|
|
340
601
|
|
|
341
602
|
playFrame(data: ArrayBuffer): void {
|
|
@@ -344,35 +605,59 @@ export class AudioFramePlayer {
|
|
|
344
605
|
return;
|
|
345
606
|
}
|
|
346
607
|
|
|
608
|
+
const buffer = this.acquireBuffer(audio.length);
|
|
609
|
+
// Reuse a scratch Float32Array per frame is not worth it — copyToChannel
|
|
610
|
+
// needs a Float32Array view anyway; the POOLED allocation is the
|
|
611
|
+
// AudioBuffer itself (the expensive audio-graph object, AU.2d).
|
|
347
612
|
const floatData = new Float32Array(audio.length);
|
|
348
613
|
for (let i = 0; i < audio.length; i += 1) {
|
|
349
614
|
floatData[i] = audio[i] / FLOAT_DIVISOR;
|
|
350
615
|
}
|
|
351
|
-
|
|
352
|
-
const buffer = this.context.createBuffer(1, floatData.length, SAMPLE_RATE);
|
|
353
616
|
buffer.copyToChannel(floatData, 0);
|
|
354
617
|
|
|
355
618
|
const source = this.context.createBufferSource();
|
|
356
619
|
source.buffer = buffer;
|
|
357
620
|
source.connect(this.gainNode);
|
|
358
621
|
|
|
359
|
-
// Track source so barge-in can stop it cleanly
|
|
622
|
+
// Track source so barge-in can stop it cleanly; recycle the buffer once
|
|
623
|
+
// the source finishes (or is stopped by clearQueue — onended fires for
|
|
624
|
+
// both), so steady-state playback allocates zero new AudioBuffers.
|
|
360
625
|
this.activeSources.add(source);
|
|
361
|
-
source.onended = () =>
|
|
626
|
+
source.onended = () => {
|
|
627
|
+
this.activeSources.delete(source);
|
|
628
|
+
this.recycleBuffer(buffer);
|
|
629
|
+
};
|
|
362
630
|
|
|
363
|
-
|
|
631
|
+
// AU.2b — adaptive jitter buffer. Steady state chains at queuedTime; a
|
|
632
|
+
// run (re)start schedules jitterLeadS ahead so network jitter on the
|
|
633
|
+
// following frames is absorbed instead of gapping. A RESTART of an
|
|
634
|
+
// in-progress turn (originTime already set ⇒ audio had started, but the
|
|
635
|
+
// queue drained before this frame arrived) is an underrun: grow the lead.
|
|
636
|
+
let startTime: number;
|
|
637
|
+
if (this.queuedTime > this.context.currentTime) {
|
|
638
|
+
startTime = this.queuedTime;
|
|
639
|
+
} else {
|
|
640
|
+
if (this.originTime !== null) {
|
|
641
|
+
this.jitterLeadS = Math.min(
|
|
642
|
+
AudioFramePlayer.MAX_JITTER_LEAD_S,
|
|
643
|
+
this.jitterLeadS + AudioFramePlayer.JITTER_LEAD_STEP_S,
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
startTime = this.context.currentTime + this.jitterLeadS;
|
|
647
|
+
}
|
|
364
648
|
|
|
365
|
-
// Record the origin time when the very first frame is scheduled
|
|
366
|
-
|
|
367
|
-
|
|
649
|
+
// Record the origin time when the very first frame is scheduled.
|
|
650
|
+
// Written to the internal field directly (not the setter) so a
|
|
651
|
+
// legitimate startTime of exactly 0 still counts as initialized (#90).
|
|
652
|
+
if (this.originTime === null) {
|
|
653
|
+
this.originTime = startTime;
|
|
368
654
|
}
|
|
369
655
|
|
|
370
656
|
// Track the start time of the first frame in this chunk.
|
|
371
657
|
// audio_metadata arrives AFTER the binary frames for the same chunk,
|
|
372
658
|
// so this captures the correct base time for viseme scheduling.
|
|
373
|
-
if (
|
|
659
|
+
if (this.chunkStartTime === null) {
|
|
374
660
|
this.chunkStartTime = startTime;
|
|
375
|
-
this.chunkStartTimeSet = true;
|
|
376
661
|
}
|
|
377
662
|
|
|
378
663
|
source.start(startTime);
|
|
@@ -397,6 +682,7 @@ export const buildHelloPayload = ({
|
|
|
397
682
|
entityId,
|
|
398
683
|
adventureSessionId,
|
|
399
684
|
partyPersonaIds,
|
|
685
|
+
audioCodecs,
|
|
400
686
|
}: {
|
|
401
687
|
videoId?: string;
|
|
402
688
|
personaId?: string;
|
|
@@ -439,6 +725,17 @@ export const buildHelloPayload = ({
|
|
|
439
725
|
* Matches `HelloMessage.partyPersonaIds` in `shared/audio_protocol.py`.
|
|
440
726
|
*/
|
|
441
727
|
partyPersonaIds?: string[];
|
|
728
|
+
/**
|
|
729
|
+
* AU.4 — codecs this client can speak, in preference order (e.g.
|
|
730
|
+
* `['opus', 'pcm16']`). Omit (undefined) to leave the field OFF the hello
|
|
731
|
+
* frame entirely — required against servers that predate the
|
|
732
|
+
* `HelloMessage.audioCodecs` widening (their `extra='forbid'` validation
|
|
733
|
+
* rejects unknown fields), and the land-dark default. Only pass this once
|
|
734
|
+
* the client actually ships an Opus encode/decode path; the negotiated
|
|
735
|
+
* result comes back on `hello_ack.negotiatedCodec`. Matches
|
|
736
|
+
* `HelloMessage.audioCodecs` in `shared/audio_protocol.py`.
|
|
737
|
+
*/
|
|
738
|
+
audioCodecs?: string[];
|
|
442
739
|
}) => ({
|
|
443
740
|
action: 'hello' as const,
|
|
444
741
|
version: HELLO_VERSION,
|
|
@@ -456,6 +753,7 @@ export const buildHelloPayload = ({
|
|
|
456
753
|
...(entityId ? { entityId } : {}),
|
|
457
754
|
...(adventureSessionId ? { adventureSessionId } : {}),
|
|
458
755
|
...(partyPersonaIds && partyPersonaIds.length > 0 ? { partyPersonaIds } : {}),
|
|
756
|
+
...(audioCodecs && audioCodecs.length > 0 ? { audioCodecs } : {}),
|
|
459
757
|
});
|
|
460
758
|
|
|
461
759
|
export type HelloPayload = ReturnType<typeof buildHelloPayload>;
|
|
@@ -694,6 +992,16 @@ export class AudioSessionClient {
|
|
|
694
992
|
*/
|
|
695
993
|
const SENTENCE_OVERLAP_EPSILON_S = 0.01;
|
|
696
994
|
|
|
995
|
+
/**
|
|
996
|
+
* Cap on the suspended-context frame queue (debt #88 follow-up). Frames are
|
|
997
|
+
* 20 ms each, so 150 ≈ 3 s of audio. While the AudioContext stays suspended
|
|
998
|
+
* (iOS/Chrome pre-gesture — `resume()` can stay pending indefinitely), a
|
|
999
|
+
* streaming reply would otherwise queue UNBOUNDED PCM in memory and then
|
|
1000
|
+
* burst-play the entire stale backlog on a late gesture. Drop-oldest: a very
|
|
1001
|
+
* late resume plays at most the freshest ~3 s instead of minutes-old audio.
|
|
1002
|
+
*/
|
|
1003
|
+
const MAX_PENDING_FRAMES = 150;
|
|
1004
|
+
|
|
697
1005
|
/** Walk a phoneme message from the back, return the last phoneme with
|
|
698
1006
|
* non-empty `phones`. Returns null only when every word is empty. */
|
|
699
1007
|
function findLastPhone(words: WordPhonemeInfo[]): PhonemeInfo | null {
|
|
@@ -744,16 +1052,101 @@ export class AudioPipeline {
|
|
|
744
1052
|
// 20–100 ms forward drift of visemes vs audio.
|
|
745
1053
|
private pendingMetadata: AudioMetadataMessage[] = [];
|
|
746
1054
|
|
|
747
|
-
|
|
1055
|
+
// Post-barge inbound-frame latch (AU.1a). `bargeIn()` only silences frames
|
|
1056
|
+
// that were ALREADY scheduled (`clearQueue()` stops active sources) — TTS
|
|
1057
|
+
// frames still in flight from the server arrive AFTER the flush and would
|
|
1058
|
+
// be scheduled and PLAY ("audio buffers still play back on barge-in").
|
|
1059
|
+
// While latched, inbound binary frames + audio_metadata are dropped. The
|
|
1060
|
+
// latch clears on the next turn boundary (`resetTurn()`, driven by the
|
|
1061
|
+
// next final transcript) or on `destroy()`.
|
|
1062
|
+
private barged = false;
|
|
1063
|
+
|
|
1064
|
+
// In-arrival-order event queue for the suspended-context burst (debt #88 +
|
|
1065
|
+
// the AU.2 fold of debt 20260710-suspended-burst-drain…). When the context
|
|
1066
|
+
// is suspended, frames AND audio_metadata are queued TOGETHER in arrival
|
|
1067
|
+
// order and replayed in that order once a SINGLE resume() resolves. The
|
|
1068
|
+
// earlier frames-only queue lost the frame↔metadata interleaving: a burst
|
|
1069
|
+
// spanning multiple chunks drained one metadata per frame landing, so a
|
|
1070
|
+
// later chunk's metadata could anchor to a mid-previous-chunk frame time.
|
|
1071
|
+
// Replaying in arrival order preserves the live-path per-chunk anchoring
|
|
1072
|
+
// (frames re-arm chunkStartTime, the chunk's own metadata consumes it).
|
|
1073
|
+
private pendingEvents: Array<
|
|
1074
|
+
| { kind: 'frame'; data: ArrayBuffer }
|
|
1075
|
+
| { kind: 'metadata'; msg: AudioMetadataMessage }
|
|
1076
|
+
> = [];
|
|
1077
|
+
|
|
1078
|
+
private pendingFrameCount = 0;
|
|
1079
|
+
|
|
1080
|
+
private resumeDrainInFlight = false;
|
|
1081
|
+
|
|
1082
|
+
/** AU.2a — last suspended-state value reported to `onPlaybackSuspended`,
|
|
1083
|
+
* so the callback fires only on transitions. */
|
|
1084
|
+
private suspendedNotified = false;
|
|
1085
|
+
|
|
1086
|
+
private readonly onPlaybackSuspended?: (suspended: boolean) => void;
|
|
1087
|
+
|
|
1088
|
+
constructor(
|
|
1089
|
+
onVisemeChange: (viseme: string) => void,
|
|
1090
|
+
options?: {
|
|
1091
|
+
/**
|
|
1092
|
+
* AU.2a — fired with `true` when TTS frames are piling up behind a
|
|
1093
|
+
* suspended AudioContext (the iOS "mic looks live, audio is silent"
|
|
1094
|
+
* state: reconnect re-armed audio outside a user gesture, so
|
|
1095
|
+
* `resume()` hangs until the next gesture), and with `false` once
|
|
1096
|
+
* playback drains. Hosts use it to show a tap-to-restore overlay whose
|
|
1097
|
+
* tap handler calls {@link resume} synchronously in the gesture.
|
|
1098
|
+
*/
|
|
1099
|
+
onPlaybackSuspended?: (suspended: boolean) => void;
|
|
1100
|
+
},
|
|
1101
|
+
) {
|
|
748
1102
|
this.player = new AudioFramePlayer();
|
|
749
1103
|
this.visemeScheduler = new VisemeScheduler(
|
|
750
1104
|
this.player.getContext(),
|
|
751
1105
|
onVisemeChange,
|
|
752
1106
|
);
|
|
1107
|
+
this.onPlaybackSuspended = options?.onPlaybackSuspended;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
private notifySuspended(suspended: boolean): void {
|
|
1111
|
+
if (this.suspendedNotified === suspended) return;
|
|
1112
|
+
this.suspendedNotified = suspended;
|
|
1113
|
+
this.onPlaybackSuspended?.(suspended);
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* AU.2a — probe the (shared) AudioContext and fire `onPlaybackSuspended`
|
|
1118
|
+
* per its live state. Hosts call this after a reconnect re-arm: on iOS the
|
|
1119
|
+
* gesture-less `resume()` can stay pending forever, so the awaited arm
|
|
1120
|
+
* never returns and only an external probe can surface the tap-to-restore
|
|
1121
|
+
* overlay. Transition-guarded — safe to call repeatedly.
|
|
1122
|
+
*/
|
|
1123
|
+
notifyIfSuspended(): void {
|
|
1124
|
+
this.notifySuspended(this.player.getContext().state === 'suspended');
|
|
753
1125
|
}
|
|
754
1126
|
|
|
1127
|
+
/**
|
|
1128
|
+
* Resume the player's (shared) AudioContext and drain any queued
|
|
1129
|
+
* suspended-burst events. Callers restoring audio from a user gesture
|
|
1130
|
+
* (the AU.2a tap-to-restore overlay) MUST call this synchronously inside
|
|
1131
|
+
* the gesture handler — the underlying `resume()` is what iOS gates.
|
|
1132
|
+
*/
|
|
755
1133
|
async resume(): Promise<void> {
|
|
756
1134
|
await this.player.resume();
|
|
1135
|
+
this.drainPendingEvents();
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* §Q DM.1 — duck persona TTS under a visual takeover (cutscene clip / world
|
|
1140
|
+
* stream). Delegates to {@link AudioFramePlayer.setDuck}; hosts drive the
|
|
1141
|
+
* pipeline, not the player, so this is the surface they reach for.
|
|
1142
|
+
*/
|
|
1143
|
+
setDuck(gain: number): void {
|
|
1144
|
+
this.player.setDuck(gain);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/** Restore full persona-TTS volume after a takeover is dismissed. */
|
|
1148
|
+
clearDuck(): void {
|
|
1149
|
+
this.player.clearDuck();
|
|
757
1150
|
}
|
|
758
1151
|
|
|
759
1152
|
/**
|
|
@@ -776,52 +1169,147 @@ export class AudioPipeline {
|
|
|
776
1169
|
this._sessionClient.setAudioPlayer(this.player);
|
|
777
1170
|
}
|
|
778
1171
|
|
|
779
|
-
/**
|
|
780
|
-
|
|
1172
|
+
/**
|
|
1173
|
+
* Handle an incoming binary TTS audio frame.
|
|
1174
|
+
*
|
|
1175
|
+
* Returns `true` when the frame was accepted (played or queued for the
|
|
1176
|
+
* resume drain), `false` when it was DROPPED (post-barge latch or closed
|
|
1177
|
+
* context). Consumers use the return to avoid asserting UI state (e.g.
|
|
1178
|
+
* "speaking") for audio that will never play. Additive — existing callers
|
|
1179
|
+
* that ignore the return are unchanged.
|
|
1180
|
+
*/
|
|
1181
|
+
handleBinaryFrame(data: ArrayBuffer): boolean {
|
|
781
1182
|
try {
|
|
1183
|
+
// Post-barge latch: drop in-flight frames for the interrupted reply.
|
|
1184
|
+
// Re-armed by `resetTurn()` at the next turn boundary.
|
|
1185
|
+
if (this.barged) {
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
782
1188
|
const state = this.player.getContext().state;
|
|
783
1189
|
// 'closed' shouldn't normally happen here because callers go
|
|
784
1190
|
// through `destroy()` before letting the context close, but a
|
|
785
1191
|
// stray frame after a teardown race would crash `playFrame` with
|
|
786
1192
|
// an InvalidStateError. Drop it explicitly.
|
|
787
1193
|
if (state === 'closed') {
|
|
788
|
-
return;
|
|
1194
|
+
return false;
|
|
789
1195
|
}
|
|
790
|
-
if (state === 'running') {
|
|
791
|
-
this.
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
// position before the frame even reaches the audio graph.
|
|
813
|
-
this.updateTrackerPosition();
|
|
814
|
-
this.drainPendingMetadata();
|
|
815
|
-
})
|
|
816
|
-
.catch((err) =>
|
|
817
|
-
console.error('[AudioPipeline] Failed to resume audio:', err),
|
|
818
|
-
);
|
|
1196
|
+
if (state === 'running' && this.pendingEvents.length === 0) {
|
|
1197
|
+
this.playFrameNow(data);
|
|
1198
|
+
return true;
|
|
1199
|
+
}
|
|
1200
|
+
// Suspended-context path (typical: first frame before any user
|
|
1201
|
+
// gesture) — or a running context whose resume-drain hasn't emptied
|
|
1202
|
+
// the queue yet (ordering: a frame must never jump ahead of queued
|
|
1203
|
+
// predecessors). Queue in arrival order; a single resume() drains
|
|
1204
|
+
// the queue in order when it resolves (debt #88 — the previous
|
|
1205
|
+
// per-frame `.then()` chains raced and could reorder frames).
|
|
1206
|
+
// Bounded drop-oldest so a never-resuming context can't accumulate
|
|
1207
|
+
// unbounded PCM (see MAX_PENDING_FRAMES).
|
|
1208
|
+
this.pendingEvents.push({ kind: 'frame', data });
|
|
1209
|
+
this.pendingFrameCount += 1;
|
|
1210
|
+
this.trimPendingEvents();
|
|
1211
|
+
// AU.2a — a frame stuck behind a suspended context is exactly the
|
|
1212
|
+
// "mic live, audio silent" state; let the host show tap-to-restore.
|
|
1213
|
+
if (state === 'suspended') {
|
|
1214
|
+
this.notifySuspended(true);
|
|
1215
|
+
}
|
|
1216
|
+
if (this.resumeDrainInFlight) {
|
|
1217
|
+
return true;
|
|
819
1218
|
}
|
|
1219
|
+
this.resumeDrainInFlight = true;
|
|
1220
|
+
this.player
|
|
1221
|
+
.resume()
|
|
1222
|
+
.then(() => {
|
|
1223
|
+
this.resumeDrainInFlight = false;
|
|
1224
|
+
// Drain INSIDE then() so position reads are taken after each
|
|
1225
|
+
// playFrame schedules — outside, we'd write stale positions
|
|
1226
|
+
// before the frames even reach the audio graph.
|
|
1227
|
+
this.drainPendingEvents();
|
|
1228
|
+
})
|
|
1229
|
+
.catch((err) => {
|
|
1230
|
+
this.resumeDrainInFlight = false;
|
|
1231
|
+
// Drop the queued events — parity with the previous per-frame
|
|
1232
|
+
// behavior (a rejected resume() lost that frame). Retaining them
|
|
1233
|
+
// would burst-play a STALE backlog whenever a much-later frame or
|
|
1234
|
+
// gesture finally drains the queue — the very symptom AU.1 fixes.
|
|
1235
|
+
this.clearPendingEvents();
|
|
1236
|
+
console.error('[AudioPipeline] Failed to resume audio:', err);
|
|
1237
|
+
});
|
|
1238
|
+
return true;
|
|
820
1239
|
} catch (err) {
|
|
821
1240
|
console.error('[AudioPipeline] Failed to play audio frame:', err);
|
|
1241
|
+
// `false` strictly means "deliberately dropped" (latch/closed). An
|
|
1242
|
+
// unexpected play error is still an ACCEPTED frame — consumers keep
|
|
1243
|
+
// their pre-AU.1 behavior (e.g. asserting "speaking") for it.
|
|
1244
|
+
return true;
|
|
822
1245
|
}
|
|
823
1246
|
}
|
|
824
1247
|
|
|
1248
|
+
/** Schedule one frame and run the per-frame bookkeeping (tracker + metadata). */
|
|
1249
|
+
private playFrameNow(data: ArrayBuffer): void {
|
|
1250
|
+
this.player.playFrame(data);
|
|
1251
|
+
this.updateTrackerPosition();
|
|
1252
|
+
this.drainPendingMetadata();
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
/** Reset the burst queue + its frame counter (single reset site). */
|
|
1256
|
+
private clearPendingEvents(): void {
|
|
1257
|
+
this.pendingEvents = [];
|
|
1258
|
+
this.pendingFrameCount = 0;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/** Drop-oldest cap on queued burst FRAMES (metadata rides along: when a
|
|
1262
|
+
* frame is dropped, any metadata queued BEFORE the next surviving frame
|
|
1263
|
+
* belongs to a dropped chunk and is dropped with it — otherwise the
|
|
1264
|
+
* drain would anchor that stale metadata to the next SURVIVING chunk's
|
|
1265
|
+
* first frame, corrupting visemes/word timestamps; codex P2 on #727). */
|
|
1266
|
+
private trimPendingEvents(): void {
|
|
1267
|
+
if (this.pendingFrameCount <= MAX_PENDING_FRAMES) return;
|
|
1268
|
+
while (this.pendingFrameCount > MAX_PENDING_FRAMES) {
|
|
1269
|
+
const dropped = this.pendingEvents.shift();
|
|
1270
|
+
if (dropped === undefined) {
|
|
1271
|
+
this.pendingFrameCount = 0;
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
if (dropped.kind === 'frame') {
|
|
1275
|
+
this.pendingFrameCount -= 1;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
// Strip metadata now stranded at the front: it followed a dropped frame,
|
|
1279
|
+
// so it describes a dropped chunk. (An ASYNC metadata-first message for
|
|
1280
|
+
// the next surviving chunk is indistinguishable without frame chunk-ids;
|
|
1281
|
+
// in this pathological >3 s-flood path, dropping is the safe choice —
|
|
1282
|
+
// missing visemes beat wrongly-anchored ones.)
|
|
1283
|
+
while (this.pendingEvents[0]?.kind === 'metadata') {
|
|
1284
|
+
this.pendingEvents.shift();
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/** Drain queued suspended-burst events in arrival order (debt #88; AU.2
|
|
1289
|
+
* extends the queue to carry metadata too, preserving frame↔metadata
|
|
1290
|
+
* interleaving so multi-chunk bursts anchor each chunk's visemes/word
|
|
1291
|
+
* timestamps at that chunk's own first frame). */
|
|
1292
|
+
private drainPendingEvents(): void {
|
|
1293
|
+
while (this.pendingEvents.length > 0) {
|
|
1294
|
+
// A barge-in may have landed while resume() was in flight — the
|
|
1295
|
+
// queued events belong to the interrupted reply, drop them all.
|
|
1296
|
+
if (this.barged) {
|
|
1297
|
+
this.clearPendingEvents();
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
const event = this.pendingEvents.shift();
|
|
1301
|
+
if (event === undefined) continue;
|
|
1302
|
+
if (event.kind === 'frame') {
|
|
1303
|
+
this.pendingFrameCount -= 1;
|
|
1304
|
+
this.playFrameNow(event.data);
|
|
1305
|
+
} else {
|
|
1306
|
+
this.routeAudioMetadata(event.msg);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
// Queue fully replayed — playback is live again (AU.2a).
|
|
1310
|
+
this.notifySuspended(false);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
825
1313
|
/**
|
|
826
1314
|
* Push the current playhead into the session's playback tracker in the
|
|
827
1315
|
* same coordinate frame everything else uses (relative — elapsed since
|
|
@@ -843,7 +1331,29 @@ export class AudioPipeline {
|
|
|
843
1331
|
* would fall back to `AudioContext.currentTime`, anchoring visemes ~20–
|
|
844
1332
|
* 100 ms ahead of the audio. Buffer until a binary frame lands and the
|
|
845
1333
|
* real chunk start is known. */
|
|
846
|
-
handleAudioMetadata(msg: AudioMetadataMessage):
|
|
1334
|
+
handleAudioMetadata(msg: AudioMetadataMessage): boolean {
|
|
1335
|
+
// Post-barge latch: metadata for the interrupted reply's audio must not
|
|
1336
|
+
// schedule visemes (its frames are dropped too — see handleBinaryFrame).
|
|
1337
|
+
// Returns false when dropped (same contract as handleBinaryFrame).
|
|
1338
|
+
if (this.barged) {
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
// Suspended-burst path (AU.2 fold of the multi-chunk anchoring debt):
|
|
1342
|
+
// while frames are queued behind a suspended context, metadata must NOT
|
|
1343
|
+
// bypass them into pendingMetadata — it queues INLINE so the drain
|
|
1344
|
+
// replays the exact arrival interleaving and each chunk's metadata
|
|
1345
|
+
// anchors at that chunk's own first frame.
|
|
1346
|
+
if (this.pendingEvents.length > 0) {
|
|
1347
|
+
this.pendingEvents.push({ kind: 'metadata', msg });
|
|
1348
|
+
return true;
|
|
1349
|
+
}
|
|
1350
|
+
this.routeAudioMetadata(msg);
|
|
1351
|
+
return true;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
/** Live-path metadata routing: buffer until the chunk's first binary frame
|
|
1355
|
+
* has landed (Inworld ASYNC mode), else process immediately. */
|
|
1356
|
+
private routeAudioMetadata(msg: AudioMetadataMessage): void {
|
|
847
1357
|
if (!this.player.hasChunkStart()) {
|
|
848
1358
|
this.pendingMetadata.push(msg);
|
|
849
1359
|
return;
|
|
@@ -879,7 +1389,11 @@ export class AudioPipeline {
|
|
|
879
1389
|
// frames), fall back to chunkStartTime so the very-first-chunk math
|
|
880
1390
|
// still produces a 0-based offset.
|
|
881
1391
|
if (msg.wordTimestamps?.length && this.sessionClient) {
|
|
882
|
-
|
|
1392
|
+
// Null-aware read (debt #90): `??` — NOT `||` — so a legitimate
|
|
1393
|
+
// origin of exactly 0 anchors correctly instead of falling back to
|
|
1394
|
+
// this chunk's own start (which would zero out chunkRelativeStart
|
|
1395
|
+
// for every later chunk and mis-anchor all word timestamps).
|
|
1396
|
+
const origin = this.player.getPlaybackOriginOrNull() ?? chunkStartTime;
|
|
883
1397
|
const chunkRelativeStart = chunkStartTime - origin;
|
|
884
1398
|
this.sessionClient.addWordTimestamps(
|
|
885
1399
|
msg.wordTimestamps.map((ts) => ({
|
|
@@ -929,11 +1443,36 @@ export class AudioPipeline {
|
|
|
929
1443
|
}
|
|
930
1444
|
}
|
|
931
1445
|
|
|
932
|
-
/**
|
|
933
|
-
|
|
1446
|
+
/**
|
|
1447
|
+
* Clear the turn-scoped buffers/anchors shared by `resetTurn()`,
|
|
1448
|
+
* `bargeIn()`, and `destroy()` — the SINGLE reset site so a future
|
|
1449
|
+
* turn-scoped field can't be cleared in one place and leak in another.
|
|
1450
|
+
* The `barged` latch is deliberately NOT touched here: bargeIn() keeps it
|
|
1451
|
+
* set, resetTurn()/destroy() clear it explicitly.
|
|
1452
|
+
*/
|
|
1453
|
+
private clearTurnBuffers(): void {
|
|
934
1454
|
this.sentenceStartTime = null;
|
|
935
1455
|
this.lastPhonemeEnd = 0;
|
|
936
1456
|
this.pendingMetadata = [];
|
|
1457
|
+
this.clearPendingEvents();
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/** Reset state for a new conversational turn.
|
|
1461
|
+
*
|
|
1462
|
+
* Deliberately does NOT touch the player's queue (§Q PLYR.6, codex P1 on
|
|
1463
|
+
* #1514). Each consumer drives this from its OWN view of the turn boundary
|
|
1464
|
+
* and they disagree about when that is: the Vue surfaces call it on the
|
|
1465
|
+
* `done` frame (`../Web-App` `ai-integration-seer.vue:69`) and on the first
|
|
1466
|
+
* token of a new assistant message (`seer-ai-chat.vue:835`) — `done` lands
|
|
1467
|
+
* while most of that reply's audio is still scheduled, so flushing here
|
|
1468
|
+
* would truncate every reply on those surfaces. The PLYR.6 flush belongs to
|
|
1469
|
+
* the SERVER-authoritative boundary only, and lives in
|
|
1470
|
+
* `VoiceSession.resetTurn()` (driven by `turn_start`), which is the one
|
|
1471
|
+
* caller that knows the queued audio is stale. */
|
|
1472
|
+
resetTurn(): void {
|
|
1473
|
+
this.clearTurnBuffers();
|
|
1474
|
+
// Re-arm playback: the new turn's audio is legitimate.
|
|
1475
|
+
this.barged = false;
|
|
937
1476
|
this.sessionClient?.resetForNewTurn();
|
|
938
1477
|
}
|
|
939
1478
|
|
|
@@ -943,14 +1482,19 @@ export class AudioPipeline {
|
|
|
943
1482
|
* When a session is attached, delegates to `AudioSessionClient.bargeIn()`
|
|
944
1483
|
* which sends the `barge_in` WebSocket action to the server, clears the
|
|
945
1484
|
* player queue, stops position tracking, and resets the playback tracker.
|
|
946
|
-
* Without a session we still clear local audio/visemes
|
|
947
|
-
*
|
|
948
|
-
*
|
|
1485
|
+
* Without a session we still clear local audio/visemes AND latch (the
|
|
1486
|
+
* server has no way to know, but any further chunks it streams for this
|
|
1487
|
+
* turn are DROPPED by the latch until `resetTurn()` re-arms playback —
|
|
1488
|
+
* AU.1a changed the old "the next chunk resumes playback" behavior).
|
|
949
1489
|
*
|
|
950
1490
|
* Returns the `InterruptResult` describing what was spoken when a session
|
|
951
1491
|
* is attached; returns null when there is no session.
|
|
952
1492
|
*/
|
|
953
1493
|
async bargeIn(): Promise<InterruptResult | null> {
|
|
1494
|
+
// Latch FIRST so a frame racing in while the (async) session barge-in
|
|
1495
|
+
// runs is dropped rather than scheduled (AU.1a). Cleared by resetTurn().
|
|
1496
|
+
this.barged = true;
|
|
1497
|
+
this.clearPendingEvents();
|
|
954
1498
|
let result: InterruptResult | null = null;
|
|
955
1499
|
if (this.sessionClient) {
|
|
956
1500
|
result = await this.sessionClient.bargeIn();
|
|
@@ -958,21 +1502,38 @@ export class AudioPipeline {
|
|
|
958
1502
|
this.player.clearQueue();
|
|
959
1503
|
}
|
|
960
1504
|
this.visemeScheduler.clear();
|
|
961
|
-
this.
|
|
962
|
-
this.lastPhonemeEnd = 0;
|
|
963
|
-
this.pendingMetadata = [];
|
|
1505
|
+
this.clearTurnBuffers();
|
|
964
1506
|
return result;
|
|
965
1507
|
}
|
|
966
1508
|
|
|
1509
|
+
/**
|
|
1510
|
+
* AU.3 — server-initiated flush (`{type:'tts_flush'}`): the server already
|
|
1511
|
+
* arbitrated a barge-in (auto barge-in via Deepgram StartOfTurn, or the
|
|
1512
|
+
* server echoing a button barge), so drop local audio/visemes and LATCH —
|
|
1513
|
+
* exactly `bargeIn()` minus the client→server `barge_in` send (sending it
|
|
1514
|
+
* back would double-cancel the NEXT turn's TTS context). Idempotent: a
|
|
1515
|
+
* second flush (e.g. button + server echo) is a no-op on empty queues.
|
|
1516
|
+
* The latch clears on the next server `turn_start` (`resetTurn()`).
|
|
1517
|
+
*/
|
|
1518
|
+
serverFlush(): void {
|
|
1519
|
+
this.barged = true;
|
|
1520
|
+
this.clearPendingEvents();
|
|
1521
|
+
this.player.clearQueue();
|
|
1522
|
+
// Mirror `AudioSessionClient.bargeIn()`'s local half: stop position
|
|
1523
|
+
// tracking + reset the word tracker for the next turn.
|
|
1524
|
+
this.sessionClient?.resetForNewTurn();
|
|
1525
|
+
this.visemeScheduler.clear();
|
|
1526
|
+
this.clearTurnBuffers();
|
|
1527
|
+
}
|
|
1528
|
+
|
|
967
1529
|
/** Clean up all resources. */
|
|
968
1530
|
async destroy(): Promise<void> {
|
|
969
1531
|
this._sessionClient?.cleanup();
|
|
970
1532
|
this._sessionClient = null;
|
|
971
1533
|
this.visemeScheduler.destroy();
|
|
972
1534
|
await this.player.stop();
|
|
973
|
-
this.
|
|
974
|
-
this.
|
|
975
|
-
this.pendingMetadata = [];
|
|
1535
|
+
this.clearTurnBuffers();
|
|
1536
|
+
this.barged = false;
|
|
976
1537
|
}
|
|
977
1538
|
}
|
|
978
1539
|
|