RealityKit Spatial Audio - Volume drops abruptly

I have a class with an Entity, on which I added a Spatial Audio component. Furthermore, I have a function, which uses the playAudio() method to start the Spatial Audio. During the first call of the function, everything is fine. If I call the again, the audio volume drops abruptly after a half second. It is very quiet.

Approximately, I have following code:

class VoiceOutputPlayer: NSObject, ObservableObject, AVAudioPlayerDelegate {
    private var speechEntity = Entity()
    
    func play() {
        Task{
            let audioRessource = try await AudioFileResource(contentsOf: urlWave)
            self.speechEntity.playAudio(audioRessource)
        }
    }
    
    func initSpatialAudio() -> Entity {
        speechEntity.transform.translation.y = -0.37
        speechEntity.transform.translation.z = 0.09
        speechEntity.spatialAudio = SpatialAudioComponent(gain: Double.zero)
        speechEntity.spatialAudio?.reverbLevel = -2
        speechEntity.spatialAudio?.directivity = .beam(focus: 0.9)
        speechEntity.orientation = .init(angle: .pi, axis: [0, 1, 0])
        speechEntity.spatialAudio?.distanceAttenuation = .rolloff(factor: 1)
        return speechEntity
    }
}

Have visionOS 2.2 on the Apple Vision Pro and use Xcode 16.1

Hello @Pascal2807,

It's hard to say for sure given the limited information provided, however, this feels like a bug to me. Our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. I'd greatly appreciate it if you could open a bug report, include a sample project that replicates the issue including the audio file, and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating your bug report.

Thanks,
Michael

RealityKit Spatial Audio - Volume drops abruptly
 
 
Q