2015-10-04 61 views
4

我正在处理iOS文本到语音应用程序,并尝试添加一个选项以使用Alex语音,这是iOS 9的新增功能。我需要确定用户是否已使用设置下载了Alex语音 - >可访问性。我似乎无法找到如何做到这一点。如何检测iOS设备是否下载了语音文件?

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

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

+0

一个有趣而且很好格式化的问题+1 – Cesare

回答

3

好的,所以我想我是在过度这个想法,并认为它更复杂。解决方案很简单。

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的编辑。希望这可以帮助别人。

+0

不幸的是,'[AVSpeechSynthesisVoice voiceWithIdentifier:]'方法似乎从iOS 9.1+中缺失。用不太有用的'voiceWithLanguage'代替。 – axello

0

下面介绍一种方法。让我们与亚历克斯坚持为例:

- (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 =增强)。

相关问题