在iOS 7上使用AVSpeechSynthesizer但保留iOS 6的兼容性 [英] Use AVSpeechSynthesizer on iOS 7 but retain compatibility for iOS 6

查看:174
本文介绍了在iOS 7上使用AVSpeechSynthesizer但保留iOS 6的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hello I Understand TTS is only available in iOS 7 but i used many apis in the past by checking if the class is available and managed to retain compatibility on previous versions but with AVSpeechSynthesizer it doesn't seem to work, can you please help me use TTS for iOS 7 and retain compatibility by disabling it in iOS 6, thank you very much.

这是我的代码,但它似乎无法正常工作

Here is my code but it doesn't seem to work

    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 7设备上运行时工作,如果它的iOS 6崩溃。

i've already linked avfoundation in my project and set deployment target iOS 6 and it seems to work only when runing on iOS 7 devices if its iOS 6 it crashes.

这里是我收到的错误消息

here is the error message i get

dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate


推荐答案

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

The framework needs to be be weak linked. Do the following:


  1. 在项目导航器(左侧)中单击项目文件以在编辑器中打开项目

  2. 点击编辑器中的构建阶段标签

  3. 展开带库的链接二进制文件部分

  4. AVFoundation.framework 必需设置为可选

  1. Click your project file in the Project Navigator (on the left) to open your project in the editor
  2. Click the Build Phases tab in the editor
  3. Expand the Link Binary With Libraries section
  4. Set AVFoundation.framework from Required to Optional

此外,您可能希望使用一个更安全的(并由Apple推荐)。

Additionally, you might want to update your version check with one that's safer (and recommended by Apple).

这篇关于在iOS 7上使用AVSpeechSynthesizer但保留iOS 6的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆