One-call spatial audio for RealityKit. Drop a 3D sound into a scene with a single line.
dependencies: [
.package(path: "../RealityAudio"),
],import RealityAudio
import RealityKit
let url = Bundle.main.url(forResource: "footstep", withExtension: "mp3")!
let emitter = try RealityAudio.play(
url,
in: arView.scene,
at: SIMD3(x: 0, y: 0, z: -2),
occluded: true
)Returns the Entity emitter. Hold onto it to stop playback later:
emitter.removeFromParent()| Parameter | Description |
|---|---|
url |
File URL of the audio resource (.wav, .mp3, etc.) |
scene |
The Scene to add the emitter to (e.g. arView.scene) |
position |
World-space position in metres where the sound originates |
occluded |
true → realistic distance rolloff (pairs with LiDAR occlusion). false → uniform volume. Defaults to true. |
- iOS 17.0+
- visionOS 1.0+
Physical occlusion requires two things:
- This library — pass
occluded: trueto enable distance rolloff. - Your ARView — enable scene understanding:
arView.environment.sceneUnderstanding.options.insert(.occlusion)When both are in place, RealityKit automatically attenuates or blocks the sound when the user moves behind physical walls or furniture.