Swift ios9 为资产构建 MacinTalk 语音:(空)

Swift ios9 Building MacinTalk voice for asset: (null)

我正在使用 xcode 7 , swift 2.0

我正在将语音文本转换为在模拟器中工作的 Speech,但不是在真实的 iphone6 plus 设备中,iOS 9. 我已正确导入 AVFOUNDATION 及其框架。

我试过了...

@IBAction func SpeakTheList(sender: AnyObject) {
    let mySpeechUtterance = AVSpeechUtterance(string: speakString)

    //let voice = AVSpeechSynthesisVoice(language: "en-US")
   // mySpeechUtterance.voice = voice

    let voices = AVSpeechSynthesisVoice.speechVoices()

    for voice in voices {

        if "en-US" == voice.language {
            mySpeechUtterance.voice = voice
            print(voice.language)
            break;
        }
    }
    mySpeechSynthesizer.speakUtterance(mySpeechUtterance)
}

我收到以下错误: 为资产构建 MacinTalk 语音:(空) 我需要在 iphone6plus iOS 9 中进行设置吗,或者我必须下载一些东西。

我在这里找到了一个建议Why I'm getting "Building MacinTalk voice for asset: (null)" in iOS device test

这么说.. “从 iOS9 开始,可能是在开发过程中打开了一个他们忘记关闭的日志事件”

终于在 iOS9 中发现了一个错误,在 XCODE 新版本 7.2 更新和 iOS 9.2 更新 发布后不久, 我测试了上面相同的代码,文本到语音开始工作了。

只是想补充一点(并且通过扩展,原始 post 中的 linked 讨论):

我有两个设备:一个 iPad2 和一个 iPad Air。它们 运行 与 iOS (9.2, 13C75) 的版本完全相同。我有以下 objective-C++ 函数,用于在 Yosemite 上使用 Xcode 7.2 (7C68) 从 Qt 生成语音:

void iOSTTSClient::speakSpeedGender(const QString &msg, const float speechRateModifier, const QString &gender, const bool cutOff) {
    QString noHTML(msg);
    noHTML.remove(QRegularExpression("<[^<]*?>"));
    AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:noHTML.toNSString()];
    /* See https://forums.developer.apple.com/thread/18178 */
    const float baseSpeechRate = (m_iOSVersion < 9.0) ? 0.15 : AVSpeechUtteranceDefaultSpeechRate;
    utterance.rate = baseSpeechRate * speechRateModifier;
    NSString *locale;
    if (gender.compare("male", Qt::CaseInsensitive) == 0)
        locale = @"en-GB"; // "Daniel" by default
    else if (gender.compare("female", Qt::CaseInsensitive) == 0)
        locale = @"en-US"; // "Samantha" by default
    else
        locale = [AVSpeechSynthesisVoice currentLanguageCode];
    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:locale];
    const QString errMsg = QString("Null pointer to AVSpeechSynthesisVoice (could not fetch voice for locale '%1')!").arg(QString::fromNSString(locale));
    Q_ASSERT_X(voice, "speakSpeedGender", errMsg.toLatin1().data());
    utterance.voice = voice;
    static const AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
    if (synthesizer.speaking && cutOff) {
        const bool stopped = [synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
        Q_ASSERT_X(stopped, "speakSpeedGender", "Could not stop previous utterance!");
    }
    [synthesizer speakUtterance:utterance];
}

在 iPad Air 上,一切正常:

Building MacinTalk voice for asset: file:///private/var/mobile/Library/Assets/com_apple_MobileAsset_MacinTalkVoiceAssets/db2bf75d6d3dbf8d4825a3ea16b1a879ac31466b.asset/AssetData/

但是在 iPad2 上,我什么也没听到,得到以下信息:

Building MacinTalk voice for asset: (null)

出于好奇,我在那里启动了 iPad2 模拟器和 运行 我的应用程序。我还收到 另一条 控制台消息:

AXSpeechAssetDownloader|error| ASAssetQuery error fetching results (for com.apple.MobileAsset.MacinTalkVoiceAssets) Error Domain=ASError Code=21 "Unable to copy asset information" UserInfo={NSDescription=Unable to copy asset information}

可是,我听到了讲话!我意识到我戴着耳机。果然,当我将耳塞插入 iPad2 时,我也在那里听到了语音。所以现在我正在搜索相关信息。下面的 link 是最近的并且有通常的 this-worked-for-me 巫术分类(none 它帮助了我,但也许会帮助其他人解决这个问题):

https://forums.developer.apple.com/thread/18444

总结:TTS "works" 但在没有 headphones/ear 耳机的情况下不一定能听到。这似乎是 iOS 9.2 的硬件设置问题。控制台消息可能相关也可能不相关。

最后更新:为了完整的利益,如果不好意思,披露,我想我会分享我是如何最终解决这个问题的。有问题的 iPad2 将 "Use side switch to:" 选项设置为 "Mute"。我没有管它,而是继续操作并自行切换了开关。哇!一切都在没有耳塞的情况下工作。因此,如果您听不到 text-to-speech,请尝试 ear-buds。如果可行,请检查您的设备是否设置为静音!

不要使用 pauseSpeakingAtBoundary()。相反,请使用 stopSpeakingAtBoundarycontinueSpeaking。这对我有用。