Mac OS X 文本转语音性别

发布于 2024-11-19 21:37:24 字数 909 浏览 6 评论 0原文

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

I'm making an application, in which I am trying to get all the different voices in Mac OS X, and then sort them by gender. I've created three mutable arrays to put the voices of each gender (Male, Female, Novelty) in, and I'm using enumeration to go through each one and put it in the correct array. Unfortunately, It's not working. All but the novelty arrays come up empty, and the novelty array only has one voice, Zarvox. Does anybody see what I'm doing wrong? I've posted the code below:

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];
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黄昏下泛黄的笔记 2024-11-26 21:37:24

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

Allocate maleVoices, femaleVoices, and noveltyVoices outside of the for loop. You're just creating a new, empty array with each iteration of the loop.

烟花肆意 2024-11-26 21:37:24

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

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

Direct equality comparison with strings is usually unreliable. Use the -isEqualToString: method:

if([voiceGender isEqualToString:NSVoiceGenderMale]){
    // etc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文