How to convert text to speech for OSX in a Swift playground

I am trying to learn how to do text-to-speech for OSX ( not iOS) in Swift. I have a playground with the code:

import Cocoa

let synth = NSSpeechSynthesizer()
synth.startSpeaking( "Hello World" )

It seems to work, but no sound comes up. In Xcode, in the lower left corner there is a small blue triangle that I click, thinking that it can do something, but unfortunately not:

Xcode interface image with a blue triangle in the lower left corner

Any ideas how to convert text to speech for OSX on the Swift playground? Thanks in advance!

+4
source share
1 answer

NSSpeechSynthesizer .startSpeaking must be completed in the background task, but by default this is not possible on the playground.

, PlaygroundSupport , :

import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
+1

Source: https://habr.com/ru/post/1662796/


All Articles