0

我正在使用 xcode 7 , swift 2.0

我在模拟器中获得语音文本到语音工作,但不是在真正的 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 语音:(null) 我需要在我的 iphone6plus iOS 9 中进行设置,或者我必须下载一些东西。

我在这里找到了一个建议为什么我在 iOS 设备测试中得到“为资产构建 MacinTalk 语音:(null)”

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

4

3 回答 3

2

只想添加到此(以及扩展,原始帖子中的链接讨论):

我有两台设备:一台 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 上,一切运行良好:

为资产构建 MacinTalk 语音:file:///private/var/mobile/Library/Assets/com_apple_MobileAsset_MacinTalkVoiceAssets/db2bf75d6d3dbf8d4825a3ea16b1a879ac31466b.asset/AssetData/

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

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

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

AXSpeechAssetDownloader|错误| ASAssetQuery 错误获取结果(对于 com.apple.MobileAsset.MacinTalkVoiceAssets) 错误域=ASError Code=21 “无法复制资产信息” UserInfo={NSDescription=无法复制资产信息}

但是,我听到了讲话!我意识到我戴着耳机。果然,当我将耳塞插入 iPad2 时,我也听到了那里的讲话。所以现在我正在搜索这方面的信息。以下链接是最近的,并且具有这种为我工作的伏都教的常见分类(没有一个对我有帮助,但可能会帮助其他人解决这个问题):

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

总而言之:TTS“有效”,但在没有耳机/耳塞的情况下不一定能听到。这似乎是 iOS 9.2 的硬件设置问题。控制台消息可能相关也可能不相关。

最后更新:为了完整的,如果害羞的,披露,我想我会分享我最终是如何解决这个问题的。有问题的 iPad2 将“使用侧面开关:”选项设置为“静音”。我不理会它,但继续切换开关本身。哇!在没有耳塞的情况下一切正常。因此,如果您无法听到文字转语音,请尝试使用耳塞。如果可行,请检查您的设备是否设置为静音!

于 2016-01-12T19:58:08.193 回答
0

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

于 2016-06-12T15:18:42.650 回答
-1

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

于 2015-12-16T07:26:24.403 回答