configuration
TypeScriptget configuration(): Promise<AudioGeneratorConfiguration>Swift declaration@MainActor final let configuration: AudioGeneratorConfigurationThe configuration with rendering parameters for the render handler.
class · iOS 18.0+ · SDK 27.1
@MainActor class AudioGeneratorControllerA controller that manages the playback of a real-time audio stream. To receive an audio generator controller, call an entity's ``Entity/prepareAudio(configuration:_:)`` or ``Entity/playAudio(configuration:_:)`` method. The following examples show how you can use the controller: ```objc /// myHandler.mm AVAudioSourceNodeRenderBlock myHandler = ^OSStatus(BOOL *isSilence, const AudioTimeStamp *timestamp, AVAudioFrameCount frameCount, AudioBufferList *outputData) { double phase = FREQUENCY * timestamp->mSampleTime * (1.f / SAMPLE_RATE); for (int idx = 0; idx < frameCount; idx++) { ((Float32 *)outputData->mBuffers[0].mData)[idx] = sin(phase * 2.f * M_PI) * 0.5; phase += (FREQUENCY / SAMPLE_RATE); } return 0; }; ``` ```swift // Create a configuration. var config = AudioGeneratorConfiguration(kAudioChannelLayoutTag_Mono) // Prepare a closure that you define in myHandler.mm. var controller = myEntity.prepareAudio(configuration: config, myHandler) controller.gain = -3.0 controller.play() ``` During playback, the audio appears to come from the entity that you use to create the controller. As a person moves around the MR scene, RealityKit modulates the characteristics of the audio to account for their location. - Note: Audio stops rendering when the system deallocates `AudioGeneratorController`. Create another `AudioGeneratorController` to restart audio. Call ``AudioGeneratorController/stop()`` to halt the audio, and ``AudioGeneratorController/play()`` to restart the stream.
get configuration(): Promise<AudioGeneratorConfiguration>Swift declaration@MainActor final let configuration: AudioGeneratorConfigurationThe configuration with rendering parameters for the render handler.
get gain(): Promise<number>Swift declaration@MainActor var gain: Audio.Decibel { get set }The gain in decibels of the audio generator controller output.
setGain(value: number): Promise<void>Swift declaration@MainActor var gain: Audio.Decibel { get set }The gain in decibels of the audio generator controller output.
play(): Promise<void>Swift declaration@MainActor func play()Begins the audio stream from the generator render handler. When you play the controller, the render handler starts receiving callbacks. The controller ignores calls to ``AudioGeneratorController/play()`` when audio is already playing.
stop(): Promise<void>Swift declaration@MainActor func stop()Stops playback of the render handler. Callbacks to the render handler stop after calling ``AudioGeneratorController/stop()``. There may be a short delay between when you call `stop` and when the callbacks actually stop.
get entity(): Promise<(Entity) | null>Swift declaration@MainActor weak var entity: Entity? { get }The entity the audio stream emanates from.
get isPlaying(): Promise<boolean>Swift declaration@MainActor var isPlaying: Bool { get }A Boolean value that indicates whether playback is currently active. You may experience a small delay between when you call the ``AudioGeneratorController/play()`` method and when the ``AudioGeneratorController/isPlaying`` property reports `true`.
No declarations were skipped in this snapshot.