在使用 Swift 进行引用时,我遇到了重复相同命令的问题。
这是我现在拥有的
import AVFoundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let QuoteArray = [
"Quote1",
"Quote2",
"Quote3",
]
let max = QuoteArray.count
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)])
utterance.rate = 0.5
utterance.voice = AVSpeechSynthesisVoice(language: "en-AU")
synthesizer.speak(AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)]))
sleep(5)
synthesizer.speak(AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)]))
sleep(10)
synthesizer.speak(AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)]))
我不确定如何选择一个随机数组位置,以及如何使用合成语音和速度。我试图让它随机读取 3 个随机引号,但我似乎无法让它正常工作。
如果我修改最后几行而不是AVSpeechUtterance(string...
他们说,由于错误utterance
,我无法运行第二或第三报价。SIGBART
有任何想法吗?
utterance.rate = 35
utterance.pitchMultiplier = 3
utterance.voice = AVSpeechSynthesisVoice(language: "en-AU")
synth.speak(utterance)
sleep(5)
synth.speak(utterance)
sleep(10)
synth.speak(utterance)
sleep(15)
如果我试图把它带回到这些话语中,我会得到一个
error: Execution was interrupted, reason: signal SIGABRT.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation."