ここに私の遊び場のコードがあります:
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 ループが完了した後に発話が開始されます。
各反復中に話し、ループの次の反復に進む前に話し終えるにはどうすればよいですか?