【问题标题】:Use AVSpeechSynthesizer on iOS 7 but retain compatibility for iOS 6在 iOS 7 上使用 AVSpeechSynthesizer,但保留对 iOS 6 的兼容性
【发布时间】:2014-01-13 22:18:37
【问题描述】:

您好,我了解 TTS 仅在 iOS 7 中可用,但我过去通过检查该类是否可用并设法保持与以前版本的兼容性,但使用 AVSpeechSynthesizer 它似乎不起作用,你可以请帮助我在 iOS 7 中使用 TTS 并通过在 iOS 6 中禁用它来保持兼容性,非常感谢。

这是我的代码,但它似乎不起作用

    if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) {
    if([AVSpeechSynthesizer class]) {
        AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
        AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
        utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
        utterance.rate = AVSpeechUtteranceDefaultSpeechRate/2;
        utterance.pitchMultiplier = 0.9;
        utterance.preUtteranceDelay = 0;
        utterance.postUtteranceDelay = 0;
        [synth speakUtterance:utterance];
    } else {
        // Feature not available, do something else
    }
}

我已经在我的项目中链接了 avfoundation 并设置了部署目标 iOS 6,如果它的 iOS 6 崩溃,它似乎只有在 iOS 7 设备上运行时才有效。

这是我收到的错误消息

dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate

【问题讨论】:

  • 你是否弱链接了框架?
  • 非常感谢,在模拟器中好像可以了!
  • 转到“构建阶段”并将“AVFundation”从必需更改为可选......然后瞧!

标签: ios iphone objective-c xcode ios7


【解决方案1】:

框架需要弱链接。执行以下操作:

  1. 在项目导航器(左侧)中单击您的项目文件以在编辑器中打开您的项目
  2. 点击编辑器中的构建阶段标签
  3. 展开Link Binary With Libraries部分
  4. AVFoundation.framework必需 设置为 可选

此外,您可能希望使用one that's safer(Apple 推荐)更新您的版本检查。

【讨论】:

  • 你播种了我们的通讯吗?为什么你的答案不一样? :)
  • @TonyMkenu 在我看来,Stack Overflow 的意义在于有人来寻找他们问题的答案。如果这个问题没有实际答案,只有 cmets,那么有人可能会错过这个问题的解决方案。
  • 非常感谢!这应该被标记为已接受的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-25
  • 2013-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多