我正在使用 sfoster iPhone TTS。我想将文本转换为语音,还想将字符串拆分为字母,文本和每个字母都会发音。但它不发音文本和字母。我的代码如下:
-(void)spellOut:(NSString *)text{
[fliteEngine speakText:text];
[fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
[fliteEngine setVoice:@"cmu_us_rms"];
/* split a string into an array */
NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[text length]];
for (int i=0; i < [text length]; i++) {
NSString *ichar = [NSString stringWithFormat:@"%c", [text characterAtIndex:i]];
[characters addObject:ichar];
}
/* set letter from each index of the array */
for (int i=0; i<[characters count]; i++) {
NSString *letter = [characters objectAtIndex:i];
NSLog(@"%@\n",letter);
[fliteEngine speakText:letter];
[fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
[fliteEngine setVoice:@"cmu_us_rms"];
}
}
问题出在哪里?
提前致谢。
最佳答案
首先,您似乎尚未启动 FliteTTS,因此请先执行此操作
fliteEngine = [[FliteTTS alloc] init];
然后,当我通过您的代码了解到,如果您使用此代码,它就会起作用 无需单独发音所有字符。
-(void)spellOut:(NSString *)text{
[fliteEngine speakText:text];
[fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
[fliteEngine setVoice:@"cmu_us_rms"];
/* split a string into an array */
NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[text length]];
for (int i=0; i < [text length]; i++)
{
NSString *ichar = [NSString stringWithFormat:@"%c", [text characterAtIndex:i]];
[characters addObject:ichar];
}
}
希望对您有帮助。
关于iphone - 文本转语音不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16295693/