@escapeaihq/client-core 0.52.0 → 0.139.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 +10295 -2216
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +4187 -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 +13 -0
- package/dist/conversation/binding.d.ts.map +1 -1
- 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 +44 -0
- package/dist/conversation/controller.d.ts.map +1 -1
- package/dist/conversation/controller.js +82 -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 +138 -0
- package/dist/domains/personas.d.ts.map +1 -0
- package/dist/domains/personas.js +322 -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 +395 -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.map +1 -1
- package/dist/reactor/dmSceneControlPrompt.js +64 -2
- package/dist/reactor/dmSceneControlPrompt.js.map +1 -1
- 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 +19 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +78 -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 +42 -3
- 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.map +1 -1
- package/dist/reactor/toolPromptAddon.js +16 -2
- 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 +58 -10
- package/dist/toolSchemas.d.ts.map +1 -1
- package/dist/toolSchemas.js +37 -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 +273 -10
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +79 -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/chatSessionStore.test.ts +243 -0
- package/src/__tests__/conversation/controller.test.ts +211 -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 +208 -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 +79 -0
- 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-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-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 +12687 -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 +13 -0
- package/src/conversation/chatSessionStore.ts +281 -0
- package/src/conversation/controller.ts +96 -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 +440 -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 +1016 -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 +69 -2
- 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 +78 -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 +81 -3
- 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 +16 -2
- 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 +40 -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 +361 -12
- package/src/workflowAuthoring.ts +664 -0
package/dist/audio.js
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import { BYTES_PER_SAMPLE, HELLO_VERSION, SAMPLE_RATE, SAMPLES_PER_FRAME, TAG_AI, TAG_MIC, encodeAudioFrame, decodeAudioFrame, buildBargeInMessage, buildPlaybackPositionMessage, } from './audioProtocol.js';
|
|
2
2
|
import { VisemeScheduler } from './visemeScheduler.js';
|
|
3
|
+
import { resampleToTarget } from './audioDsp.js';
|
|
4
|
+
import { acquireSharedAudioContext, releaseSharedAudioContext, } from './sharedAudioContext.js';
|
|
3
5
|
const FLOAT_DIVISOR = 32768;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const output = new Float32Array(targetLength);
|
|
19
|
-
for (let i = 0; i < targetLength; i += 1) {
|
|
20
|
-
const origin = i / ratio;
|
|
21
|
-
const index = Math.floor(origin);
|
|
22
|
-
const nextIndex = Math.min(index + 1, input.length - 1);
|
|
23
|
-
const weight = origin - index;
|
|
24
|
-
output[i] = input[index] * (1 - weight) + input[nextIndex] * weight;
|
|
25
|
-
}
|
|
26
|
-
return floatTo16BitPCM(output);
|
|
6
|
+
/**
|
|
7
|
+
* The ONE mic-capture constraint set (AU.3). `echoCancellation: true` is
|
|
8
|
+
* LOAD-BEARING for auto barge-in: the server treats any Deepgram
|
|
9
|
+
* `StartOfTurn` during assistant speech as the user interrupting, so the
|
|
10
|
+
* persona's own TTS leaking into the mic would self-trigger barge-ins.
|
|
11
|
+
* Pinned by a unit test — do not weaken without re-testing auto barge-in
|
|
12
|
+
* on speakerphone/laptop-speaker setups.
|
|
13
|
+
*/
|
|
14
|
+
export const MIC_AUDIO_CONSTRAINTS = {
|
|
15
|
+
echoCancellation: true,
|
|
16
|
+
noiseSuppression: true,
|
|
17
|
+
channelCount: 1,
|
|
18
|
+
sampleRate: SAMPLE_RATE,
|
|
19
|
+
sampleSize: BYTES_PER_SAMPLE * 8,
|
|
27
20
|
};
|
|
28
21
|
export class MicrophoneRecorder {
|
|
29
22
|
onFrame;
|
|
@@ -47,12 +40,13 @@ export class MicrophoneRecorder {
|
|
|
47
40
|
* `start()`'s own internal `prime()` runs after the gesture has
|
|
48
41
|
* unwound and iOS leaves the context in `suspended` state.
|
|
49
42
|
*
|
|
50
|
-
* No I/O, no awaits, no permission prompts — just
|
|
51
|
-
*
|
|
43
|
+
* No I/O, no awaits, no permission prompts — just an acquire of the shared
|
|
44
|
+
* page-singleton context (AU.2a: iOS caps a page at 4 live AudioContexts;
|
|
45
|
+
* the recorder and player now SHARE one) and a fire-and-forget `resume()`. */
|
|
52
46
|
prime() {
|
|
53
47
|
if (this.audioContext)
|
|
54
48
|
return;
|
|
55
|
-
this.audioContext =
|
|
49
|
+
this.audioContext = acquireSharedAudioContext();
|
|
56
50
|
void this.audioContext.resume();
|
|
57
51
|
}
|
|
58
52
|
async start() {
|
|
@@ -71,21 +65,15 @@ export class MicrophoneRecorder {
|
|
|
71
65
|
this.prime();
|
|
72
66
|
try {
|
|
73
67
|
this.mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
74
|
-
audio:
|
|
75
|
-
echoCancellation: true,
|
|
76
|
-
noiseSuppression: true,
|
|
77
|
-
channelCount: 1,
|
|
78
|
-
sampleRate: SAMPLE_RATE,
|
|
79
|
-
sampleSize: BYTES_PER_SAMPLE * 8,
|
|
80
|
-
},
|
|
68
|
+
audio: MIC_AUDIO_CONSTRAINTS,
|
|
81
69
|
});
|
|
82
70
|
}
|
|
83
71
|
catch (err) {
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
72
|
+
// Release our hold on the shared context so a permission denial
|
|
73
|
+
// doesn't leak a refcount, and a retry from a fresh user gesture
|
|
74
|
+
// starts clean (the singleton itself is retained for reuse — AU.2a).
|
|
87
75
|
if (this.audioContext) {
|
|
88
|
-
|
|
76
|
+
releaseSharedAudioContext();
|
|
89
77
|
this.audioContext = null;
|
|
90
78
|
}
|
|
91
79
|
const message = err instanceof Error ? err.message : 'Microphone permission denied';
|
|
@@ -116,6 +104,14 @@ export class MicrophoneRecorder {
|
|
|
116
104
|
// Guard: worklet message can arrive after stop() has nulled the context
|
|
117
105
|
if (!this.audioContext)
|
|
118
106
|
return;
|
|
107
|
+
// AU.2c — an updated worklet processor resamples + anti-alias filters
|
|
108
|
+
// OFF the main thread and posts wire-ready Int16 PCM. A stale cached
|
|
109
|
+
// processor (or a host app serving the old asset) still posts raw
|
|
110
|
+
// Float32 at the context rate; keep the main-thread fallback for it.
|
|
111
|
+
if (event.data instanceof Int16Array) {
|
|
112
|
+
this.enqueueSamples(event.data);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
119
115
|
const pcm = resampleToTarget(event.data, this.audioContext.sampleRate);
|
|
120
116
|
this.enqueueSamples(pcm);
|
|
121
117
|
};
|
|
@@ -161,7 +157,9 @@ export class MicrophoneRecorder {
|
|
|
161
157
|
this.source = null;
|
|
162
158
|
}
|
|
163
159
|
if (this.audioContext) {
|
|
164
|
-
|
|
160
|
+
// AU.2a: release the shared singleton (suspended at refcount 0, never
|
|
161
|
+
// closed) instead of closing a per-recorder context.
|
|
162
|
+
releaseSharedAudioContext();
|
|
165
163
|
this.audioContext = null;
|
|
166
164
|
}
|
|
167
165
|
if (this.mediaStream) {
|
|
@@ -184,46 +182,225 @@ export class MicrophoneRecorder {
|
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
}
|
|
185
|
+
/** Default RMS threshold (normalized 0..1) above which a mic frame counts as
|
|
186
|
+
* voiced. Post-echoCancellation TTS residue and room noise sit well below
|
|
187
|
+
* this; normal speech at conversational distance sits well above. */
|
|
188
|
+
const MIC_VAD_DEFAULT_THRESHOLD = 0.015;
|
|
189
|
+
/** Consecutive voiced frames (20 ms each) required before `speaking` flips
|
|
190
|
+
* true — the AU.3 VAD-assist DEBOUNCE (~100 ms) so clicks/pops don't flash
|
|
191
|
+
* the "listening/interrupting" affordance. */
|
|
192
|
+
const MIC_VAD_DEFAULT_ATTACK_FRAMES = 5;
|
|
193
|
+
/** Consecutive silent frames before `speaking` flips false (~500 ms hangover
|
|
194
|
+
* so natural inter-word gaps don't flicker the affordance). */
|
|
195
|
+
const MIC_VAD_DEFAULT_RELEASE_FRAMES = 25;
|
|
196
|
+
/**
|
|
197
|
+
* AU.3 — tiny energy-based voice-activity detector over the outbound mic
|
|
198
|
+
* frames (the same tagged PCM16 frames `MicrophoneRecorder` emits). CLIENT
|
|
199
|
+
* AFFORDANCE ONLY: the authoritative barge-in decision is server-side
|
|
200
|
+
* (Deepgram StartOfTurn); this just debounces a local "the user is speaking"
|
|
201
|
+
* signal so hosts can show a listening/interrupting indicator without a
|
|
202
|
+
* server round-trip. Framework-agnostic, no audio-graph dependency.
|
|
203
|
+
*/
|
|
204
|
+
export class MicVad {
|
|
205
|
+
onChange;
|
|
206
|
+
voicedRun = 0;
|
|
207
|
+
silentRun = 0;
|
|
208
|
+
isSpeaking = false;
|
|
209
|
+
threshold;
|
|
210
|
+
attackFrames;
|
|
211
|
+
releaseFrames;
|
|
212
|
+
constructor(onChange, options = {}) {
|
|
213
|
+
this.onChange = onChange;
|
|
214
|
+
this.threshold = options.threshold ?? MIC_VAD_DEFAULT_THRESHOLD;
|
|
215
|
+
this.attackFrames = options.attackFrames ?? MIC_VAD_DEFAULT_ATTACK_FRAMES;
|
|
216
|
+
this.releaseFrames = options.releaseFrames ?? MIC_VAD_DEFAULT_RELEASE_FRAMES;
|
|
217
|
+
}
|
|
218
|
+
get speaking() {
|
|
219
|
+
return this.isSpeaking;
|
|
220
|
+
}
|
|
221
|
+
/** Feed one outbound mic frame (tag byte + PCM16LE, as produced by
|
|
222
|
+
* `encodeAudioFrame(TAG_MIC, …)`). Fires `onChange` on debounced
|
|
223
|
+
* speech-start/speech-end transitions. */
|
|
224
|
+
push(frame) {
|
|
225
|
+
// Skip the 1-byte tag; read aligned PCM16LE samples.
|
|
226
|
+
const byteLength = frame.byteLength - 1;
|
|
227
|
+
const sampleCount = Math.floor(byteLength / 2);
|
|
228
|
+
if (sampleCount <= 0)
|
|
229
|
+
return;
|
|
230
|
+
const view = new DataView(frame.buffer, frame.byteOffset + 1, sampleCount * 2);
|
|
231
|
+
let sumSquares = 0;
|
|
232
|
+
for (let i = 0; i < sampleCount; i += 1) {
|
|
233
|
+
const s = view.getInt16(i * 2, true) / 32768;
|
|
234
|
+
sumSquares += s * s;
|
|
235
|
+
}
|
|
236
|
+
const rms = Math.sqrt(sumSquares / sampleCount);
|
|
237
|
+
if (rms >= this.threshold) {
|
|
238
|
+
this.voicedRun += 1;
|
|
239
|
+
this.silentRun = 0;
|
|
240
|
+
if (!this.isSpeaking && this.voicedRun >= this.attackFrames) {
|
|
241
|
+
this.isSpeaking = true;
|
|
242
|
+
this.onChange(true);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this.silentRun += 1;
|
|
247
|
+
this.voicedRun = 0;
|
|
248
|
+
if (this.isSpeaking && this.silentRun >= this.releaseFrames) {
|
|
249
|
+
this.isSpeaking = false;
|
|
250
|
+
this.onChange(false);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** Reset all state (session stop/teardown). Fires `onChange(false)` if a
|
|
255
|
+
* speaking run was open so hosts never strand the affordance. */
|
|
256
|
+
reset() {
|
|
257
|
+
this.voicedRun = 0;
|
|
258
|
+
this.silentRun = 0;
|
|
259
|
+
if (this.isSpeaking) {
|
|
260
|
+
this.isSpeaking = false;
|
|
261
|
+
this.onChange(false);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Persona-TTS gain while a visual TAKEOVER owns the surface (§Q DM.1) — a
|
|
267
|
+
* cutscene clip or a HappyOyster world stream. Those play un-muted and carry
|
|
268
|
+
* their own music/SFX mux, so without a duck the DM and the takeover talk over
|
|
269
|
+
* each other at full volume.
|
|
270
|
+
*
|
|
271
|
+
* 0.25 keeps the DM audible under the takeover rather than cutting it: the DM
|
|
272
|
+
* is still narrating the moment, so muting is wrong and full volume is wrong.
|
|
273
|
+
*/
|
|
274
|
+
export const AUDIO_TAKEOVER_DUCK_GAIN = 0.25;
|
|
275
|
+
/**
|
|
276
|
+
* Time constant for the duck ramp, in seconds. A gain step is a click; ~30 ms
|
|
277
|
+
* of `setTargetAtTime` is inaudible as a transition and still fast enough that
|
|
278
|
+
* the duck lands under the takeover's first frame.
|
|
279
|
+
*/
|
|
280
|
+
export const AUDIO_DUCK_RAMP_TIME_CONSTANT_S = 0.03;
|
|
187
281
|
export class AudioFramePlayer {
|
|
188
282
|
context;
|
|
189
283
|
gainNode;
|
|
284
|
+
/** Current output gain (1 = un-ducked). Tracked as a field because the ramp
|
|
285
|
+
* schedules the value rather than assigning `gain.value`, so the param is
|
|
286
|
+
* not a reliable readback of what was REQUESTED. */
|
|
287
|
+
duckGain = 1;
|
|
190
288
|
activeSources = new Set();
|
|
191
289
|
queuedTime = 0;
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
|
|
290
|
+
/** Internal origin sentinel: `null` = no frame scheduled yet. A `null`
|
|
291
|
+
* sentinel (not `0`) so a legitimate `AudioContext.currentTime` of exactly
|
|
292
|
+
* 0 at first-frame time still counts as initialized (debt internal-#90). */
|
|
293
|
+
originTime = null;
|
|
294
|
+
/** Timestamp (AudioContext.currentTime) when the first frame started
|
|
295
|
+
* playing; 0 when no frame has played yet.
|
|
296
|
+
*
|
|
297
|
+
* Published-compat accessor pair over the null-sentinel `originTime`:
|
|
298
|
+
* external consumers (e.g. `VoiceSession.resetTurn`) read a plain number
|
|
299
|
+
* and write `0` to mean "reset for the next turn" — the setter maps that
|
|
300
|
+
* reset back onto the internal `null` sentinel. */
|
|
301
|
+
get playbackOrigin() {
|
|
302
|
+
return this.originTime ?? 0;
|
|
303
|
+
}
|
|
304
|
+
set playbackOrigin(value) {
|
|
305
|
+
this.originTime = value === 0 ? null : value;
|
|
306
|
+
}
|
|
307
|
+
/** Start time of the first audio frame in the current chunk; `null` = no
|
|
308
|
+
* frame has set it yet (same #90 null-sentinel rationale as `originTime`).
|
|
195
309
|
* Reset each time getChunkStartTime() is called (consumed by viseme scheduler). */
|
|
196
|
-
chunkStartTime =
|
|
197
|
-
|
|
310
|
+
chunkStartTime = null;
|
|
311
|
+
// ── AU.2b adaptive jitter buffer ──────────────────────────────────────
|
|
312
|
+
// Frames used to be scheduled at `max(currentTime, queuedTime)`: the very
|
|
313
|
+
// first frame of a run started IMMEDIATELY, so any 20–40 ms of network
|
|
314
|
+
// jitter on the next frame produced an audible gap (spec-K Fault B #2).
|
|
315
|
+
// Now every run start (first frame of a turn, or a restart after an
|
|
316
|
+
// underrun) is scheduled `jitterLeadS` in the future, buying that much
|
|
317
|
+
// jitter absorption; steady-state frames still chain at `queuedTime`.
|
|
318
|
+
// Each mid-stream underrun ADAPTIVELY grows the lead (bad network ⇒ more
|
|
319
|
+
// buffer, at the cost of latency), capped at MAX_JITTER_LEAD_S.
|
|
320
|
+
static INITIAL_JITTER_LEAD_S = 0.06;
|
|
321
|
+
jitterLeadS = AudioFramePlayer.INITIAL_JITTER_LEAD_S;
|
|
322
|
+
static JITTER_LEAD_STEP_S = 0.02;
|
|
323
|
+
static MAX_JITTER_LEAD_S = 0.2;
|
|
324
|
+
// ── AU.2d AudioBuffer pool ────────────────────────────────────────────
|
|
325
|
+
// TTS frames are fixed-size (SAMPLES_PER_FRAME) at 50 Hz; allocating a
|
|
326
|
+
// fresh AudioBuffer per frame churns ~50 allocations/s through the GC
|
|
327
|
+
// (spec-K Fault B #3). Finished sources return their buffer here for
|
|
328
|
+
// reuse; only exact-size buffers are pooled.
|
|
329
|
+
bufferPool = [];
|
|
330
|
+
static MAX_POOLED_BUFFERS = 32;
|
|
331
|
+
/** statechange listener kept as a field so stop() can detach it — the
|
|
332
|
+
* context is the SHARED page singleton (AU.2a), so an orphaned listener
|
|
333
|
+
* from a stopped player must not keep firing. */
|
|
334
|
+
onStateChange = () => {
|
|
335
|
+
if (this.context.state === 'running' &&
|
|
336
|
+
this.queuedTime < this.context.currentTime) {
|
|
337
|
+
this.queuedTime = this.context.currentTime;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
198
340
|
constructor() {
|
|
199
|
-
|
|
341
|
+
// AU.2a: acquire the shared page-singleton context (iOS max-4 pool)
|
|
342
|
+
// instead of creating a per-player one.
|
|
343
|
+
this.context = acquireSharedAudioContext();
|
|
200
344
|
this.gainNode = this.context.createGain();
|
|
201
345
|
this.gainNode.connect(this.context.destination);
|
|
202
346
|
// Re-anchor queuedTime on AudioContext resume so post-suspension
|
|
203
347
|
// frames aren't scheduled in the past (mobile lock screen / tab
|
|
204
348
|
// background recovery). See docs/features/2026-05-10-audio-pipeline-safety-net.md.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this.queuedTime = this.context.currentTime;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
349
|
+
// addEventListener (not `onstatechange = …`) because the context is
|
|
350
|
+
// shared — assignment would clobber other listeners on the singleton.
|
|
351
|
+
this.context.addEventListener?.('statechange', this.onStateChange);
|
|
211
352
|
}
|
|
212
|
-
/** Return the playback time elapsed since the first frame was scheduled.
|
|
353
|
+
/** Return the playback time elapsed since the first frame was scheduled.
|
|
354
|
+
*
|
|
355
|
+
* §Q PLYR.5 — NEVER negative. `originTime` is the *scheduled* start of the
|
|
356
|
+
* turn's first frame, which can sit in the FUTURE, so the raw
|
|
357
|
+
* `currentTime - originTime` can go negative; staging captured a live
|
|
358
|
+
* session streaming `-61.148, -61.052, -60.948…` at ~10 Hz. Until the
|
|
359
|
+
* turn's audio is actually audible, the playhead INTO that turn is 0 —
|
|
360
|
+
* which is what the server's `is_speech_active` / `get_words_spoken_until`
|
|
361
|
+
* arithmetic (`api/chat/ws.py`) needs to stay truthful.
|
|
362
|
+
*
|
|
363
|
+
* §Q PLYR.6 removed the DRIVER of the big negatives (a new turn no longer
|
|
364
|
+
* chains behind the previous turn's backlog — `AudioPipeline.resetTurn`
|
|
365
|
+
* flushes it), leaving only the jitter lead in the future. The clamp stays
|
|
366
|
+
* as the floor: `startTime` is always `>= currentTime` by construction. */
|
|
213
367
|
getPlaybackTime() {
|
|
214
|
-
if (this.
|
|
368
|
+
if (this.originTime === null)
|
|
215
369
|
return 0;
|
|
216
|
-
return this.context.currentTime - this.
|
|
370
|
+
return Math.max(0, this.context.currentTime - this.originTime);
|
|
217
371
|
}
|
|
218
372
|
/**
|
|
219
373
|
* Return the AudioContext time at which the first frame was scheduled,
|
|
220
374
|
* or 0 if no frame has played yet. Used by `AudioPipeline` to convert
|
|
221
375
|
* absolute chunk start times into the relative coordinate frame the
|
|
222
376
|
* playback tracker uses for word timestamps.
|
|
377
|
+
*
|
|
378
|
+
* NOTE: a return of 0 is ambiguous (unset vs a legitimate origin of
|
|
379
|
+
* exactly 0). Callers that need to distinguish must use
|
|
380
|
+
* {@link getPlaybackOriginOrNull} — this method stays for the published
|
|
381
|
+
* numeric surface.
|
|
223
382
|
*/
|
|
224
383
|
getPlaybackOrigin() {
|
|
225
384
|
return this.playbackOrigin;
|
|
226
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Null-aware origin read (debt internal-#90): `null` = no frame has been
|
|
388
|
+
* scheduled yet; a `number` (including a legitimate `0`) = the recorded
|
|
389
|
+
* origin. `AudioPipeline.processAudioMetadata` uses this so an origin of
|
|
390
|
+
* exactly 0 is not conflated with "unset" in the word-timestamp math.
|
|
391
|
+
*/
|
|
392
|
+
getPlaybackOriginOrNull() {
|
|
393
|
+
return this.originTime;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Explicitly reset the playback origin for a new turn. Preferred over the
|
|
397
|
+
* legacy `playbackOrigin = 0` write (which the setter maps to the same
|
|
398
|
+
* reset) — this name states the intent and cannot collide with a
|
|
399
|
+
* legitimate computed origin of 0.
|
|
400
|
+
*/
|
|
401
|
+
resetPlaybackOrigin() {
|
|
402
|
+
this.originTime = null;
|
|
403
|
+
}
|
|
227
404
|
/** Expose the AudioContext for external time queries. */
|
|
228
405
|
getContext() {
|
|
229
406
|
return this.context;
|
|
@@ -236,9 +413,8 @@ export class AudioFramePlayer {
|
|
|
236
413
|
* Call this from the audio_metadata handler to schedule visemes at the
|
|
237
414
|
* correct time. Resets after each call so the next chunk gets a fresh start. */
|
|
238
415
|
getChunkStartTime() {
|
|
239
|
-
const t = this.chunkStartTime
|
|
240
|
-
this.chunkStartTime =
|
|
241
|
-
this.chunkStartTimeSet = false;
|
|
416
|
+
const t = this.chunkStartTime ?? this.getNextFrameStartTime();
|
|
417
|
+
this.chunkStartTime = null;
|
|
242
418
|
return t;
|
|
243
419
|
}
|
|
244
420
|
/** True iff a binary frame has set `chunkStartTime` for the current chunk.
|
|
@@ -247,13 +423,52 @@ export class AudioFramePlayer {
|
|
|
247
423
|
* without binary, `getChunkStartTime()` falls back to `currentTime`,
|
|
248
424
|
* which anchors visemes to "now" instead of the actual chunk start. */
|
|
249
425
|
hasChunkStart() {
|
|
250
|
-
return this.
|
|
426
|
+
return this.chunkStartTime !== null;
|
|
251
427
|
}
|
|
252
428
|
async resume() {
|
|
253
429
|
if (this.context.state === 'suspended') {
|
|
254
430
|
await this.context.resume();
|
|
255
431
|
}
|
|
256
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Duck (or restore) persona TTS on the shared output gain — the mix point the
|
|
435
|
+
* player has always owned but never exposed.
|
|
436
|
+
*
|
|
437
|
+
* Hosts call `setDuck(AUDIO_TAKEOVER_DUCK_GAIN)` when a cutscene / world
|
|
438
|
+
* takeover becomes visible and `clearDuck()` when it is dismissed. The duck is
|
|
439
|
+
* a MIX setting, not playback state: it survives `clearQueue()`/`resetTurn()`
|
|
440
|
+
* so a barge-in or a turn boundary mid-takeover cannot silently restore full
|
|
441
|
+
* volume underneath a playing clip.
|
|
442
|
+
*
|
|
443
|
+
* @param gain clamped to `[0, 1]`; a non-finite value is ignored.
|
|
444
|
+
*/
|
|
445
|
+
setDuck(gain) {
|
|
446
|
+
if (!Number.isFinite(gain))
|
|
447
|
+
return;
|
|
448
|
+
const target = Math.min(1, Math.max(0, gain));
|
|
449
|
+
this.duckGain = target;
|
|
450
|
+
const param = this.gainNode.gain;
|
|
451
|
+
const now = this.context.currentTime;
|
|
452
|
+
// Ramp when the platform offers one; fall back through the schedulers a
|
|
453
|
+
// minimal/mocked AudioParam may implement before assigning outright.
|
|
454
|
+
if (typeof param.setTargetAtTime === 'function') {
|
|
455
|
+
param.setTargetAtTime(target, now, AUDIO_DUCK_RAMP_TIME_CONSTANT_S);
|
|
456
|
+
}
|
|
457
|
+
else if (typeof param.setValueAtTime === 'function') {
|
|
458
|
+
param.setValueAtTime(target, now);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
param.value = target;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/** Restore full persona-TTS volume — the takeover was dismissed. */
|
|
465
|
+
clearDuck() {
|
|
466
|
+
this.setDuck(1);
|
|
467
|
+
}
|
|
468
|
+
/** The gain last requested via {@link setDuck} (1 = un-ducked). */
|
|
469
|
+
getDuck() {
|
|
470
|
+
return this.duckGain;
|
|
471
|
+
}
|
|
257
472
|
/** Immediately silence and stop all scheduled/playing audio. */
|
|
258
473
|
clearQueue() {
|
|
259
474
|
// Stopping each source is sufficient to silence playback — the
|
|
@@ -268,51 +483,92 @@ export class AudioFramePlayer {
|
|
|
268
483
|
}
|
|
269
484
|
this.activeSources.clear();
|
|
270
485
|
this.queuedTime = this.context.currentTime;
|
|
271
|
-
this.
|
|
272
|
-
this.chunkStartTime =
|
|
273
|
-
this.chunkStartTimeSet = false;
|
|
486
|
+
this.originTime = null;
|
|
487
|
+
this.chunkStartTime = null;
|
|
274
488
|
}
|
|
275
489
|
async stop() {
|
|
276
490
|
// Reuse clearQueue so the source-stop loop only lives in one place,
|
|
277
|
-
// then zero out the queuedTime watermark and
|
|
491
|
+
// then zero out the queuedTime watermark and RELEASE the shared context
|
|
492
|
+
// (AU.2a — suspended at refcount 0, kept for reuse; closing a shared
|
|
493
|
+
// singleton would kill the mic and burn an iOS context slot).
|
|
278
494
|
this.clearQueue();
|
|
279
495
|
this.queuedTime = 0;
|
|
280
|
-
|
|
496
|
+
this.bufferPool = [];
|
|
497
|
+
this.context.removeEventListener?.('statechange', this.onStateChange);
|
|
498
|
+
releaseSharedAudioContext();
|
|
499
|
+
}
|
|
500
|
+
/** Pop a pooled AudioBuffer of exactly `length` frames, or allocate one. */
|
|
501
|
+
acquireBuffer(length) {
|
|
502
|
+
const pooled = this.bufferPool.pop();
|
|
503
|
+
if (pooled && pooled.length === length) {
|
|
504
|
+
return pooled;
|
|
505
|
+
}
|
|
506
|
+
// Wrong-size pooled buffer (shouldn't happen — frames are fixed-size):
|
|
507
|
+
// discard it and allocate fresh.
|
|
508
|
+
return this.context.createBuffer(1, length, SAMPLE_RATE);
|
|
509
|
+
}
|
|
510
|
+
recycleBuffer(buffer) {
|
|
511
|
+
if (this.bufferPool.length < AudioFramePlayer.MAX_POOLED_BUFFERS) {
|
|
512
|
+
this.bufferPool.push(buffer);
|
|
513
|
+
}
|
|
281
514
|
}
|
|
282
515
|
playFrame(data) {
|
|
283
516
|
const { tag, audio } = decodeAudioFrame(data);
|
|
284
517
|
if (tag !== TAG_AI) {
|
|
285
518
|
return;
|
|
286
519
|
}
|
|
520
|
+
const buffer = this.acquireBuffer(audio.length);
|
|
521
|
+
// Reuse a scratch Float32Array per frame is not worth it — copyToChannel
|
|
522
|
+
// needs a Float32Array view anyway; the POOLED allocation is the
|
|
523
|
+
// AudioBuffer itself (the expensive audio-graph object, AU.2d).
|
|
287
524
|
const floatData = new Float32Array(audio.length);
|
|
288
525
|
for (let i = 0; i < audio.length; i += 1) {
|
|
289
526
|
floatData[i] = audio[i] / FLOAT_DIVISOR;
|
|
290
527
|
}
|
|
291
|
-
const buffer = this.context.createBuffer(1, floatData.length, SAMPLE_RATE);
|
|
292
528
|
buffer.copyToChannel(floatData, 0);
|
|
293
529
|
const source = this.context.createBufferSource();
|
|
294
530
|
source.buffer = buffer;
|
|
295
531
|
source.connect(this.gainNode);
|
|
296
|
-
// Track source so barge-in can stop it cleanly
|
|
532
|
+
// Track source so barge-in can stop it cleanly; recycle the buffer once
|
|
533
|
+
// the source finishes (or is stopped by clearQueue — onended fires for
|
|
534
|
+
// both), so steady-state playback allocates zero new AudioBuffers.
|
|
297
535
|
this.activeSources.add(source);
|
|
298
|
-
source.onended = () =>
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
536
|
+
source.onended = () => {
|
|
537
|
+
this.activeSources.delete(source);
|
|
538
|
+
this.recycleBuffer(buffer);
|
|
539
|
+
};
|
|
540
|
+
// AU.2b — adaptive jitter buffer. Steady state chains at queuedTime; a
|
|
541
|
+
// run (re)start schedules jitterLeadS ahead so network jitter on the
|
|
542
|
+
// following frames is absorbed instead of gapping. A RESTART of an
|
|
543
|
+
// in-progress turn (originTime already set ⇒ audio had started, but the
|
|
544
|
+
// queue drained before this frame arrived) is an underrun: grow the lead.
|
|
545
|
+
let startTime;
|
|
546
|
+
if (this.queuedTime > this.context.currentTime) {
|
|
547
|
+
startTime = this.queuedTime;
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
if (this.originTime !== null) {
|
|
551
|
+
this.jitterLeadS = Math.min(AudioFramePlayer.MAX_JITTER_LEAD_S, this.jitterLeadS + AudioFramePlayer.JITTER_LEAD_STEP_S);
|
|
552
|
+
}
|
|
553
|
+
startTime = this.context.currentTime + this.jitterLeadS;
|
|
554
|
+
}
|
|
555
|
+
// Record the origin time when the very first frame is scheduled.
|
|
556
|
+
// Written to the internal field directly (not the setter) so a
|
|
557
|
+
// legitimate startTime of exactly 0 still counts as initialized (#90).
|
|
558
|
+
if (this.originTime === null) {
|
|
559
|
+
this.originTime = startTime;
|
|
303
560
|
}
|
|
304
561
|
// Track the start time of the first frame in this chunk.
|
|
305
562
|
// audio_metadata arrives AFTER the binary frames for the same chunk,
|
|
306
563
|
// so this captures the correct base time for viseme scheduling.
|
|
307
|
-
if (
|
|
564
|
+
if (this.chunkStartTime === null) {
|
|
308
565
|
this.chunkStartTime = startTime;
|
|
309
|
-
this.chunkStartTimeSet = true;
|
|
310
566
|
}
|
|
311
567
|
source.start(startTime);
|
|
312
568
|
this.queuedTime = startTime + buffer.duration;
|
|
313
569
|
}
|
|
314
570
|
}
|
|
315
|
-
export const buildHelloPayload = ({ videoId, personaId, mode = 'tts_stt', audioFormat = 'PCM16', enableAudioMarkups = false, voiceTemperature = 1.0, speakingRate = 1.0, voiceId = 'Ashley', systemPrompt, systemPromptOverride = false, modelId, ttsModelId, entityId, adventureSessionId, partyPersonaIds, }) => ({
|
|
571
|
+
export const buildHelloPayload = ({ videoId, personaId, mode = 'tts_stt', audioFormat = 'PCM16', enableAudioMarkups = false, voiceTemperature = 1.0, speakingRate = 1.0, voiceId = 'Ashley', systemPrompt, systemPromptOverride = false, modelId, ttsModelId, entityId, adventureSessionId, partyPersonaIds, audioCodecs, }) => ({
|
|
316
572
|
action: 'hello',
|
|
317
573
|
version: HELLO_VERSION,
|
|
318
574
|
videoId,
|
|
@@ -329,6 +585,7 @@ export const buildHelloPayload = ({ videoId, personaId, mode = 'tts_stt', audioF
|
|
|
329
585
|
...(entityId ? { entityId } : {}),
|
|
330
586
|
...(adventureSessionId ? { adventureSessionId } : {}),
|
|
331
587
|
...(partyPersonaIds && partyPersonaIds.length > 0 ? { partyPersonaIds } : {}),
|
|
588
|
+
...(audioCodecs && audioCodecs.length > 0 ? { audioCodecs } : {}),
|
|
332
589
|
});
|
|
333
590
|
/**
|
|
334
591
|
* PlaybackTracker - Tracks word-level playback position for barge-in support.
|
|
@@ -516,6 +773,15 @@ export class AudioSessionClient {
|
|
|
516
773
|
* the timeline.
|
|
517
774
|
*/
|
|
518
775
|
const SENTENCE_OVERLAP_EPSILON_S = 0.01;
|
|
776
|
+
/**
|
|
777
|
+
* Cap on the suspended-context frame queue (debt #88 follow-up). Frames are
|
|
778
|
+
* 20 ms each, so 150 ≈ 3 s of audio. While the AudioContext stays suspended
|
|
779
|
+
* (iOS/Chrome pre-gesture — `resume()` can stay pending indefinitely), a
|
|
780
|
+
* streaming reply would otherwise queue UNBOUNDED PCM in memory and then
|
|
781
|
+
* burst-play the entire stale backlog on a late gesture. Drop-oldest: a very
|
|
782
|
+
* late resume plays at most the freshest ~3 s instead of minutes-old audio.
|
|
783
|
+
*/
|
|
784
|
+
const MAX_PENDING_FRAMES = 150;
|
|
519
785
|
/** Walk a phoneme message from the back, return the last phoneme with
|
|
520
786
|
* non-empty `phones`. Returns null only when every word is empty. */
|
|
521
787
|
function findLastPhone(words) {
|
|
@@ -559,12 +825,72 @@ export class AudioPipeline {
|
|
|
559
825
|
// of the actual chunk start time set by the binary frame, producing a
|
|
560
826
|
// 20–100 ms forward drift of visemes vs audio.
|
|
561
827
|
pendingMetadata = [];
|
|
562
|
-
|
|
828
|
+
// Post-barge inbound-frame latch (AU.1a). `bargeIn()` only silences frames
|
|
829
|
+
// that were ALREADY scheduled (`clearQueue()` stops active sources) — TTS
|
|
830
|
+
// frames still in flight from the server arrive AFTER the flush and would
|
|
831
|
+
// be scheduled and PLAY ("audio buffers still play back on barge-in").
|
|
832
|
+
// While latched, inbound binary frames + audio_metadata are dropped. The
|
|
833
|
+
// latch clears on the next turn boundary (`resetTurn()`, driven by the
|
|
834
|
+
// next final transcript) or on `destroy()`.
|
|
835
|
+
barged = false;
|
|
836
|
+
// In-arrival-order event queue for the suspended-context burst (debt #88 +
|
|
837
|
+
// the AU.2 fold of debt 20260710-suspended-burst-drain…). When the context
|
|
838
|
+
// is suspended, frames AND audio_metadata are queued TOGETHER in arrival
|
|
839
|
+
// order and replayed in that order once a SINGLE resume() resolves. The
|
|
840
|
+
// earlier frames-only queue lost the frame↔metadata interleaving: a burst
|
|
841
|
+
// spanning multiple chunks drained one metadata per frame landing, so a
|
|
842
|
+
// later chunk's metadata could anchor to a mid-previous-chunk frame time.
|
|
843
|
+
// Replaying in arrival order preserves the live-path per-chunk anchoring
|
|
844
|
+
// (frames re-arm chunkStartTime, the chunk's own metadata consumes it).
|
|
845
|
+
pendingEvents = [];
|
|
846
|
+
pendingFrameCount = 0;
|
|
847
|
+
resumeDrainInFlight = false;
|
|
848
|
+
/** AU.2a — last suspended-state value reported to `onPlaybackSuspended`,
|
|
849
|
+
* so the callback fires only on transitions. */
|
|
850
|
+
suspendedNotified = false;
|
|
851
|
+
onPlaybackSuspended;
|
|
852
|
+
constructor(onVisemeChange, options) {
|
|
563
853
|
this.player = new AudioFramePlayer();
|
|
564
854
|
this.visemeScheduler = new VisemeScheduler(this.player.getContext(), onVisemeChange);
|
|
855
|
+
this.onPlaybackSuspended = options?.onPlaybackSuspended;
|
|
856
|
+
}
|
|
857
|
+
notifySuspended(suspended) {
|
|
858
|
+
if (this.suspendedNotified === suspended)
|
|
859
|
+
return;
|
|
860
|
+
this.suspendedNotified = suspended;
|
|
861
|
+
this.onPlaybackSuspended?.(suspended);
|
|
565
862
|
}
|
|
863
|
+
/**
|
|
864
|
+
* AU.2a — probe the (shared) AudioContext and fire `onPlaybackSuspended`
|
|
865
|
+
* per its live state. Hosts call this after a reconnect re-arm: on iOS the
|
|
866
|
+
* gesture-less `resume()` can stay pending forever, so the awaited arm
|
|
867
|
+
* never returns and only an external probe can surface the tap-to-restore
|
|
868
|
+
* overlay. Transition-guarded — safe to call repeatedly.
|
|
869
|
+
*/
|
|
870
|
+
notifyIfSuspended() {
|
|
871
|
+
this.notifySuspended(this.player.getContext().state === 'suspended');
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Resume the player's (shared) AudioContext and drain any queued
|
|
875
|
+
* suspended-burst events. Callers restoring audio from a user gesture
|
|
876
|
+
* (the AU.2a tap-to-restore overlay) MUST call this synchronously inside
|
|
877
|
+
* the gesture handler — the underlying `resume()` is what iOS gates.
|
|
878
|
+
*/
|
|
566
879
|
async resume() {
|
|
567
880
|
await this.player.resume();
|
|
881
|
+
this.drainPendingEvents();
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* §Q DM.1 — duck persona TTS under a visual takeover (cutscene clip / world
|
|
885
|
+
* stream). Delegates to {@link AudioFramePlayer.setDuck}; hosts drive the
|
|
886
|
+
* pipeline, not the player, so this is the surface they reach for.
|
|
887
|
+
*/
|
|
888
|
+
setDuck(gain) {
|
|
889
|
+
this.player.setDuck(gain);
|
|
890
|
+
}
|
|
891
|
+
/** Restore full persona-TTS volume after a takeover is dismissed. */
|
|
892
|
+
clearDuck() {
|
|
893
|
+
this.player.clearDuck();
|
|
568
894
|
}
|
|
569
895
|
/**
|
|
570
896
|
* Attach a WebSocket for barge-in support.
|
|
@@ -585,51 +911,146 @@ export class AudioPipeline {
|
|
|
585
911
|
this._sessionClient = new AudioSessionClient(ws);
|
|
586
912
|
this._sessionClient.setAudioPlayer(this.player);
|
|
587
913
|
}
|
|
588
|
-
/**
|
|
914
|
+
/**
|
|
915
|
+
* Handle an incoming binary TTS audio frame.
|
|
916
|
+
*
|
|
917
|
+
* Returns `true` when the frame was accepted (played or queued for the
|
|
918
|
+
* resume drain), `false` when it was DROPPED (post-barge latch or closed
|
|
919
|
+
* context). Consumers use the return to avoid asserting UI state (e.g.
|
|
920
|
+
* "speaking") for audio that will never play. Additive — existing callers
|
|
921
|
+
* that ignore the return are unchanged.
|
|
922
|
+
*/
|
|
589
923
|
handleBinaryFrame(data) {
|
|
590
924
|
try {
|
|
925
|
+
// Post-barge latch: drop in-flight frames for the interrupted reply.
|
|
926
|
+
// Re-armed by `resetTurn()` at the next turn boundary.
|
|
927
|
+
if (this.barged) {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
591
930
|
const state = this.player.getContext().state;
|
|
592
931
|
// 'closed' shouldn't normally happen here because callers go
|
|
593
932
|
// through `destroy()` before letting the context close, but a
|
|
594
933
|
// stray frame after a teardown race would crash `playFrame` with
|
|
595
934
|
// an InvalidStateError. Drop it explicitly.
|
|
596
935
|
if (state === 'closed') {
|
|
597
|
-
return;
|
|
936
|
+
return false;
|
|
598
937
|
}
|
|
599
|
-
if (state === 'running') {
|
|
600
|
-
this.
|
|
601
|
-
|
|
602
|
-
this.drainPendingMetadata();
|
|
938
|
+
if (state === 'running' && this.pendingEvents.length === 0) {
|
|
939
|
+
this.playFrameNow(data);
|
|
940
|
+
return true;
|
|
603
941
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
// position before the frame even reaches the audio graph.
|
|
623
|
-
this.updateTrackerPosition();
|
|
624
|
-
this.drainPendingMetadata();
|
|
625
|
-
})
|
|
626
|
-
.catch((err) => console.error('[AudioPipeline] Failed to resume audio:', err));
|
|
942
|
+
// Suspended-context path (typical: first frame before any user
|
|
943
|
+
// gesture) — or a running context whose resume-drain hasn't emptied
|
|
944
|
+
// the queue yet (ordering: a frame must never jump ahead of queued
|
|
945
|
+
// predecessors). Queue in arrival order; a single resume() drains
|
|
946
|
+
// the queue in order when it resolves (debt #88 — the previous
|
|
947
|
+
// per-frame `.then()` chains raced and could reorder frames).
|
|
948
|
+
// Bounded drop-oldest so a never-resuming context can't accumulate
|
|
949
|
+
// unbounded PCM (see MAX_PENDING_FRAMES).
|
|
950
|
+
this.pendingEvents.push({ kind: 'frame', data });
|
|
951
|
+
this.pendingFrameCount += 1;
|
|
952
|
+
this.trimPendingEvents();
|
|
953
|
+
// AU.2a — a frame stuck behind a suspended context is exactly the
|
|
954
|
+
// "mic live, audio silent" state; let the host show tap-to-restore.
|
|
955
|
+
if (state === 'suspended') {
|
|
956
|
+
this.notifySuspended(true);
|
|
957
|
+
}
|
|
958
|
+
if (this.resumeDrainInFlight) {
|
|
959
|
+
return true;
|
|
627
960
|
}
|
|
961
|
+
this.resumeDrainInFlight = true;
|
|
962
|
+
this.player
|
|
963
|
+
.resume()
|
|
964
|
+
.then(() => {
|
|
965
|
+
this.resumeDrainInFlight = false;
|
|
966
|
+
// Drain INSIDE then() so position reads are taken after each
|
|
967
|
+
// playFrame schedules — outside, we'd write stale positions
|
|
968
|
+
// before the frames even reach the audio graph.
|
|
969
|
+
this.drainPendingEvents();
|
|
970
|
+
})
|
|
971
|
+
.catch((err) => {
|
|
972
|
+
this.resumeDrainInFlight = false;
|
|
973
|
+
// Drop the queued events — parity with the previous per-frame
|
|
974
|
+
// behavior (a rejected resume() lost that frame). Retaining them
|
|
975
|
+
// would burst-play a STALE backlog whenever a much-later frame or
|
|
976
|
+
// gesture finally drains the queue — the very symptom AU.1 fixes.
|
|
977
|
+
this.clearPendingEvents();
|
|
978
|
+
console.error('[AudioPipeline] Failed to resume audio:', err);
|
|
979
|
+
});
|
|
980
|
+
return true;
|
|
628
981
|
}
|
|
629
982
|
catch (err) {
|
|
630
983
|
console.error('[AudioPipeline] Failed to play audio frame:', err);
|
|
984
|
+
// `false` strictly means "deliberately dropped" (latch/closed). An
|
|
985
|
+
// unexpected play error is still an ACCEPTED frame — consumers keep
|
|
986
|
+
// their pre-AU.1 behavior (e.g. asserting "speaking") for it.
|
|
987
|
+
return true;
|
|
631
988
|
}
|
|
632
989
|
}
|
|
990
|
+
/** Schedule one frame and run the per-frame bookkeeping (tracker + metadata). */
|
|
991
|
+
playFrameNow(data) {
|
|
992
|
+
this.player.playFrame(data);
|
|
993
|
+
this.updateTrackerPosition();
|
|
994
|
+
this.drainPendingMetadata();
|
|
995
|
+
}
|
|
996
|
+
/** Reset the burst queue + its frame counter (single reset site). */
|
|
997
|
+
clearPendingEvents() {
|
|
998
|
+
this.pendingEvents = [];
|
|
999
|
+
this.pendingFrameCount = 0;
|
|
1000
|
+
}
|
|
1001
|
+
/** Drop-oldest cap on queued burst FRAMES (metadata rides along: when a
|
|
1002
|
+
* frame is dropped, any metadata queued BEFORE the next surviving frame
|
|
1003
|
+
* belongs to a dropped chunk and is dropped with it — otherwise the
|
|
1004
|
+
* drain would anchor that stale metadata to the next SURVIVING chunk's
|
|
1005
|
+
* first frame, corrupting visemes/word timestamps; codex P2 on #727). */
|
|
1006
|
+
trimPendingEvents() {
|
|
1007
|
+
if (this.pendingFrameCount <= MAX_PENDING_FRAMES)
|
|
1008
|
+
return;
|
|
1009
|
+
while (this.pendingFrameCount > MAX_PENDING_FRAMES) {
|
|
1010
|
+
const dropped = this.pendingEvents.shift();
|
|
1011
|
+
if (dropped === undefined) {
|
|
1012
|
+
this.pendingFrameCount = 0;
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
if (dropped.kind === 'frame') {
|
|
1016
|
+
this.pendingFrameCount -= 1;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
// Strip metadata now stranded at the front: it followed a dropped frame,
|
|
1020
|
+
// so it describes a dropped chunk. (An ASYNC metadata-first message for
|
|
1021
|
+
// the next surviving chunk is indistinguishable without frame chunk-ids;
|
|
1022
|
+
// in this pathological >3 s-flood path, dropping is the safe choice —
|
|
1023
|
+
// missing visemes beat wrongly-anchored ones.)
|
|
1024
|
+
while (this.pendingEvents[0]?.kind === 'metadata') {
|
|
1025
|
+
this.pendingEvents.shift();
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
/** Drain queued suspended-burst events in arrival order (debt #88; AU.2
|
|
1029
|
+
* extends the queue to carry metadata too, preserving frame↔metadata
|
|
1030
|
+
* interleaving so multi-chunk bursts anchor each chunk's visemes/word
|
|
1031
|
+
* timestamps at that chunk's own first frame). */
|
|
1032
|
+
drainPendingEvents() {
|
|
1033
|
+
while (this.pendingEvents.length > 0) {
|
|
1034
|
+
// A barge-in may have landed while resume() was in flight — the
|
|
1035
|
+
// queued events belong to the interrupted reply, drop them all.
|
|
1036
|
+
if (this.barged) {
|
|
1037
|
+
this.clearPendingEvents();
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
const event = this.pendingEvents.shift();
|
|
1041
|
+
if (event === undefined)
|
|
1042
|
+
continue;
|
|
1043
|
+
if (event.kind === 'frame') {
|
|
1044
|
+
this.pendingFrameCount -= 1;
|
|
1045
|
+
this.playFrameNow(event.data);
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
this.routeAudioMetadata(event.msg);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
// Queue fully replayed — playback is live again (AU.2a).
|
|
1052
|
+
this.notifySuspended(false);
|
|
1053
|
+
}
|
|
633
1054
|
/**
|
|
634
1055
|
* Push the current playhead into the session's playback tracker in the
|
|
635
1056
|
* same coordinate frame everything else uses (relative — elapsed since
|
|
@@ -651,6 +1072,27 @@ export class AudioPipeline {
|
|
|
651
1072
|
* 100 ms ahead of the audio. Buffer until a binary frame lands and the
|
|
652
1073
|
* real chunk start is known. */
|
|
653
1074
|
handleAudioMetadata(msg) {
|
|
1075
|
+
// Post-barge latch: metadata for the interrupted reply's audio must not
|
|
1076
|
+
// schedule visemes (its frames are dropped too — see handleBinaryFrame).
|
|
1077
|
+
// Returns false when dropped (same contract as handleBinaryFrame).
|
|
1078
|
+
if (this.barged) {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
// Suspended-burst path (AU.2 fold of the multi-chunk anchoring debt):
|
|
1082
|
+
// while frames are queued behind a suspended context, metadata must NOT
|
|
1083
|
+
// bypass them into pendingMetadata — it queues INLINE so the drain
|
|
1084
|
+
// replays the exact arrival interleaving and each chunk's metadata
|
|
1085
|
+
// anchors at that chunk's own first frame.
|
|
1086
|
+
if (this.pendingEvents.length > 0) {
|
|
1087
|
+
this.pendingEvents.push({ kind: 'metadata', msg });
|
|
1088
|
+
return true;
|
|
1089
|
+
}
|
|
1090
|
+
this.routeAudioMetadata(msg);
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
/** Live-path metadata routing: buffer until the chunk's first binary frame
|
|
1094
|
+
* has landed (Inworld ASYNC mode), else process immediately. */
|
|
1095
|
+
routeAudioMetadata(msg) {
|
|
654
1096
|
if (!this.player.hasChunkStart()) {
|
|
655
1097
|
this.pendingMetadata.push(msg);
|
|
656
1098
|
return;
|
|
@@ -684,7 +1126,11 @@ export class AudioPipeline {
|
|
|
684
1126
|
// frames), fall back to chunkStartTime so the very-first-chunk math
|
|
685
1127
|
// still produces a 0-based offset.
|
|
686
1128
|
if (msg.wordTimestamps?.length && this.sessionClient) {
|
|
687
|
-
|
|
1129
|
+
// Null-aware read (debt #90): `??` — NOT `||` — so a legitimate
|
|
1130
|
+
// origin of exactly 0 anchors correctly instead of falling back to
|
|
1131
|
+
// this chunk's own start (which would zero out chunkRelativeStart
|
|
1132
|
+
// for every later chunk and mis-anchor all word timestamps).
|
|
1133
|
+
const origin = this.player.getPlaybackOriginOrNull() ?? chunkStartTime;
|
|
688
1134
|
const chunkRelativeStart = chunkStartTime - origin;
|
|
689
1135
|
this.sessionClient.addWordTimestamps(msg.wordTimestamps.map((ts) => ({
|
|
690
1136
|
word: ts.word,
|
|
@@ -722,11 +1168,35 @@ export class AudioPipeline {
|
|
|
722
1168
|
}
|
|
723
1169
|
}
|
|
724
1170
|
}
|
|
725
|
-
/**
|
|
726
|
-
|
|
1171
|
+
/**
|
|
1172
|
+
* Clear the turn-scoped buffers/anchors shared by `resetTurn()`,
|
|
1173
|
+
* `bargeIn()`, and `destroy()` — the SINGLE reset site so a future
|
|
1174
|
+
* turn-scoped field can't be cleared in one place and leak in another.
|
|
1175
|
+
* The `barged` latch is deliberately NOT touched here: bargeIn() keeps it
|
|
1176
|
+
* set, resetTurn()/destroy() clear it explicitly.
|
|
1177
|
+
*/
|
|
1178
|
+
clearTurnBuffers() {
|
|
727
1179
|
this.sentenceStartTime = null;
|
|
728
1180
|
this.lastPhonemeEnd = 0;
|
|
729
1181
|
this.pendingMetadata = [];
|
|
1182
|
+
this.clearPendingEvents();
|
|
1183
|
+
}
|
|
1184
|
+
/** Reset state for a new conversational turn.
|
|
1185
|
+
*
|
|
1186
|
+
* Deliberately does NOT touch the player's queue (§Q PLYR.6, codex P1 on
|
|
1187
|
+
* #1514). Each consumer drives this from its OWN view of the turn boundary
|
|
1188
|
+
* and they disagree about when that is: the Vue surfaces call it on the
|
|
1189
|
+
* `done` frame (`../Web-App` `ai-integration-seer.vue:69`) and on the first
|
|
1190
|
+
* token of a new assistant message (`seer-ai-chat.vue:835`) — `done` lands
|
|
1191
|
+
* while most of that reply's audio is still scheduled, so flushing here
|
|
1192
|
+
* would truncate every reply on those surfaces. The PLYR.6 flush belongs to
|
|
1193
|
+
* the SERVER-authoritative boundary only, and lives in
|
|
1194
|
+
* `VoiceSession.resetTurn()` (driven by `turn_start`), which is the one
|
|
1195
|
+
* caller that knows the queued audio is stale. */
|
|
1196
|
+
resetTurn() {
|
|
1197
|
+
this.clearTurnBuffers();
|
|
1198
|
+
// Re-arm playback: the new turn's audio is legitimate.
|
|
1199
|
+
this.barged = false;
|
|
730
1200
|
this.sessionClient?.resetForNewTurn();
|
|
731
1201
|
}
|
|
732
1202
|
/**
|
|
@@ -735,14 +1205,19 @@ export class AudioPipeline {
|
|
|
735
1205
|
* When a session is attached, delegates to `AudioSessionClient.bargeIn()`
|
|
736
1206
|
* which sends the `barge_in` WebSocket action to the server, clears the
|
|
737
1207
|
* player queue, stops position tracking, and resets the playback tracker.
|
|
738
|
-
* Without a session we still clear local audio/visemes
|
|
739
|
-
*
|
|
740
|
-
*
|
|
1208
|
+
* Without a session we still clear local audio/visemes AND latch (the
|
|
1209
|
+
* server has no way to know, but any further chunks it streams for this
|
|
1210
|
+
* turn are DROPPED by the latch until `resetTurn()` re-arms playback —
|
|
1211
|
+
* AU.1a changed the old "the next chunk resumes playback" behavior).
|
|
741
1212
|
*
|
|
742
1213
|
* Returns the `InterruptResult` describing what was spoken when a session
|
|
743
1214
|
* is attached; returns null when there is no session.
|
|
744
1215
|
*/
|
|
745
1216
|
async bargeIn() {
|
|
1217
|
+
// Latch FIRST so a frame racing in while the (async) session barge-in
|
|
1218
|
+
// runs is dropped rather than scheduled (AU.1a). Cleared by resetTurn().
|
|
1219
|
+
this.barged = true;
|
|
1220
|
+
this.clearPendingEvents();
|
|
746
1221
|
let result = null;
|
|
747
1222
|
if (this.sessionClient) {
|
|
748
1223
|
result = await this.sessionClient.bargeIn();
|
|
@@ -751,20 +1226,36 @@ export class AudioPipeline {
|
|
|
751
1226
|
this.player.clearQueue();
|
|
752
1227
|
}
|
|
753
1228
|
this.visemeScheduler.clear();
|
|
754
|
-
this.
|
|
755
|
-
this.lastPhonemeEnd = 0;
|
|
756
|
-
this.pendingMetadata = [];
|
|
1229
|
+
this.clearTurnBuffers();
|
|
757
1230
|
return result;
|
|
758
1231
|
}
|
|
1232
|
+
/**
|
|
1233
|
+
* AU.3 — server-initiated flush (`{type:'tts_flush'}`): the server already
|
|
1234
|
+
* arbitrated a barge-in (auto barge-in via Deepgram StartOfTurn, or the
|
|
1235
|
+
* server echoing a button barge), so drop local audio/visemes and LATCH —
|
|
1236
|
+
* exactly `bargeIn()` minus the client→server `barge_in` send (sending it
|
|
1237
|
+
* back would double-cancel the NEXT turn's TTS context). Idempotent: a
|
|
1238
|
+
* second flush (e.g. button + server echo) is a no-op on empty queues.
|
|
1239
|
+
* The latch clears on the next server `turn_start` (`resetTurn()`).
|
|
1240
|
+
*/
|
|
1241
|
+
serverFlush() {
|
|
1242
|
+
this.barged = true;
|
|
1243
|
+
this.clearPendingEvents();
|
|
1244
|
+
this.player.clearQueue();
|
|
1245
|
+
// Mirror `AudioSessionClient.bargeIn()`'s local half: stop position
|
|
1246
|
+
// tracking + reset the word tracker for the next turn.
|
|
1247
|
+
this.sessionClient?.resetForNewTurn();
|
|
1248
|
+
this.visemeScheduler.clear();
|
|
1249
|
+
this.clearTurnBuffers();
|
|
1250
|
+
}
|
|
759
1251
|
/** Clean up all resources. */
|
|
760
1252
|
async destroy() {
|
|
761
1253
|
this._sessionClient?.cleanup();
|
|
762
1254
|
this._sessionClient = null;
|
|
763
1255
|
this.visemeScheduler.destroy();
|
|
764
1256
|
await this.player.stop();
|
|
765
|
-
this.
|
|
766
|
-
this.
|
|
767
|
-
this.pendingMetadata = [];
|
|
1257
|
+
this.clearTurnBuffers();
|
|
1258
|
+
this.barged = false;
|
|
768
1259
|
}
|
|
769
1260
|
}
|
|
770
1261
|
//# sourceMappingURL=audio.js.map
|