我正在制作一个应用程序,我试图在 Mac OS X 中获取所有不同的声音,然后按性别对它们进行排序。我创建了三个可变数组来放入每个性别(男性、女性、新奇)的声音,并且我正在使用枚举来遍历每个数组并将其放入正确的数组中。不幸的是,它不起作用。除了新奇阵外,所有的都是空的,新奇阵只有一个声音,Zarvox。有人看到我做错了吗?我已经发布了下面的代码:
NSArray* voices = [NSSpeechSynthesizer availableVoices];
for(NSString* x in voices){
NSDictionary* voiceInfo = [NSSpeechSynthesizer attributesForVoice:x];
NSString* voiceName = [voiceInfo objectForKey:NSVoiceName];
NSString* voiceGender = [voiceInfo objectForKey:NSVoiceGender];
maleVoices = [[NSMutableArray alloc] init];
femaleVoices = [[NSMutableArray alloc] init];
noveltyVoices = [[NSMutableArray alloc] init];
if (voiceGender == NSVoiceGenderMale){
[maleVoices addObject:voiceName];
} else if (voiceGender == NSVoiceGenderFemale) {
[femaleVoices addObject:voiceName];
} else {
[noveltyVoices addObject:voiceName];
}
}