Swift playgrounds ios 10 text to text command speech
I am using Quick Playgrounds on an iPad iOS 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 click "run my code". I am getting the error "Attempting to rate editor space" I do not know what this error means. Hope someone can help. Thank.
+3
source to share
1 answer
utterance: AVSpeechUtterance
is just an editor placeholder that tells you what you should put there:
synthesizer.speak(utterance: AVSpeechUtterance)
You need to call this passing the object you created:
synthesizer.speak(utterance)
You need a few more lines to get him to speak. Here's 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)
+2
source to share