Add reference
1
|
import< /span> AVFoundation
|
play voice
1 2 3 4 5 6 7 8 9
|
let player = AVSpeechSynthesizer(); player.delegate = self; let u = AVSpeechUtterance(string: "The weather is nice today"); span> u.voice = AVSpeechSynthesisVoice(language: "zh-CN" ); u.volume = 1.0; u.rate = 0.48; u.pitchMultiplier = 1.0; player.speakUtterance(u);
|
Below iPhone6
rate
is set to 0.1Otherwise, you will read the pits of iOS very quickly
agent method
1 < span class="line">2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
func (synthesizer: AVSpeechSynthesizer, didStartSpeechUtterance utterance: AVSpeechUtterance) { < span class="built_in">print("start playing") }
< sp an class="line">func (synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) { let process = Double span>(characterRange.location) / Double(utterance.speechString.characters.count); print("During playback, the playback progress is: (process)") }
func (synthesizer: AVSpeechSynthesizer, didFinishSpeechUtterance utterance: AVSpeechUtterance) { print ("Playing completed") }
|
common method
1 2 3 4
|
player.stopSpeakingAtBoundary(AVSpeechBoundary.Immediate);
player.pauseSpeakingAtBoundary(AVSpeechBoundary.Immediate);
< /td> |