AVSpeechUtterance - Swift - 用短语初始化 [英] AVSpeechUtterance - Swift - initializing with a phrase
问题描述
所以我只是想在Swift中使用AVSpeechSynthesizer。我无法弄清楚如何为AVSpeechUtterance设置短语。
So I'm just trying to use the AVSpeechSynthesizer with Swift. I cannot figure out how to set the phrase for the 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)
}
First println - Nil
First println - Nil
Second println - 这是要说的短语
Second println - This is the phrase to say
文档说init(字符串字符串:字符串!),但我无法弄清楚把它放在哪里
Documentation says init(string string: String!), but I can't figure out where to put it
推荐答案
代码很好,语音字符串设置正确。但问题是AVSpeechUtterance在iOS 8 Beta上没有按预期工作。我建议在这里提交错误报告。
The code is fine, speech string is set correctly. However issue is that AVSpeechUtterance is not working as expected on iOS 8 Beta. I suggest file a bug report here.
代码在iOS 7.1设备和模拟器上正常工作。
The code works fine on iOS 7.1 device and simulator.
这篇关于AVSpeechUtterance - Swift - 用短语初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!