如何检测iOS设备是否下载了语音文件?
我正在开发一个iOS文本语音转换应用程序,并尝试添加一个使用Alex voice的选项,这是iOS 9的新功能。我需要确定用户是否已在设置->可访问性中下载Alex voice。我似乎不知道该怎么做如何检测iOS设备是否下载了语音文件?,ios,objective-c,text-to-speech,Ios,Objective C,Text To Speech,我正在开发一个iOS文本语音转换应用程序,并尝试添加一个使用Alex voice的选项,这是iOS 9的新功能。我需要确定用户是否已在设置->可访问性中下载Alex voice。我似乎不知道该怎么做 if ([AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex] == "Not Found" ) { // Do something... } 原因是其他语言的声音是标准的,以一定的
if ([AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex] == "Not Found" ) {
// Do something...
}
原因是其他语言的声音是标准的,以一定的速度播放,不同于Alex的声音。因此,我有一个可用的应用程序,但如果用户没有下载语音,iOS会自动默认为基本语音,但播放速率不正确。如果我能检测到未下载的语音,我可以补偿差异和/或建议用户。好的,所以我想我是想得太多了,认为这更复杂。解决办法很简单
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的编辑。希望这对其他人有帮助 这里有一种方法。让我们以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.");
}
}
此方法循环所有已安装的语音并查询每个语音的名称。如果亚历克斯也在其中,他就被安排好了
您可以查询的其他值包括“language”(返回类似en US的语言代码)和quality(1=标准,2=增强)。一个有趣且格式良好的问题+1不幸的是,iOS 9.1+中似乎缺少
[AVSpeechSynthesisVoice voiceWithIdentifier::
方法。被不太有用的“voiceWithLanguage”取代。