I am working on a text to speak task. In which I am facing problem that if I got the text for example: Hello everyone. 2 minutes to go.
Then using code below for speech synthesizer, It considers whole text as one sentence and doesn't give a natural pause after Hello everyone.
. It speaks whole text as one sentence just like there is no . (full stop)
after Hello everyone
. This happens only if there is a number after punctuation mark . (full stop)
let utterance = AVSpeechUtterance(string: "Hello everyone. 2 minutes to go.")
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
utterance.rate = AVSpeechUtteranceDefaultSpeechRate
synthesizer.speak(utterance)
If you are concerned how I'm initializing session and synthesizer then here is the code below:
let synthesizer = AVSpeechSynthesizer()
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayback, with: .duckOthers)
try session.setActive(true)
} catch {
print(error.localizedDescription)
}