---
title: "prepareAudio(_:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/entity/prepareaudio(_:)"
---

# prepareAudio(_:)

Prepares an audio resource for playback.

## Declaration

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

## Parameters

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

## Return Value

Return Value An 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

Discussion To start playback right away with default AudioPlaybackController properties, use the 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: 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()

## See Also

### Playing audio

- [playAudio(_:)](realitykit/entity/playaudio(_:).md)
- [playAudio(configuration:_:)](realitykit/entity/playaudio(configuration:_:).md)
- [prepareAudio(configuration:_:)](realitykit/entity/prepareaudio(configuration:_:).md)
- [stopAllAudio()](realitykit/entity/stopallaudio().md)
- [spatialAudio](realitykit/entity/spatialaudio.md)
- [ambientAudio](realitykit/entity/ambientaudio.md)
- [channelAudio](realitykit/entity/channelaudio.md)
