因此,我只是尝试使用AVSpeechSynthesizer与Swift。我不知道如何为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)
}第一次打印-零
第二次印刷-这是要说的话
文档上写着init( string : String!),但是我不知道该把它放在哪里。
发布于 2014-06-29 05:15:43
代码正常,语音字符串设置正确。然而,问题是AVSpeechUtterance并没有像预期的那样在iOS 8 Beta上工作。我建议提交一个错误报告这里。
该代码在iOS 7.1设备和模拟器上运行良好。
发布于 2014-09-15 00:57:19
是的,这是个窃听器。就通用汽车( iOS8 GM )而言,第一次尝试让AVSpeechSynthesizer说一句AVSpeechUtterance,似乎会导致沉默。
我的解决办法是让AVSpeechSynthesizer在初始化后立即说出单个字符的话语。这将是安静的,然后您的AVSpeechSynthesizer将正常工作。
在目标C中:
AVSpeechUtterance *bugWorkaroundUtterance = [AVSpeechUtterance speechUtteranceWithString:@" "];
bugWorkaroundUtterance.rate = AVSpeechUtteranceMaximumSpeechRate;
[self.speechSynthesizer speakUtterance:bugWorkaroundUtterance];https://stackoverflow.com/questions/24472766
复制相似问题