Immersive Audio in RealityKit 🎧
Enhance your AR apps with spatial audio in RealityKit/ARKit
This is part of my RealityKit Snippets collection of short code examples for getting things done in RealityKit.
Audio in RealityKit
To make your augmented reality experiences even more realistic, RealityKit has tools to incorporate sound. The sound capabilities include:
- Loading and playing audio files
- Adjusting sound to user orientation
- Attaching sound to physical locations (The sound level changes as you move closer to/further away from an entity)
Add audio to an entity
Options
inputMode changes how the sound reacts to the real world.
.nonSpatialplays the audio normally regardless of position and orientation..ambientadjusts the left/right audio balance to follow which way the user is facing..spatialhas the same features as.ambientbut also changes the sound’s volume based on the user’s position. The closer the user moves toward the entity, the louder the sound.
The .spatial and .ambient modes sound best with headphones!
loadingStrategy tells RealityKit whether to preload your sounds when you first create your audio resource or to stream them as you play them. Which option you choose depends on how large your sounds are and how often the sound is needed.
