我正在制作一个应用程序,试图在其中获得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];
    }
}

最佳答案

maleVoices循环之外分配femaleVoicesnoveltyVoicesfor。您只是在循环的每次迭代中创建一个新的空数组。

10-08 06:05