Text-to-speech when you receive an important alert while the app is closed

If you are receiving a regular push notification and try to read the content of the push notification in AVSpeechSynthesizer, it will read the text when the app is in the foreground, but when the app is closed, stopped, or in the background, it will display “Unable to list audio folders” and the text cannot be read. I couldn't find anything in the documentation about whether this works for critical alerts, so if anyone knows, please let me know.

This text has been translated with DeepL

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

Text-to-speech when you receive an important alert while the app is closed
 
 
Q