My codes launches a local notification. I can figure out how to add a title to the notification but I can not figure out how to use a custom sound. Specifically I want to use avseechutterance to speak the variable a in my code.
let content = UNMutableNotificationContent()
//a goes on the line below
content.sound =
let a = AVSpeechUtterance(string: " Good afternoon ")
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(a)
a.voice = AVSpeechSynthesisVoice(language: "en-US")
a.rate = 0.08
Hi @zalubski
I don’t think it’s possible. Custom notification sound should be an instance of the UNNotificationSound class, AVSpeechSynthesisVoice can’t help you with this.
It should look something like this:
content.sound = UNNotificationSound(named: soundName)
Nikita
@zalubski , @nikita_gaydukov Hello, I am stuck on the same topic
// playing sound in notifications
let notificationContent = UNMutableNotificationContent()
notificationContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: ringtoneName + “.mp3”))
how do I use the text to speech inside the notificationContent.sound = UNNotificationSound(named: )
following is my code for the text to speech conversion
// Text to speech
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
try audioSession.setActive(true)
UIApplication.shared.beginReceivingRemoteControlEvents()
let utterance = AVSpeechUtterance(string: message) // message is the notificaiton title i am passing through the string
utterance.rate = 0.5
utterance.volume = 0.8
utterance.voice = AVSpeechSynthesisVoice(language: languageCode)
synthesizer.speak(utterance)
currentCount += 1