我正在开发一个iOS文本到语音的应用程序,并试图添加一个使用Alex语音的选项,这是iOS 9的新功能。我需要确定用户是否在设置->可访问性中下载了Alex的声音。我似乎不知道该怎么做。
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.");
}
}
此方法循环遍历所有已安装的声音并查询每个声音的名称。如果亚历克斯在其中,他就被安插了。
您可以查询的其他值是"语言"(返回语言代码,如en-US)和质量(1 =标准,2 =增强)。