gpt4 book ai didi

swift - AVSpeechUtterance - Swift - 用短语初始化

转载 作者:搜寻专家 更新时间:2023-10-30 21:56:22 25 4
gpt4 key购买 nike

所以我只是想在 Swift 中使用 AVSpeechSynthesizer。我不知道如何为 AVSpeechUtterance 设置短语。

@IBAction func buttonSpeakClicked(sender:UIButton)
{
var mySpeechSynthesizer:AVSpeechSynthesizer = AVSpeechSynthesizer()
var myString:String = "This is the phrase to say"
var mySpeechUtterance:AVSpeechUtterance = AVSpeechUtterance(string:myString)

println("\(mySpeechUtterance.speechString)")
println("My string - \(myString)")

mySpeechSynthesizer .speakUtterance(mySpeechUtterance)
}

第一个 println - Nil

第二个 println - This is the phrase to say

文档说 init(string string: String!),但我不知道把它放在哪里

最佳答案

代码没问题,语音字符串设置正确。然而,问题是 AVSpeechUtterance 在 iOS 8 Beta 上没有按预期工作。我建议提交错误报告 here .

代码在 iOS 7.1 设备和模拟器上运行良好。

关于swift - AVSpeechUtterance - Swift - 用短语初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24472766/

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