castle-web-cli 0.4.232 → 0.4.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +329 -11
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +309 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chrome.js +1144 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +109 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +9 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +378 -7
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +662 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +207 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +477 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +253 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
// Market-only Simlish synthesis from the round-3 audition. Two reusable
|
|
2
|
+
// 19-node graphs replace its per-line graph allocation; no text is spoken.
|
|
3
|
+
import { release } from './soundscapeSynthesis.js';
|
|
4
|
+
// Simlish-like NPC speech, round 3: gibberish with real consonants.
|
|
5
|
+
//
|
|
6
|
+
// makeSimlishVoice(context, destination) -> { say(text, time, voice), stop }
|
|
7
|
+
//
|
|
8
|
+
// The text only drives the shape: how many words, how long each is, where the
|
|
9
|
+
// commas and full stops fall and whether a sentence asks or exclaims. Every
|
|
10
|
+
// word becomes a pseudo-word of 1-3 syllables (CV or CVC) chosen by a seeded
|
|
11
|
+
// random from the word itself, so the same word always comes out as the same
|
|
12
|
+
// made-up word and nothing real is ever said.
|
|
13
|
+
//
|
|
14
|
+
// The voice is a small formant synthesiser:
|
|
15
|
+
//
|
|
16
|
+
// voicing osc (band-limited buzz, vibrato) -> level -> murmur low-pass
|
|
17
|
+
// (9 kHz, or ~400 Hz in a nasal) -> F1 -> F2 -> F3 -> F4
|
|
18
|
+
// (peaking filters in series) -> nasal notch -> presence shelf ->
|
|
19
|
+
// out -> 70 Hz high-pass
|
|
20
|
+
// breath noise -> aspiration level -> into the murmur low-pass (so "h"
|
|
21
|
+
// and the puff after p/t/k take the vowel's colour)
|
|
22
|
+
// frication noise -> place band-pass -> high-pass -> top cut -> level -> out
|
|
23
|
+
//
|
|
24
|
+
// Consonants are built from those parts on the context clock:
|
|
25
|
+
// p t k closure (voicing off), a burst through a band set by the place
|
|
26
|
+
// (lips ~1 kHz broad, tongue tip ~4 kHz, back ~2 kHz near the
|
|
27
|
+
// vowel's F2), then 25-40 ms of aspiration before the voice starts
|
|
28
|
+
// b d g the same with a voice bar in the closure (voicing low-passed to
|
|
29
|
+
// ~400 Hz), a softer burst and the voice starting at once
|
|
30
|
+
// s sh f sustained frication: s 6.5 kHz band over a 4 kHz high-pass, sh
|
|
31
|
+
// 3 kHz, f broad and soft; voicing off underneath
|
|
32
|
+
// h aspiration only, through the next vowel's formants
|
|
33
|
+
// m n voicing low-passed (the murmur) with a notch (antiresonance) at
|
|
34
|
+
// 1.1 / 1.7 kHz, F1 low, then a quick release into the vowel
|
|
35
|
+
// l r w y voiced, formants held at the liquid's own shape (r with F3 pulled
|
|
36
|
+
// down to ~1.7 kHz), then a slow glide into the vowel
|
|
37
|
+
// and every consonant moves the formants from its place's locus to the vowel
|
|
38
|
+
// (or from the vowel to it, in a coda).
|
|
39
|
+
//
|
|
40
|
+
// Every level and frequency is a list of breakpoints joined by linear ramps:
|
|
41
|
+
// no value ever steps, the shortest gain ramp is 3 ms, and the noise path is
|
|
42
|
+
// exactly 0 between consonants. No global low-pass: frication reaches 10 kHz.
|
|
43
|
+
//
|
|
44
|
+
// One reusable NODE_COUNT graph per pool slot, whatever the line length;
|
|
45
|
+
// the full line is scheduled at once, then its three envelopes close.
|
|
46
|
+
|
|
47
|
+
const LETTER = /[\p{L}\p{N}']/u;
|
|
48
|
+
export const TUNE = { shelfHz: 3000, shelfDb: 0, fric: 3, asp: 1.3, burst: 2, formantDb: [14, 15, 12, 9], formantQ: [4, 6, 7, 5], tilt: 1.3, voiceTop: 9000 };
|
|
49
|
+
|
|
50
|
+
export const NODE_COUNT = 19;
|
|
51
|
+
|
|
52
|
+
// [F1, F2, F3, F4] Hz, an adult's; scaled by `mouth`.
|
|
53
|
+
const VOWELS = {
|
|
54
|
+
a: [800, 1250, 2650, 3550],
|
|
55
|
+
e: [520, 1850, 2600, 3550],
|
|
56
|
+
i: [320, 2350, 3000, 3750],
|
|
57
|
+
o: [540, 920, 2500, 3450],
|
|
58
|
+
u: [360, 880, 2350, 3400],
|
|
59
|
+
ae: [700, 1720, 2600, 3550],
|
|
60
|
+
uh: [640, 1220, 2550, 3500],
|
|
61
|
+
};
|
|
62
|
+
const DIPHTHONGS = { ai: ['a', 'i'], ou: ['o', 'u'], ei: ['e', 'i'], oi: ['o', 'i'] };
|
|
63
|
+
|
|
64
|
+
const KIND = {
|
|
65
|
+
p: 'stop', t: 'stop', k: 'stop', b: 'stop', d: 'stop', g: 'stop',
|
|
66
|
+
s: 'fric', sh: 'fric', f: 'fric', h: 'h',
|
|
67
|
+
m: 'nasal', n: 'nasal',
|
|
68
|
+
l: 'liquid', r: 'liquid', w: 'liquid', y: 'liquid',
|
|
69
|
+
};
|
|
70
|
+
const VOICED = new Set(['b', 'd', 'g']);
|
|
71
|
+
const PLACE = { p: 'lab', b: 'lab', m: 'lab', f: 'lab', w: 'lab', t: 'alv', d: 'alv', n: 'alv', s: 'alv', l: 'alv', sh: 'post', r: 'post', y: 'pal', k: 'vel', g: 'vel', h: 'glot' };
|
|
72
|
+
|
|
73
|
+
// Weighted choices; Simlish leans on b, l, n, m, sh and open vowels.
|
|
74
|
+
const ONSETS = [['b', 11], ['d', 7], ['g', 5], ['p', 6], ['t', 6], ['k', 7], ['s', 9], ['sh', 7], ['f', 5], ['h', 4], ['m', 8], ['n', 8], ['l', 9], ['r', 5], ['w', 5], ['y', 3]];
|
|
75
|
+
const CODAS = [['n', 22], ['m', 9], ['l', 14], ['s', 14], ['sh', 7], ['k', 10], ['t', 9], ['b', 5], ['r', 5], ['g', 5]];
|
|
76
|
+
const NUCLEI = [['a', 20], ['e', 13], ['i', 12], ['o', 14], ['u', 9], ['ae', 7], ['uh', 8], ['ai', 6], ['ou', 4], ['ei', 4], ['oi', 3]];
|
|
77
|
+
|
|
78
|
+
function hashOf(text) {
|
|
79
|
+
let h = 0x811c9dc5;
|
|
80
|
+
const s = String(text);
|
|
81
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
82
|
+
h ^= s.charCodeAt(i);
|
|
83
|
+
h = Math.imul(h, 0x01000193);
|
|
84
|
+
}
|
|
85
|
+
return h >>> 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function seeded(seed) {
|
|
89
|
+
let a = seed >>> 0;
|
|
90
|
+
return () => {
|
|
91
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
92
|
+
let t = a;
|
|
93
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
94
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
95
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function pick(list, next) {
|
|
100
|
+
let total = 0;
|
|
101
|
+
for (const [, w] of list) {
|
|
102
|
+
total += w;
|
|
103
|
+
}
|
|
104
|
+
let r = next() * total;
|
|
105
|
+
for (const [v, w] of list) {
|
|
106
|
+
r -= w;
|
|
107
|
+
if (r < 0) {
|
|
108
|
+
return v;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return list[0][0];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// One made-up word of `n` syllables.
|
|
115
|
+
function makeSylls(n, next) {
|
|
116
|
+
const sylls = [];
|
|
117
|
+
for (let i = 0; i < n; i += 1) {
|
|
118
|
+
const onset = i > 0 || next() < 0.88 ? pick(ONSETS, next) : null;
|
|
119
|
+
const last = i === n - 1;
|
|
120
|
+
const coda = next() < (last ? 0.42 : 0.22) ? pick(CODAS, next) : null;
|
|
121
|
+
sylls.push({ onset, nucleus: pick(NUCLEI, next), coda });
|
|
122
|
+
}
|
|
123
|
+
return sylls;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Common English one-syllable words as these syllables would sound them
|
|
127
|
+
// ("mi" is "me", "tu" is "two"); a one-syllable pseudo-word that lands on one
|
|
128
|
+
// is drawn again, so nothing real slips out. Longer words are not checked.
|
|
129
|
+
const REAL = new Set(`bi di ki mi ni pi ti si shi fi hi li wi bo do go mo no to so sho fo ho lo ro wo yo bu du gu ku mu nu pu tu su shu hu lu ru wu yu
|
|
130
|
+
ba ma pa la ha sha bai dai gai mai nai pai tai sai shai hai lai rai wai bei dei gei kei mei nei pei sei hei lei rei wei yei bou dou gou mou nou tou sou shou lou rou
|
|
131
|
+
boi toi soi koi bin pin tin din sin kin fin win yes bes ben ten den hen men pen yen ban man pan tan fan ran can kan son sun fun gun run bun nun don
|
|
132
|
+
bit bet bat but pit pet pat pot put kit kat cut kut hit hat hot hut lit let lot nut not net sit set sat sot fit fat wit wet yet rat rot rut mat met
|
|
133
|
+
bad bed bid bud bod dad did had hid mad mud red rid rod sad kid lid led god bag big bog bug dig dog fig hog hug log leg lag rag rig wig pig peg mug
|
|
134
|
+
sob rob rib rub mob web bus mis mes pas gas has his yes kis los nos dos sis sash mash bash rash lash cash dish fish wish push bush rush mush gush
|
|
135
|
+
bel bil bal tel til tal sel sil kil kal fel fil fal hel hil hal mel mil mal nil wel wil pil pal dal dil dol gal gol gul hol pol pul sol tol
|
|
136
|
+
bik bak bek bok buk lik lak lek lok luk sik sak tik tak tok tuk pik pak pek pok puk nik nek nok rak rok ruk sek sok kik kak hik hak hok huk
|
|
137
|
+
bom tom mom mum sum som dim him hem ham jam ram rim tim gum gem rum lum`.split(/\s+/));
|
|
138
|
+
|
|
139
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
140
|
+
const num = (v, fallback) => (typeof v === 'number' && Number.isFinite(v) ? v : fallback);
|
|
141
|
+
|
|
142
|
+
export const VOICE_DEFAULTS = {
|
|
143
|
+
pitch: 240, // Hz, the voice's resting pitch
|
|
144
|
+
rate: 4.2, // syllables a second
|
|
145
|
+
mouth: 1.08, // formant scale (a smaller mouth, higher formants)
|
|
146
|
+
spread: 3, // semitones of word accent
|
|
147
|
+
lift: 1, // how far ?, ! and . move the tune
|
|
148
|
+
bounce: 0, // semitones of syllable-to-syllable hop
|
|
149
|
+
vibrato: 9, // cents
|
|
150
|
+
wordGap: 0.045, // seconds between pseudo-words
|
|
151
|
+
level: 0.5,
|
|
152
|
+
seed: 0, // varies the made-up words between speakers
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// --- the plan ----------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
// A line as sentences of words of syllables { onset, nucleus, coda }.
|
|
158
|
+
export function simlishWords(text, seed = 0) {
|
|
159
|
+
const sentences = [];
|
|
160
|
+
let words = [];
|
|
161
|
+
let word = '';
|
|
162
|
+
const flushWord = (pauseAfter) => {
|
|
163
|
+
if (word) {
|
|
164
|
+
const n = clamp(Math.round(word.replace(/'/g, '').length / 3.2), 1, 3);
|
|
165
|
+
const next = seeded(hashOf(word.toLowerCase()) ^ seed);
|
|
166
|
+
let sylls = [];
|
|
167
|
+
for (let tries = 0; tries < 8; tries += 1) {
|
|
168
|
+
sylls = makeSylls(n, next);
|
|
169
|
+
if (n > 1 || !REAL.has(sylls.map((y) => `${y.onset ?? ''}${y.nucleus}${y.coda ?? ''}`).join(''))) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
words.push({ sylls, pause: 0 });
|
|
174
|
+
word = '';
|
|
175
|
+
}
|
|
176
|
+
if (pauseAfter && words.length) {
|
|
177
|
+
words[words.length - 1].pause = Math.max(words[words.length - 1].pause, pauseAfter);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const close = (mark) => {
|
|
181
|
+
flushWord(0);
|
|
182
|
+
if (words.length) {
|
|
183
|
+
sentences.push({ words, mark });
|
|
184
|
+
words = [];
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
for (const ch of String(text ?? '')) {
|
|
188
|
+
if (LETTER.test(ch)) {
|
|
189
|
+
word += ch;
|
|
190
|
+
} else if ('.!?…'.includes(ch)) {
|
|
191
|
+
close(ch === '…' ? '.' : ch);
|
|
192
|
+
} else if (',;:—–'.includes(ch)) {
|
|
193
|
+
flushWord(0.19);
|
|
194
|
+
} else {
|
|
195
|
+
flushWord(0);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
close('.');
|
|
199
|
+
return sentences;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// --- the synthesiser -----------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
// One band-limited 1/n buzz per context (a glottal source after radiation);
|
|
205
|
+
// the browser drops partials above Nyquist on its own.
|
|
206
|
+
const buzzes = new WeakMap();
|
|
207
|
+
function buzzOf(ctx, tilt) {
|
|
208
|
+
let set = buzzes.get(ctx);
|
|
209
|
+
if (!set) {
|
|
210
|
+
set = new Map();
|
|
211
|
+
buzzes.set(ctx, set);
|
|
212
|
+
}
|
|
213
|
+
let w = set.get(tilt);
|
|
214
|
+
if (!w) {
|
|
215
|
+
const n = 64;
|
|
216
|
+
const real = new Float32Array(n + 1);
|
|
217
|
+
const imag = new Float32Array(n + 1);
|
|
218
|
+
for (let i = 1; i <= n; i += 1) {
|
|
219
|
+
imag[i] = 1 / i ** tilt;
|
|
220
|
+
}
|
|
221
|
+
w = ctx.createPeriodicWave(real, imag);
|
|
222
|
+
set.set(tilt, w);
|
|
223
|
+
}
|
|
224
|
+
return w;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Three seconds of DC-free white noise per context, its loop seam
|
|
228
|
+
// cross-faded so the wrap is just more noise.
|
|
229
|
+
const noises = new WeakMap();
|
|
230
|
+
function noiseOf(ctx) {
|
|
231
|
+
let b = noises.get(ctx);
|
|
232
|
+
if (!b) {
|
|
233
|
+
const n = Math.floor(ctx.sampleRate * 3);
|
|
234
|
+
const fade = 2048;
|
|
235
|
+
b = ctx.createBuffer(1, n, ctx.sampleRate);
|
|
236
|
+
const d = b.getChannelData(0);
|
|
237
|
+
const next = seeded(0x51a1);
|
|
238
|
+
const raw = new Float32Array(n + fade);
|
|
239
|
+
let mean = 0;
|
|
240
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
241
|
+
raw[i] = next() * 2 - 1;
|
|
242
|
+
mean += raw[i];
|
|
243
|
+
}
|
|
244
|
+
mean /= raw.length;
|
|
245
|
+
for (let i = 0; i < n; i += 1) {
|
|
246
|
+
d[i] = raw[i] - mean;
|
|
247
|
+
}
|
|
248
|
+
// The tail beyond n fades into the head, equal power.
|
|
249
|
+
for (let i = 0; i < fade; i += 1) {
|
|
250
|
+
const a = (i + 0.5) / fade;
|
|
251
|
+
d[i] = d[i] * Math.sin(a * Math.PI / 2) + (raw[n + i] - mean) * Math.cos(a * Math.PI / 2);
|
|
252
|
+
}
|
|
253
|
+
noises.set(ctx, b);
|
|
254
|
+
}
|
|
255
|
+
return b;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Breakpoint lists, emitted as linear ramps.
|
|
259
|
+
class Track {
|
|
260
|
+
constructor(value) {
|
|
261
|
+
this.points = [[0, value]];
|
|
262
|
+
}
|
|
263
|
+
at(t, v) {
|
|
264
|
+
this.points.push([t, v]);
|
|
265
|
+
}
|
|
266
|
+
apply(param, t0) {
|
|
267
|
+
const pts = this.points.slice(1).sort((a, b) => a[0] - b[0]);
|
|
268
|
+
param.setValueAtTime(this.points[0][1], t0);
|
|
269
|
+
let last = t0;
|
|
270
|
+
for (const [t, v] of pts) {
|
|
271
|
+
const at = Math.max(t0 + t, last + 0.0005);
|
|
272
|
+
param.linearRampToValueAtTime(v, at);
|
|
273
|
+
last = at;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function scheduleLine(context, graph, text, startTime, voice = {}) {
|
|
280
|
+
const ctx = context;
|
|
281
|
+
const v = { ...VOICE_DEFAULTS, ...voice };
|
|
282
|
+
const pitch = clamp(num(v.pitch, 240), 90, 600);
|
|
283
|
+
const rate = clamp(num(v.rate, 4.2), 2.5, 8);
|
|
284
|
+
const mouth = clamp(num(v.mouth, 1.08), 0.8, 1.35);
|
|
285
|
+
const k = clamp(4.2 / rate, 0.75, 1.3);
|
|
286
|
+
const tune = { ...TUNE, ...(v.tune ?? {}) };
|
|
287
|
+
const sentences = simlishWords(text, v.seed >>> 0);
|
|
288
|
+
if (!sentences.length || !Number.isFinite(startTime)) {
|
|
289
|
+
return startTime;
|
|
290
|
+
}
|
|
291
|
+
const rnd = seeded(hashOf(text) ^ 0x5171 ^ (v.seed >>> 0));
|
|
292
|
+
const vowelOf = (name) => (VOWELS[name] ?? VOWELS.a).map((f, i) => f * (i < 3 ? mouth : 0.5 + 0.5 * mouth));
|
|
293
|
+
|
|
294
|
+
// Tracks, in seconds from startTime.
|
|
295
|
+
const P = new Track(pitch);
|
|
296
|
+
const VE = new Track(0);
|
|
297
|
+
const OPEN = tune.voiceTop;
|
|
298
|
+
const SL = new Track(OPEN);
|
|
299
|
+
const AS = new Track(0);
|
|
300
|
+
const FG = new Track(0);
|
|
301
|
+
const FB = new Track(4000);
|
|
302
|
+
const FQ = new Track(1);
|
|
303
|
+
const FH = new Track(2000);
|
|
304
|
+
const NG = new Track(0);
|
|
305
|
+
const NF = new Track(1400);
|
|
306
|
+
const first = sentences[0].words[0].sylls[0];
|
|
307
|
+
const firstV = vowelOf(DIPHTHONGS[first.nucleus]?.[0] ?? first.nucleus);
|
|
308
|
+
const F = [0, 1, 2, 3].map((i) => new Track(firstV[i]));
|
|
309
|
+
const formantsTo = (t, fs) => fs.forEach((f, i) => F[i].at(t, f));
|
|
310
|
+
|
|
311
|
+
// Where the formants start from (onset) or head to (coda) for a consonant
|
|
312
|
+
// next to vowel `fv`.
|
|
313
|
+
function locus(c, fv) {
|
|
314
|
+
const [f1, f2, f3, f4] = fv;
|
|
315
|
+
switch (c) {
|
|
316
|
+
case 'l': return [380 * mouth, 1150 * mouth, 2850 * mouth, f4];
|
|
317
|
+
case 'r': return [420 * mouth, 1150 * mouth, 1700 * mouth, f4];
|
|
318
|
+
case 'w': return [310 * mouth, 760 * mouth, 2300 * mouth, f4];
|
|
319
|
+
case 'y': return [290 * mouth, 2250 * mouth, 3050 * mouth, f4];
|
|
320
|
+
case 'h': return fv;
|
|
321
|
+
default: break;
|
|
322
|
+
}
|
|
323
|
+
const place = PLACE[c];
|
|
324
|
+
const low = KIND[c] === 'fric' ? f1 * 0.8 : 270 * mouth;
|
|
325
|
+
if (place === 'lab') {
|
|
326
|
+
return [low, f2 * 0.62 + 300 * mouth, f3 * 0.9, f4];
|
|
327
|
+
}
|
|
328
|
+
if (place === 'alv') {
|
|
329
|
+
return [low, 1750 * mouth * 0.6 + f2 * 0.4, Math.max(f3, 2700 * mouth), f4];
|
|
330
|
+
}
|
|
331
|
+
if (place === 'post') {
|
|
332
|
+
return [low, 1900 * mouth * 0.6 + f2 * 0.4, Math.min(f3, 2450 * mouth), f4];
|
|
333
|
+
}
|
|
334
|
+
// Velar: F2 and F3 pinch together near the vowel's F2.
|
|
335
|
+
const pinch = Math.max(f2 * 1.08, 1450 * mouth);
|
|
336
|
+
return [low, pinch, Math.min(f3, pinch * 1.18), f4];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// The frication band for a burst or a fricative at this place.
|
|
340
|
+
function band(c, fv) {
|
|
341
|
+
switch (PLACE[c]) {
|
|
342
|
+
case 'lab': return c === 'f' ? [5200, 0.45, 1400, 9000] : [1100, 0.7, 500, 6000];
|
|
343
|
+
case 'alv': return c === 's' ? [6200, 1.8, 4000, 11000] : [4200, 1.1, 2500, 9000];
|
|
344
|
+
case 'post': return [3000, 1.7, 1800, 7500];
|
|
345
|
+
default: return [clamp(fv[1] * 1.15, 1500, 2900), 2.2, 900, 6000];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const FL = new Track(9000);
|
|
349
|
+
const setBand = (at, c, fv) => {
|
|
350
|
+
const [bf, bq, bh, top] = band(c, fv);
|
|
351
|
+
FB.at(at, bf);
|
|
352
|
+
FQ.at(at, bq);
|
|
353
|
+
FH.at(at, bh);
|
|
354
|
+
FL.at(at, top);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
let t = 0.005;
|
|
358
|
+
let pitchIndex = 0;
|
|
359
|
+
for (const sentence of sentences) {
|
|
360
|
+
const words = sentence.words;
|
|
361
|
+
const sylCount = words.reduce((n, w) => n + w.sylls.length, 0);
|
|
362
|
+
let si = 0;
|
|
363
|
+
const lift = num(v.lift, 1);
|
|
364
|
+
for (let wi = 0; wi < words.length; wi += 1) {
|
|
365
|
+
const word = words[wi];
|
|
366
|
+
const accent = (rnd() * 0.8 + 0.2) * num(v.spread, 3) * (rnd() < 0.7 ? 1 : -0.4);
|
|
367
|
+
for (let yi = 0; yi < word.sylls.length; yi += 1) {
|
|
368
|
+
const syl = word.sylls[yi];
|
|
369
|
+
const finalSyl = si === sylCount - 1;
|
|
370
|
+
const stressed = yi === 0;
|
|
371
|
+
const phraseStart = t < 0.01 || VE.points[VE.points.length - 1][1] === 0;
|
|
372
|
+
const parts = DIPHTHONGS[syl.nucleus] ?? [syl.nucleus];
|
|
373
|
+
const fv = vowelOf(parts[0]);
|
|
374
|
+
const fv2 = parts[1] ? vowelOf(parts[1]) : null;
|
|
375
|
+
// Pitch: declination, a word accent, a bounce, the sentence's ending.
|
|
376
|
+
const pos = sylCount > 1 ? si / (sylCount - 1) : 1;
|
|
377
|
+
let semi = 2 - 3.5 * pos + (stressed ? accent : accent * 0.35) + (pitchIndex % 2 ? -1 : 1) * num(v.bounce, 0) * 0.5;
|
|
378
|
+
let endGlide = (rnd() - 0.5) * 0.8;
|
|
379
|
+
if (sentence.mark === '?') {
|
|
380
|
+
if (si === sylCount - 2) {
|
|
381
|
+
semi += 3 * lift;
|
|
382
|
+
} else if (finalSyl) {
|
|
383
|
+
semi += 6 * lift;
|
|
384
|
+
endGlide = 4 * lift;
|
|
385
|
+
}
|
|
386
|
+
} else if (sentence.mark === '!') {
|
|
387
|
+
semi += 2.5 * lift;
|
|
388
|
+
if (si === sylCount - 2) {
|
|
389
|
+
semi += 3 * lift;
|
|
390
|
+
} else if (finalSyl) {
|
|
391
|
+
semi += 1.5 * lift;
|
|
392
|
+
endGlide = -4 * lift;
|
|
393
|
+
}
|
|
394
|
+
} else if (finalSyl) {
|
|
395
|
+
semi -= 2.5 * lift;
|
|
396
|
+
endGlide = -3 * lift;
|
|
397
|
+
} else if (si === sylCount - 2) {
|
|
398
|
+
semi -= 0.8 * lift;
|
|
399
|
+
}
|
|
400
|
+
pitchIndex += 1;
|
|
401
|
+
const level = (stressed ? 1 : 0.8) * (sentence.mark === '!' ? 1.1 : 1) * (0.92 + rnd() * 0.16);
|
|
402
|
+
const slot = (1 / (rate * 1.17)) * (0.88 + rnd() * 0.24) * (stressed ? 1.08 : 0.94) * (finalSyl ? 1.45 : 1);
|
|
403
|
+
|
|
404
|
+
// --- onset ---
|
|
405
|
+
const c = syl.onset;
|
|
406
|
+
const kind = c ? KIND[c] : null;
|
|
407
|
+
let tv = t; // voicing (vowel) onset
|
|
408
|
+
let cDur = 0;
|
|
409
|
+
const L = c ? locus(c, fv) : null;
|
|
410
|
+
if (!c) {
|
|
411
|
+
if (!phraseStart) {
|
|
412
|
+
// A vowel after a vowel: a glottal dip.
|
|
413
|
+
VE.at(t, level * 0.8);
|
|
414
|
+
VE.at(t + 0.015, level * 0.35);
|
|
415
|
+
tv = t + 0.03;
|
|
416
|
+
}
|
|
417
|
+
} else if (kind === 'stop') {
|
|
418
|
+
const voiced = VOICED.has(c);
|
|
419
|
+
const closure = (phraseStart ? 0.03 : 0.045) * k;
|
|
420
|
+
const burst = (PLACE[c] === 'vel' ? 0.016 : PLACE[c] === 'lab' ? 0.008 : 0.012) * k;
|
|
421
|
+
const vot = voiced ? 0.006 : (PLACE[c] === 'vel' ? 0.04 : 0.032) * k;
|
|
422
|
+
const tb = t + closure;
|
|
423
|
+
if (voiced) {
|
|
424
|
+
SL.at(t, OPEN);
|
|
425
|
+
SL.at(t + 0.015, 420);
|
|
426
|
+
VE.at(t + 0.015, 0.13);
|
|
427
|
+
VE.at(tb - 0.003, 0.11);
|
|
428
|
+
} else {
|
|
429
|
+
VE.at(t + 0.014, 0);
|
|
430
|
+
}
|
|
431
|
+
formantsTo(t + closure * 0.6, L);
|
|
432
|
+
setBand(tb - 0.006, c, fv);
|
|
433
|
+
const bl = tune.burst * (voiced ? 0.42 : 0.7) * (PLACE[c] === 'lab' ? 0.75 : 1);
|
|
434
|
+
FG.at(tb, 0);
|
|
435
|
+
FG.at(tb + 0.003, bl);
|
|
436
|
+
FG.at(tb + burst, bl * 0.3);
|
|
437
|
+
FG.at(tb + burst + 0.012, 0);
|
|
438
|
+
if (!voiced) {
|
|
439
|
+
AS.at(tb + 0.004, 0);
|
|
440
|
+
AS.at(tb + 0.012, tune.asp * 0.22);
|
|
441
|
+
AS.at(tb + burst + vot - 0.004, tune.asp * 0.14);
|
|
442
|
+
AS.at(tb + burst + vot + 0.012, 0);
|
|
443
|
+
}
|
|
444
|
+
tv = tb + burst + vot;
|
|
445
|
+
if (voiced) {
|
|
446
|
+
SL.at(tb, 420);
|
|
447
|
+
SL.at(tb + 0.008, OPEN);
|
|
448
|
+
SL.at(tb + 0.009, OPEN);
|
|
449
|
+
}
|
|
450
|
+
formantsTo(tb, L);
|
|
451
|
+
F[0].at(tv, 260 * mouth);
|
|
452
|
+
cDur = tv - t;
|
|
453
|
+
} else if (kind === 'fric') {
|
|
454
|
+
const d = (c === 'f' ? 0.075 : 0.088) * k;
|
|
455
|
+
VE.at(t + 0.016, 0);
|
|
456
|
+
setBand(t, c, fv);
|
|
457
|
+
const fl = tune.fric * (c === 's' ? 0.5 : c === 'sh' ? 0.42 : 0.2);
|
|
458
|
+
FG.at(t, 0);
|
|
459
|
+
FG.at(t + 0.022, fl);
|
|
460
|
+
FG.at(t + d - 0.014, fl * 0.9);
|
|
461
|
+
FG.at(t + d + 0.008, 0);
|
|
462
|
+
formantsTo(t + d * 0.5, L);
|
|
463
|
+
tv = t + d - 0.008;
|
|
464
|
+
cDur = d;
|
|
465
|
+
} else if (kind === 'h') {
|
|
466
|
+
const d = 0.055 * k;
|
|
467
|
+
VE.at(t + 0.014, 0);
|
|
468
|
+
formantsTo(t + 0.02, fv);
|
|
469
|
+
AS.at(t, 0);
|
|
470
|
+
AS.at(t + 0.02, tune.asp * 0.3);
|
|
471
|
+
AS.at(t + d, tune.asp * 0.24);
|
|
472
|
+
AS.at(t + d + 0.02, 0);
|
|
473
|
+
tv = t + d - 0.004;
|
|
474
|
+
cDur = d;
|
|
475
|
+
} else if (kind === 'nasal') {
|
|
476
|
+
const d = 0.062 * k;
|
|
477
|
+
SL.at(t, OPEN);
|
|
478
|
+
SL.at(t + 0.012, 380);
|
|
479
|
+
NF.at(t, c === 'm' ? 1100 * mouth : 1700 * mouth);
|
|
480
|
+
NG.at(t, 0);
|
|
481
|
+
NG.at(t + 0.012, -22);
|
|
482
|
+
VE.at(t + 0.012, 0.6 * level);
|
|
483
|
+
formantsTo(t + 0.012, L);
|
|
484
|
+
SL.at(t + d, 380);
|
|
485
|
+
SL.at(t + d + 0.012, OPEN);
|
|
486
|
+
NG.at(t + d, -22);
|
|
487
|
+
NG.at(t + d + 0.016, 0);
|
|
488
|
+
tv = t + d;
|
|
489
|
+
cDur = d;
|
|
490
|
+
} else {
|
|
491
|
+
// Liquids and glides: voiced, a held shape, then a slow glide.
|
|
492
|
+
const d = 0.055 * k;
|
|
493
|
+
VE.at(t + 0.012, 0.62 * level);
|
|
494
|
+
formantsTo(t + 0.012, L);
|
|
495
|
+
formantsTo(t + d * 0.55, L);
|
|
496
|
+
tv = t + d;
|
|
497
|
+
cDur = d;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// --- coda length, decided before the vowel takes the rest ---
|
|
501
|
+
const cc = syl.coda;
|
|
502
|
+
const ckind = cc ? KIND[cc] : null;
|
|
503
|
+
const codaDur = !cc ? 0 : ckind === 'stop' ? 0.05 * k : ckind === 'fric' ? 0.075 * k : 0.055 * k;
|
|
504
|
+
// The vowel takes what the syllable's slot leaves, after the
|
|
505
|
+
// consonants and (ending a word) the gap before the next.
|
|
506
|
+
const lastOfWordHere = yi === word.sylls.length - 1;
|
|
507
|
+
const tail = lastOfWordHere && !word.pause && wi < words.length - 1 ? num(v.wordGap, 0.045) * k + 0.028 : 0;
|
|
508
|
+
const vd = Math.max(0.06, slot - cDur - codaDur - tail);
|
|
509
|
+
const ve = tv + vd;
|
|
510
|
+
|
|
511
|
+
// --- vowel ---
|
|
512
|
+
if (phraseStart && !c) {
|
|
513
|
+
VE.at(tv, 0);
|
|
514
|
+
} else if (kind !== 'nasal' && kind !== 'liquid' && !(kind === 'stop' && VOICED.has(c))) {
|
|
515
|
+
VE.at(tv, 0);
|
|
516
|
+
}
|
|
517
|
+
VE.at(tv + (kind === 'liquid' || kind === 'nasal' ? 0.025 : 0.022), level);
|
|
518
|
+
VE.at(ve - 0.01, level * 0.86);
|
|
519
|
+
// Formant transition from the onset into the vowel.
|
|
520
|
+
const glide = kind === 'liquid' ? 0.065 : kind === 'nasal' ? 0.045 : 0.05;
|
|
521
|
+
formantsTo(tv + glide, fv);
|
|
522
|
+
if (fv2) {
|
|
523
|
+
formantsTo(tv + vd * 0.35, fv);
|
|
524
|
+
formantsTo(tv + vd * 0.9, fv2);
|
|
525
|
+
} else {
|
|
526
|
+
formantsTo(ve - 0.005, fv.map((f, i) => (i === 1 ? f * (0.97 + rnd() * 0.06) : f)));
|
|
527
|
+
}
|
|
528
|
+
// Pitch: into this syllable's note, a little higher after a voiceless
|
|
529
|
+
// consonant, then the syllable's own drift.
|
|
530
|
+
const hz = (s) => pitch * 2 ** (s / 12);
|
|
531
|
+
const push = c && !VOICED.has(c) && kind !== 'nasal' && kind !== 'liquid' ? 0.6 : 0;
|
|
532
|
+
P.at(tv, hz(semi + push));
|
|
533
|
+
P.at(tv + Math.min(0.06, vd * 0.4), hz(semi));
|
|
534
|
+
P.at(ve, hz(semi + endGlide));
|
|
535
|
+
|
|
536
|
+
// --- coda ---
|
|
537
|
+
let tEnd = ve;
|
|
538
|
+
if (cc) {
|
|
539
|
+
const fEnd = fv2 ?? fv;
|
|
540
|
+
const Lc = locus(cc, fEnd);
|
|
541
|
+
if (ckind === 'stop') {
|
|
542
|
+
const voiced = VOICED.has(cc);
|
|
543
|
+
const closure = 0.036 * k;
|
|
544
|
+
formantsTo(ve + 0.02, Lc);
|
|
545
|
+
if (voiced) {
|
|
546
|
+
SL.at(ve, OPEN);
|
|
547
|
+
SL.at(ve + 0.015, 420);
|
|
548
|
+
VE.at(ve + 0.015, 0.1);
|
|
549
|
+
VE.at(ve + closure - 0.004, 0.08);
|
|
550
|
+
VE.at(ve + closure + 0.004, 0);
|
|
551
|
+
SL.at(ve + closure + 0.006, 420);
|
|
552
|
+
SL.at(ve + closure + 0.016, OPEN);
|
|
553
|
+
} else {
|
|
554
|
+
VE.at(ve + 0.014, 0);
|
|
555
|
+
}
|
|
556
|
+
const tb = ve + closure;
|
|
557
|
+
setBand(tb - 0.006, cc, fEnd);
|
|
558
|
+
FG.at(tb, 0);
|
|
559
|
+
FG.at(tb + 0.003, tune.burst * (voiced ? 0.25 : 0.4));
|
|
560
|
+
FG.at(tb + 0.01, tune.burst * 0.1);
|
|
561
|
+
FG.at(tb + 0.022, 0);
|
|
562
|
+
tEnd = tb + 0.022;
|
|
563
|
+
} else if (ckind === 'fric') {
|
|
564
|
+
const d = codaDur;
|
|
565
|
+
setBand(ve - 0.01, cc, fEnd);
|
|
566
|
+
VE.at(ve + 0.014, 0);
|
|
567
|
+
const fl = tune.fric * (cc === 's' ? 0.45 : cc === 'sh' ? 0.38 : 0.18);
|
|
568
|
+
FG.at(ve - 0.006, 0);
|
|
569
|
+
FG.at(ve + 0.016, fl);
|
|
570
|
+
FG.at(ve + d - 0.02, fl * 0.7);
|
|
571
|
+
FG.at(ve + d, 0);
|
|
572
|
+
formantsTo(ve + 0.02, Lc);
|
|
573
|
+
tEnd = ve + d;
|
|
574
|
+
} else if (ckind === 'nasal') {
|
|
575
|
+
const d = codaDur;
|
|
576
|
+
NF.at(ve, cc === 'm' ? 1100 * mouth : 1700 * mouth);
|
|
577
|
+
formantsTo(ve + 0.03, Lc);
|
|
578
|
+
SL.at(ve, OPEN);
|
|
579
|
+
SL.at(ve + 0.015, 380);
|
|
580
|
+
NG.at(ve, 0);
|
|
581
|
+
NG.at(ve + 0.015, -22);
|
|
582
|
+
VE.at(ve + 0.015, 0.55 * level);
|
|
583
|
+
VE.at(ve + d - 0.008, 0.45 * level);
|
|
584
|
+
NG.at(ve + d + 0.02, -22);
|
|
585
|
+
NG.at(ve + d + 0.035, 0);
|
|
586
|
+
SL.at(ve + d + 0.02, 380);
|
|
587
|
+
SL.at(ve + d + 0.035, OPEN);
|
|
588
|
+
tEnd = ve + d;
|
|
589
|
+
} else {
|
|
590
|
+
const d = codaDur;
|
|
591
|
+
formantsTo(ve + d * 0.7, Lc);
|
|
592
|
+
VE.at(ve + d * 0.7, 0.6 * level);
|
|
593
|
+
tEnd = ve + d;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
// End of a word: let the voice go; the next onset (or the pause)
|
|
597
|
+
// takes it from there.
|
|
598
|
+
const lastOfWord = yi === word.sylls.length - 1;
|
|
599
|
+
if (lastOfWord) {
|
|
600
|
+
const gap = word.pause || (wi === words.length - 1 ? 0 : num(v.wordGap, 0.045) * k);
|
|
601
|
+
const nextOnset = words[wi + 1]?.sylls[0]?.onset;
|
|
602
|
+
const ending = word.pause || wi === words.length - 1 || !nextOnset || KIND[nextOnset] === 'liquid' || KIND[nextOnset] === 'nasal';
|
|
603
|
+
if (ending || gap > 0.03) {
|
|
604
|
+
// Voice out over 25-45 ms (longer at a pause).
|
|
605
|
+
const fall = word.pause || wi === words.length - 1 ? 0.06 : 0.028;
|
|
606
|
+
VE.at(tEnd, VE.points[VE.points.length - 1][1]);
|
|
607
|
+
VE.at(tEnd + fall, 0);
|
|
608
|
+
tEnd += fall;
|
|
609
|
+
}
|
|
610
|
+
t = tEnd + gap;
|
|
611
|
+
} else {
|
|
612
|
+
t = tEnd;
|
|
613
|
+
}
|
|
614
|
+
si += 1;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
// Between sentences.
|
|
618
|
+
t += 0.36 * k;
|
|
619
|
+
}
|
|
620
|
+
const duration = t;
|
|
621
|
+
const end = startTime + duration + 0.05;
|
|
622
|
+
|
|
623
|
+
const { src, vibDepth, murmur, voiceEnv, formants, notch, out, asp, fricBand, fricHigh, fricTop, fric } = graph;
|
|
624
|
+
for (const node of Object.values(graph).flat()) {
|
|
625
|
+
for (const key of ['gain', 'frequency', 'Q']) { node[key]?.cancelScheduledValues(startTime); }
|
|
626
|
+
}
|
|
627
|
+
vibDepth.gain.setValueAtTime(num(v.vibrato, 9), startTime);
|
|
628
|
+
out.gain.setValueAtTime(num(v.level, 0.5), startTime);
|
|
629
|
+
P.apply(src.frequency, startTime);
|
|
630
|
+
VE.apply(voiceEnv.gain, startTime);
|
|
631
|
+
SL.apply(murmur.frequency, startTime);
|
|
632
|
+
AS.apply(asp.gain, startTime);
|
|
633
|
+
FG.apply(fric.gain, startTime);
|
|
634
|
+
FB.apply(fricBand.frequency, startTime);
|
|
635
|
+
FQ.apply(fricBand.Q, startTime);
|
|
636
|
+
FH.apply(fricHigh.frequency, startTime);
|
|
637
|
+
FL.apply(fricTop.frequency, startTime);
|
|
638
|
+
NG.apply(notch.gain, startTime);
|
|
639
|
+
NF.apply(notch.frequency, startTime);
|
|
640
|
+
F.forEach((tr, i) => tr.apply(formants[i].frequency, startTime));
|
|
641
|
+
|
|
642
|
+
// A pooled source keeps its phase, but the audition's complete consonant,
|
|
643
|
+
// vowel, pitch and envelope plans are unchanged. Close all paths at the end.
|
|
644
|
+
for (const param of [voiceEnv.gain, asp.gain, fric.gain]) {
|
|
645
|
+
param.setValueAtTime(0, end);
|
|
646
|
+
}
|
|
647
|
+
return end;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
export function makeSimlishVoice(context, destination) {
|
|
651
|
+
const ctx = context;
|
|
652
|
+
const src = ctx.createOscillator();
|
|
653
|
+
src.setPeriodicWave(buzzOf(ctx, TUNE.tilt));
|
|
654
|
+
const vib = ctx.createOscillator();
|
|
655
|
+
vib.frequency.value = 5.4;
|
|
656
|
+
const vibDepth = ctx.createGain();
|
|
657
|
+
vibDepth.gain.value = 9;
|
|
658
|
+
vib.connect(vibDepth);
|
|
659
|
+
vibDepth.connect(src.detune);
|
|
660
|
+
const murmur = ctx.createBiquadFilter();
|
|
661
|
+
murmur.type = 'lowpass';
|
|
662
|
+
murmur.Q.value = 0;
|
|
663
|
+
const voiceEnv = ctx.createGain();
|
|
664
|
+
voiceEnv.gain.value = 0;
|
|
665
|
+
src.connect(voiceEnv);
|
|
666
|
+
voiceEnv.connect(murmur);
|
|
667
|
+
// Formants: peaking filters in series. Each lifts its band over a 1/n
|
|
668
|
+
// source and leaves the rest alone, so nothing above F4 is cut away.
|
|
669
|
+
const formants = TUNE.formantQ.map((q, i) => {
|
|
670
|
+
const f = ctx.createBiquadFilter();
|
|
671
|
+
f.type = 'peaking';
|
|
672
|
+
f.Q.value = q;
|
|
673
|
+
f.gain.value = TUNE.formantDb[i];
|
|
674
|
+
return f;
|
|
675
|
+
});
|
|
676
|
+
murmur.connect(formants[0]);
|
|
677
|
+
for (let i = 0; i < 3; i += 1) {
|
|
678
|
+
formants[i].connect(formants[i + 1]);
|
|
679
|
+
}
|
|
680
|
+
const notch = ctx.createBiquadFilter();
|
|
681
|
+
notch.type = 'peaking';
|
|
682
|
+
notch.Q.value = 2.5;
|
|
683
|
+
formants[3].connect(notch);
|
|
684
|
+
// A presence shelf, for tuning.
|
|
685
|
+
const shelf = ctx.createBiquadFilter();
|
|
686
|
+
shelf.type = 'highshelf';
|
|
687
|
+
shelf.frequency.value = TUNE.shelfHz;
|
|
688
|
+
shelf.gain.value = TUNE.shelfDb;
|
|
689
|
+
notch.connect(shelf);
|
|
690
|
+
const out = ctx.createGain();
|
|
691
|
+
out.gain.value = 0;
|
|
692
|
+
shelf.connect(out);
|
|
693
|
+
const hp = ctx.createBiquadFilter();
|
|
694
|
+
hp.type = 'highpass';
|
|
695
|
+
hp.frequency.value = 70;
|
|
696
|
+
hp.Q.value = 0.5;
|
|
697
|
+
out.connect(hp);
|
|
698
|
+
hp.connect(destination);
|
|
699
|
+
// Noise: aspiration into the cascade, frication beside it.
|
|
700
|
+
const hiss = ctx.createBufferSource();
|
|
701
|
+
hiss.buffer = noiseOf(ctx);
|
|
702
|
+
hiss.loop = true;
|
|
703
|
+
const asp = ctx.createGain();
|
|
704
|
+
asp.gain.value = 0;
|
|
705
|
+
hiss.connect(asp);
|
|
706
|
+
asp.connect(murmur);
|
|
707
|
+
const fricBand = ctx.createBiquadFilter();
|
|
708
|
+
fricBand.type = 'bandpass';
|
|
709
|
+
const fricHigh = ctx.createBiquadFilter();
|
|
710
|
+
fricHigh.type = 'highpass';
|
|
711
|
+
fricHigh.Q.value = 0.5;
|
|
712
|
+
const fricTop = ctx.createBiquadFilter();
|
|
713
|
+
fricTop.type = 'lowpass';
|
|
714
|
+
fricTop.Q.value = 0.5;
|
|
715
|
+
const fric = ctx.createGain();
|
|
716
|
+
fric.gain.value = 0;
|
|
717
|
+
hiss.connect(fricBand);
|
|
718
|
+
fricBand.connect(fricHigh);
|
|
719
|
+
fricHigh.connect(fricTop);
|
|
720
|
+
fricTop.connect(fric);
|
|
721
|
+
fric.connect(out);
|
|
722
|
+
|
|
723
|
+
const nodes = [src, vib, vibDepth, murmur, voiceEnv, ...formants, notch, shelf, out, hp, hiss, asp, fricBand, fricHigh, fricTop, fric];
|
|
724
|
+
src.start();
|
|
725
|
+
vib.start();
|
|
726
|
+
hiss.start(ctx.currentTime, 0.37);
|
|
727
|
+
let stopped = false;
|
|
728
|
+
const graph = { src, vibDepth, murmur, voiceEnv, formants, notch, out, asp, fricBand, fricHigh, fricTop, fric };
|
|
729
|
+
return {
|
|
730
|
+
nodes: nodes.length,
|
|
731
|
+
say(text, at, voice) {
|
|
732
|
+
if (stopped || !Number.isFinite(at)) { return at; }
|
|
733
|
+
return scheduleLine(ctx, graph, text, Math.max(ctx.currentTime, at), voice);
|
|
734
|
+
},
|
|
735
|
+
stop() { stopped = true; release(nodes); },
|
|
736
|
+
};
|
|
737
|
+
}
|