Reputation: 66455
In my iOS app most users can hear the AVSpeechSynthesisVoice
correctly, but some report that it simply does not work. I haven't been able to reproduce the issue locally, but here is how I use the API:
let sentence = "the sentence to be told"
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: sentence)
utterance.voice = AVSpeechSynthesisVoice(
language: "en-GB"
)
utterance.rate = AVSpeechUtteranceDefaultSpeechRate * 1.05
synthesizer.speak(utterance)
This works perfectly fine on iOS 13 (tested most minors), all iOS 14 versions, all the devices I could find... but I keep getting reports of people not getting any audio feedback.
Do you have any pointers on where to look, or at least reproduce the issue?
Upvotes: 1
Views: 700
Reputation: 22479
After playing with the API I found that setting the usesApplicationAudioSession
flag to false in the instance of AVSpeechSynthesizer
.
Add the following line to your code:
synthesizer.usesApplicationAudioSession = false
The issue seems to be caused by the device being on 'silent mode'.
Upvotes: 2
Reputation: 667
Does your app support localisation? I had a similar issue. In my case whenever user changes the app language to Simplified-Chinese the text used to get localised so, I had to change the AVSpeechSynthesisVoice(language: "zh-TW") as well.
You can get the list of languages from here.
Upvotes: 1