Mac OS X文本到语音的性别(Mac OS X Text

编程入门 行业动态 更新时间:2024-10-28 04:16:29
Mac OS X文本到语音的性别(Mac OS X Text-To-Speech Genders)

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

最满意答案

在for循环之外分配maleVoices , femaleVoices和noveltyVoices 。 您只需在循环的每次迭代中创建一个新的空数组。

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

更多推荐

本文发布于:2023-07-16 09:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语音   文本   性别   Mac   OS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!