February 2018
Intermediate to advanced
378 pages
10h 14m
English
The code is as follows:
import Speech class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate { static var shared = SpeechSynthesizer() private var synthesizer = AVSpeechSynthesizer() var voice = AVSpeechSynthesisVoice(language: "en-US") public func prepare() { let dummyUtterance = AVSpeechUtterance(string: " ") dummyUtterance.voice = AVSpeechSynthesisVoice(language: "en-US") synthesizer.speak(dummyUtterance) } public func speakAloud(word: String) { if synthesizer.isSpeaking { synthesizer.stopSpeaking(at: .immediate) } let utterance = AVSpeechUtterance(string: word) utterance.rate = 0.4 utterance.preUtteranceDelay = 0.1; utterance.postUtteranceDelay = 0.1; utterance.voice = self.voice synthesizer.speak(utterance) ...Read now
Unlock full access