<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/Entity/prepareAudio(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation6EntityC12prepareAudioyAA0E18PlaybackControllerCAA0E8ResourceCF"
  },
  "title" : "prepareAudio(_:)"
}
-->

# prepareAudio(_:)

Prepares an audio resource for playback.

```
@MainActor @preconcurrency func prepareAudio(_ resource: AudioResource) -> AudioPlaybackController
```

## Parameters

`resource`

The audio resource the method plays.
Load an audio resource from the file system with
[`init(named:in:configuration:)`](/documentation/RealityKit/AudioFileResource/init(named:in:configuration:)) ,
or from a URL with
[`init(contentsOf:withName:configuration:)`](/documentation/RealityKit/AudioFileResource/init(contentsOf:withName:configuration:)).

## Return Value

An [`AudioPlaybackController`](/documentation/RealityKit/AudioPlaybackController) object that you can use to start and
stop audio playback for this specific instance of a resource playing on this entity.
You can also use this controller to update playback properties, such as gain and speed, during playback.

## Discussion

To start playback right away with default `AudioPlaybackController` properties, use the
[`playAudio(_:)`](/documentation/RealityKit/Entity/playAudio(_:)) method instead.

> Note: As soon as the system prepares an audio resource, the audio engine begins tracking the
> position of the entity and allocates rendering resources, which incurs a power cost.

For optimal system resource usage, avoid preparing sounds before they are needed. For example:

```swift
let controller = entity.prepareAudio(anAudioResource)
controller.gain = -10 // Apply a custom gain, if desired.
controller.speed = 1.2 // Apply a custom speed, if desired.
controller.play()
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)