ios - 带有 ios8 的 AVSpeechSynthesizer

标签 ios objective-c avspeechsynthesizer

嗨,有人在 iOS 8 上试过 AvSpeechSynthesizer 吗? 我在 Xcode 6 上做了快速应用程序,但没有音频出来,我在 Xcode 5 上运行了同样的程序并且工作顺利。

示例代码来自 http://nshipster.com/avspeechsynthesizer/

NSString *string = @"Hello, World!";
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:string];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];

AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
[speechSynthesizer speakUtterance:utterance];

Xcode6 有问题吗?

== 编辑 === 看起来像 iOS 8 sim 的错误/问题,带有 Xcode6 的 iOS7.1 Sim 工作正常..

最佳答案

是的,这是一个错误。从 iOS8 GM 开始,似乎第一次尝试让 AVSpeechSynthesizer 说出 AVSpeechUtterance 将导致沉默。

我的解决方法是让 AVSpeechSynthesizer 在初始化后立即说出单个字符的话语。这将是无声的,之后您的 AVSpeechSynthesizer 将正常工作。

AVSpeechUtterance *bugWorkaroundUtterance = [AVSpeechUtterance speechUtteranceWithString:@" "];
bugWorkaroundUtterance.rate = AVSpeechUtteranceMaximumSpeechRate;
[self.speechSynthesizer speakUtterance:bugWorkaroundUtterance];

关于ios - 带有 ios8 的 AVSpeechSynthesizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24197952/

相关文章:

ios - 手机锁定时 AVSpeechSynthesizer 将无法工作

ios - 可供 AVSpeechSynthesis 在 iOS 中使用的已安装语音的可用性

ios - 如何禁用 iOS 键盘上的小数点键

iphone - Scrollview 在dismissViewControllerAnimated 后没有滚动

ios - 带有七个选项卡的选项卡栏 Controller ,五个选项卡导致 Split View Controller

objective-c - Objective-C : if statements and NSString comparison functions for efficiency and readability

iOS 应用程序蓝牙音频在 "Phone Mode."中推出

ios - Swift SDK 中会发生框架冲突吗?

objective-c - objective-c : Shake problems

ios - 如何将数据从网页传递到 iPhone 应用程序