且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Swift Playground中将文本转换为OSX的语音

更新时间:2022-11-18 18:22:40

NSSpeechSynthesizer.startSpeaking需要在后台任务中执行,但是默认情况下在操场上是不可能的.

NSSpeechSynthesizer's .startSpeaking needs to execute in a background task, but by default this is not possible in a Playground.

您可以通过导入PlaygroundSupport并设置异步模式来启用它,如下所示:

You can enable it by importing PlaygroundSupport and setting asynchronous mode, like this:

import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true