Работая над использованием 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
, я не смогу выполнить 2-ю или 3-ю кавычку из-за ошибки 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."
![enter image description here](https://i.stack.imgur.com/Wg3J7.png)