func playAudio(audioString:String){
do {
let se = AVAudioSession.sharedInstance()
try se.setActive(true, options: .notifyOthersOnDeactivation)
try se.setCategory(.playback, options: .allowAirPlay)
} catch {
}
speaker = AVSpeechSynthesizer.init()
let detailTerance = AVSpeechUtterance.init(string: audioString)
///语速
detailTerance.rate = 0.5
detailTerance.pitchMultiplier = 1//音高
detailTerance.volume = 1
detailTerance.preUtteranceDelay = 1
detailTerance.postUtteranceDelay = 1
let voice = AVSpeechSynthesisVoice.init(language: "zh-CN")
detailTerance.voice = voice
speaker.speak(detailTerance)
}
网友评论