我正在製作一個應用程序,其中我試圖在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'變量? –