我正在制作一个应用程序,其中我试图在Mac OS X中获取所有不同的声音,然后按性别对它们进行排序。我创建了三个可变数组来放置每个性别(男性,女性,新奇)的声音,并且我使用枚举来遍历每个性别并将其放入正确的数组中。不幸的是,这不起作用。除了新颖的阵列之外,所有的新颖阵列都是空的,而新奇阵列只有一个声音,Zarvox。有人看到我做错了吗?我发布了以下代码:Mac OS X文本转语音性别
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];
}
}
您是否试过使用'isEqual:'方法而不是'=='比较'voiceGender'变量? –