这是我的游乐场代码:
import AVFoundation
var speechsynth: AVSpeechSynthesizer = AVSpeechSynthesizer()
let wordsToSpeak = ["word one","word two","word three","word four"]
let endTime = NSDate().dateByAddingTimeInterval(10)
while endTime.timeIntervalSinceNow > 0 {
//workaround for iOS8 Bug
var beforeSpeechString : String = " "
var beforeSpeech:AVSpeechUtterance = AVSpeechUtterance(string: beforeSpeechString)
speechsynth.speakUtterance(beforeSpeech)
//realstring to speak
var speechString: String = wordsToSpeak[0]
var nextSpeech:AVSpeechUtterance = AVSpeechUtterance(string: speechString)
nextSpeech.voice = AVSpeechSynthesisVoice(language: "en-US")
nextSpeech.rate = AVSpeechUtteranceMinimumSpeechRate
speechsynth.speakUtterance(nextSpeech)
}
目前,演讲在 while 循环完成后开始。
我怎样才能让它在每次迭代期间说话并在继续循环的下一次迭代之前完成说话?