Swift playgrounds ios 10个文字转语音命令代码
Swift playgrounds ios 10 text to speech command code
我在 iOS iPad 上使用 swift 游乐场来创建文本转语音命令。下面是代码。
import AVFoundation
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance (string: "Say
Hello")
utterance.rate = 1
synthesizer.speak(utterance:
AVSpeechUtterance)
//当我点击"run my code"。我收到错误消息 "Attempt to evaluate editor placeholder"
我不知道这个错误是什么意思。希望有人能提供帮助。谢谢你。
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 iPad 上使用 swift 游乐场来创建文本转语音命令。下面是代码。
import AVFoundation
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance (string: "Say
Hello")
utterance.rate = 1
synthesizer.speak(utterance:
AVSpeechUtterance)
//当我点击"run my code"。我收到错误消息 "Attempt to evaluate editor placeholder" 我不知道这个错误是什么意思。希望有人能提供帮助。谢谢你。
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)