Mac OS X文本到语音性能

时间:2011-07-11 19:23:33

标签: objective-c cocoa text-to-speech speech-synthesis

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

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:2)

与字符串的直接相等比较通常是不可靠的。使用-isEqualToString:方法:

if([voiceGender isEqualToString:NSVoiceGenderMale]){
    // etc.