babylonjs-build-audio
Integrate Babylon.js audio playback, buses and spatial ownership using the explicitly selected audio API generation.
SKILL.mdskills/babylonjs-build-audio/SKILL.md
GitHubBuild Babylon.js Audio
When to use
Implement runtime music, effects, spatial emitters or scene audio lifecycle in Babylon.js.
Engine and dependencies
Before edits or tool launches, run resolve-engine.sh and resolve-skill.sh babylonjs-build-audio; require compatibility and honor task override scope. Inspect the locked Babylon revision and explicitly select its audio API generation. AudioEngineV2 and legacy Sound/AudioEngine have different construction/lifetime contracts; do not mix examples or migrate implicitly. Use rights-cleared project audio and codecs. Read MEDIA.md only when media generation or media validation is in scope.
Workflow
- For a compatible V2 project, initialize through
CreateAudioEngineAsyncand create sounds through supported V2 factories such asCreateSoundAsync; await initialization and browser activation. Existing legacy projects keep their declared adapter until a migration is selected. - Give the application one owning audio service and define scene-owned versus persistent music/emitter lifetimes. Explicitly route buses, gain/mute settings and pause behavior. Device output and audio-context failures must not block simulation.
- Set listener/camera ownership, spatial position/attachment, attenuation and distance units. Validate detachment when an actor despawns; do not leave an emitter following a disposed node.
- Bound simultaneous voices, loops and queued activation requests. Drop expired feedback rather than replaying a burst after unlock/resume. Interruption cancels scheduled effects; user volume/mute settings survive transitions. Audio clocks and game clocks need an explicit synchronization policy.
- Treat audio as presentation of gameplay events. Provide required visual/text alternatives and independent channel settings. Stop owned sounds, remove observers and release buffers/buses/engine only at their owning boundary.
Output and verification
Deliver the selected API/version contract, bus/voice policy and runtime adapter. Exercise locked startup, rejected decode/load, rapid event overlap, pause, reconnect, scene exit and repeated playback. Record audible behavior on supported target devices; mocked play calls prove routing only. Check Babylon audio generation guidance and the V2 playback API for the installed version.