I'm using swift playgrounds on iOS iPad to create a text to speech command. Below is the code.
import AVFoundation
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance (string: "Say
Hello")
utterance.rate = 1
synthesizer.speak(utterance:
AVSpeechUtterance)
//when I hit "run my code". I get the error message "Attempt to evaluate editor placeholder" I don't know what this error means. Hopefully someone can help. Thank you.
utterance: AVSpeechUtterance is just an editor placeholder that tells you what you should put there:
synthesizer.speak(utterance: AVSpeechUtterance)
You need to call it passing it the utterance object you created:
synthesizer.speak(utterance)
To get it to speak, you need a few more lines. Here is the complete code:
import AVFoundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "Say Hello")
utterance.rate = 0.5
synthesizer.speak(utterance)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With