AVSpeechSynthesizer not working in Swift Playgrounds (iPad)

I'm trying to do the Text to Speech using AVSpeechSynthesizer. But everytime I run the code, it doesn't have any sounds.


I don't know if my iPad is the problem or the Swift Playgrounds App. Tested it using Xcode Playgrounds and it works.


Anybody having same issue? I've noticed that my Learn to Code 1 and Learn to Code 2 modules doesn't have any sounds coming from my iPad even if sounds are switched on. But the Drawing Sounds have sounds available.

Accepted Reply

Systemwide mute enabled in Control Center. (If mute is enabled, the button with a bell icon with a slash through it would be red.) Just unmute it.

Replies

Systemwide mute enabled in Control Center. (If mute is enabled, the button with a bell icon with a slash through it would be red.) Just unmute it.

Since the voice synthesizer is asynchronous code, the "needsIndefiniteExecution" allows execution to continue after the end of the playground’s top-level code is reached. This, in turn, gives threads and callbacks time to execute. (from Apple's documentation of Playground Support)


Add the following lines:


import PlaygroundSupport


PlaygroundPage.current.needsIndefiniteExecution = true