gpt4 book ai didi

ios - Swift playgrounds ios 10 文字转语音命令代码

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:17 24 4
gpt4 key购买 nike

我在 iOS iPad 上使用 swift playgrounds 创建文本转语音命令。下面是代码。

import AVFoundation
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance (string: "Say
Hello")
utterance.rate = 1
synthesizer.speak(utterance:
AVSpeechUtterance)

//当我点击“运行我的代码”时。我收到错误消息“尝试评估编辑器占位符”我不知道这个错误是什么意思。希望有人能提供帮助。谢谢你。

最佳答案

utterance:AVSpeechUtterance 只是一个编辑器占位符,告诉您应该放在那里的内容:

synthesizer.speak(utterance: AVSpeechUtterance)

您需要调用它,将您创建的话语对象传递给它:

synthesizer.speak(utterance)

要让它说话,您还需要几行。完整代码如下:

import AVFoundation
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true

let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "Say Hello")

utterance.rate = 0.5

synthesizer.speak(utterance)

关于ios - Swift playgrounds ios 10 文字转语音命令代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44233282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com