只想添加到此(以及扩展,原始帖子中的链接讨论):
我有两台设备:一台 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 将“使用侧面开关:”选项设置为“静音”。我不理会它,但继续切换开关本身。哇!在没有耳塞的情况下一切正常。因此,如果您无法听到文字转语音,请尝试使用耳塞。如果可行,请检查您的设备是否设置为静音!