I am trying to implement my custom voice over in my application on MacOS (later I want to implement it on Windows too).
And I use for it AVAudioPlayer which I init with NSData initialised with wave file stored in BinaryData as const char*.
And it works fine. But I need to provide some ducking effect on other audio when my custom voiceover starts “speaking”.
And I am completely erring.
I found out there is such option if I use AVAudioSession but unfortunately it is available only for iOS, but not MacOS.
I’ve read somewhere that such option could be provided if I use AVAudioEngine and AVAudioPlayerNode instead AVAudioPlayer.
Bust actually I am completely noob with AVFoundation. And now I can’t figure it out how to initialise (schedule) AVAudioPlayerNode with BinaryData as I do in AVAudioPlayer by providing NSData.
AVAudioPlayerNode' requires AVAudioPCMBufferorAVAudioFile. But I can't find the option to initialise them with NSData*`.
But even though I will figure it out then I am still not sure if it would allow me for ducking effect on all other audio.
Please help me. I am desperate after whole week of studying AVFoundation
Rincewind!
Great thanks for your answer. To be honest I’ve already seen thread linked by you. And today I even finally successfully implemented AVAudioEngine and AVAudioPlayerNode.
But I am still not sure how to implement ducking all other audio when AVAudioPlayerNode starts playing.
The only thing I found about ducking is description in Apple AVAudioEngine documentation for prepare method. And there is sentence:
On AVAudioSession supported platforms, this method may cause the audio session to be implicitly activated. Activating the audio session (implicitly or explicitly) may cause other audio sessions to be interrupted or ducked depending on the session’s configuration. It is recommended to configure and activate the app’s audio session before preparing the engine.
But as far as I know MacOS does not support AVAudioSession so it looks like it’s not relevant for my case.
However, regarding your advice to use AI. Yes I use AI very often to solve my programistic issues. But AI (at least chat GPT) mainly found solutions in the internet where most of articles is described by using some SWIFT language, but I need to use it in C++, so there is totally different syntax. Instead: let engine = AVAudioEngine()
I need to call something like: AVAudioEngine* audioEngine = [[AVAudioEngine alloc] init];
And I can’t find to much examples in the internet with my syntax, so I don’t even try to ask AI which uses solutions from internet. But I will try.