【问题标题】:Can I load Alex Voice in the Swift Playground我可以在 Swift Playground 中加载 Alex Voice
【发布时间】:2018-05-16 00:43:11
【问题描述】:

我正在试验 Apple 的语音合成,我想看看 Alex 的声音在 iOS 设备上的声音效果如何。

有没有办法让 Alex 的声音可以通过 Swift Playground 访问?

【问题讨论】:

    标签: ios swift speech-synthesis avspeechsynthesizer


    【解决方案1】:

    是的,如果您添加这两行,它将起作用。

    import PlaygroundSupport
    PlaygroundPage.current.needsIndefiniteExecution = true
    

    由于语音合成器是异步代码,“needsIndefiniteExecution”允许在 Playground 的顶层代码结束后继续执行。这反过来又为线程和回调提供了执行时间。 (from Apple's documentation of Playground Support)

    例子:

    import AVFoundation
    import PlaygroundSupport
    
    PlaygroundPage.current.needsIndefiniteExecution = true
    let synth  = AVSpeechSynthesizer()
    let speech = AVSpeechUtterance(string: "Hello, World!")
    speech.voice = AVSpeechSynthesisVoice(language: "en-US")
    synth.speak(speech)
    

    【讨论】:

    • 您链接的示例将使用“Samantha”语音合成器声音; iOS 有一个可选的“Alex”语音(参见此处:support.apple.com/en-us/HT203077),可以在您的手机/平板电脑上额外下载;但据我所知,从操场上是无法进入的。
    • 哦,我相信你是对的。应该提供完整的列表,而 Alex 似乎不在那里。 print(AVSpeechSynthesisVoice.speechVoices())
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 2017-07-10
    • 2017-10-22
    相关资源
    最近更新 更多