While working at using Swift to spew forth quotations, I'm running into issues with the repetition of the same command.
Here's what I have right now
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)]))
I'm not sure how to both pick a random array position, and to fool around with the synthesisvoice and speed. I'm trying to make it so that 3 random quotes are read randomly, yet I can't seem to get it to work properly.
If I modify the last few lines so instead of AVSpeechUtterance(string...
they say utterance
, I cannot run a 2nd or 3rd quote because of a SIGBART
error.
Any ideas?
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)
if i try to bring it back to these utterances, i get a
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."