在iOS 7上使用AVSpeechSynthesizer但保留iOS 6的兼容性

 向日葵哄子 发布于 2023-02-03 10:14

你好我理解TTS仅在iOS 7中可用,但我过去使用了很多apis,检查该类是否可用并设法保留以前版本的兼容性,但是使用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 7设备上运行时工作,如果它的iOS 6崩溃了.

这是我得到的错误消息

dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate

Josh Brown.. 6

框架需要弱联系.请执行下列操作:

    单击Project Navigator(左侧)中的项目文件,在编辑器中打开项目

    单击编辑器中的Build Phases选项卡

    展开Link Binary With Libraries部分

    AVFoundation.frameworkRequired设置为Optional

将AVFoundation.framework从Required设置为Optional

此外,您可能希望使用更安全(并由Apple推荐)更新版本检查.

1 个回答
  • 框架需要弱联系.请执行下列操作:

      单击Project Navigator(左侧)中的项目文件,在编辑器中打开项目

      单击编辑器中的Build Phases选项卡

      展开Link Binary With Libraries部分

      AVFoundation.frameworkRequired设置为Optional

    将AVFoundation.framework从Required设置为Optional

    此外,您可能希望使用更安全(并由Apple推荐)更新版本检查.

    2023-02-03 10:16 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有