【问题标题】:How to detect if an iOS device has downloaded a voice file?如何检测 iOS 设备是否下载了语音文件?
【发布时间】:2016-01-01 00:48:00
【问题描述】:

我正在开发一个 iOS 文本到语音应用程序并尝试添加一个选项来使用 Alex 语音,这是 iOS 9 的新功能。我需要确定用户是否已在“设置”中下载了 Alex 语音 - > 可访问性。我似乎不知道该怎么做。

if ([AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex] == "Not Found" ) {
    // Do something...
}

原因是其他语言的声音是标准的,以一定的速率播放,与 Alex 的声音不同。所以我有一个可以工作的应用程序,但是如果用户没有下载语音,iOS 会自动默认为基本语音,但它会以不正确的速率播放。如果我能检测到语音尚未下载,我可以补偿差异和/或建议用户。

【问题讨论】:

  • 一个有趣且格式精美的问题 +1

标签: ios objective-c text-to-speech


【解决方案1】:

好的,所以我想我想多了,认为它更复杂。解决方法很简单。

if (![AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex]) {
        // Normalize the speech rate since the user hasn't downloaded the voice and/or trigger a notification that they need to go into settings and download the voice. 
    }

感谢所有查看此内容的人以及@CeceXX 的编辑。希望这对其他人有帮助。

【讨论】:

  • 不幸的是,[AVSpeechSynthesisVoice voiceWithIdentifier:] 方法似乎从 iOS 9.1+ 中消失了。替换为用处不大的“voiceWithLanguage”。
【解决方案2】:

这是一种方法。让我们继续以 Alex 为例:

- (void)checkForAlex {

        // is Alex installed?
        BOOL alexInstalled = NO;
        NSArray *voices = [AVSpeechSynthesisVoice speechVoices];

        for (id voiceName in voices) {

            if ([[voiceName valueForKey:@"name"] isEqualToString:@"Alex"]) {
                alexInstalled = YES;
            }
        }

        // react accordingly
        if (alexInstalled) {
            NSLog(@"Alex is installed on this device.");
        } else {
            NSLog(@"Alex is not installed on this device.");
        }
    }

此方法循环遍历所有已安装的语音并查询每个语音的名称。如果亚历克斯在其中,他就被安装了。

您可以查询的其他值是“语言”(返回类似 en-US 的语言代码)和质量(1 = 标准,2 = 增强)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-20
    • 2022-01-15
    • 2010-11-20
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多