It is not possible to start an AV session if the app is in the background. And certainly not if it is not running.
Not sure if this will work with your app and your notification infrastructure, but a solution would be to use a Notification Service Extension, wherein you can download a sound file containing the TTS results generated at your server, and then modify the notification payload to use the downloaded TTS file as your alert sound (keeping in mind the format and duration limitations). While it might be also possible to use the AVSpeechSynthesizer.write()
function to generate the sound file locally in the extension, your mileage may vary as to the success of that depending on conditions. The Notification Service Extension has limited memory (24MB) and time (30 seconds) limitations, and it may or may not be possible to create, save and pass it in the payload with the amounts you have.
When the app is in the background/closed, the alert sound is played by the notification system, not your app, so what you need to do is hand over the sound file to the system in the payload. You will want to try these and see if it will work for you.
Argun Tekant /
DTS Engineer /
Core Technologies