Iphone 文本到语音转换不工作

Iphone 文本到语音转换不工作,iphone,ios,text-to-speech,Iphone,Ios,Text To Speech,我正在使用Sforter iPhone TTS。我想把一个文本转换成语音,还想把字符串拆分成字母&文本和每个字母都会发音。但这并不是文本&字母的发音。我的代码如下: -(void)spellOut:(NSString *)text{ [fliteEngine speakText:text]; [fliteEngine setPitch:100.0 variance:50.0 speed:2.5]; [fliteEngine setVoice:@"cmu_us_rms"]; /* spl

我正在使用Sforter 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"];   
  }

}
-(void)拼写:(NSString*)文本{
[fliteEngine speakText:text];
[飞行发动机设定螺距:100.0变化:50.0速度:2.5];
[fliteEngine setVoice:@“cmu_us_rms”];
/*将字符串拆分为数组*/
NSMutableArray*字符=[[NSMutableArray alloc]initWithCapacity:[文本长度]];
对于(int i=0;i<[文本长度];i++){
NSString*ichar=[NSString stringWithFormat:@“%c”,[text characterAtIndex:i]];
[对象:ichar];
}
/*从数组的每个索引中设置字母*/
对于(int i=0;i
-(void)viewDidLoad
{
@试一试{
[超级视图下载];
self.wordToSpeech=@“功能性食品是什么意思?根据美国饮食协会(ADA)2009年4月关于功能性食品的立场),所有食品在一定程度上都是功能性的,因为它们提供了提供能量、维持生长或维持和修复生命过程的营养素。虽然功能性食品类别本身没有得到食品和药物管理局的正式承认,但美国食品和药品管理局认为功能性食品是全食品和强化、浓缩或强化食品对健康有潜在有益影响的食品。因此,功能性食品的种类可能多种多样,如坚果、钙强化橙汁、能量棒、瓶装茶和无麸质食品。虽然从全麦面包到野生鲑鱼等许多功能性食品提供了明显的健康益处,但其他功能性食品如acai berry或brain开发食品可能会做出过于乐观的承诺。因此,在购买每种功能性食品的益处之前,根据科学证据对其进行评估是很重要的”;
[自言自语];
}
@捕获(NSException*异常)
{
NSLog(@“%s\n异常:名称-%@原因->%@),[异常名称],[异常原因];
}
}
-(无效)句子表达{
@试一试{
NSString*sentenceToSpeech=@;
如果(0==self.totalCountPlayed){
sentenceToSpeech=[self.wordToSpeech substringToIndex:100];
self.totalCountPlayed=100;
}
否则{
NSString*tempString=[self.wordtospeechsubstringfromfromindex:self.totalCountPlayed];

如果(100首先,您似乎还没有启动flitets,那么请先执行此操作

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


}
-(void)拼写:(NSString*)文本{
[fliteEngine speakText:text];
[飞行发动机设定螺距:100.0变化:50.0速度:2.5];
[fliteEngine setVoice:@“cmu_us_rms”];
/*将字符串拆分为数组*/
NSMutableArray*字符=[[NSMutableArray alloc]initWithCapacity:[文本长度]];
对于(int i=0;i<[文本长度];i++)
{
NSString*ichar=[NSString stringWithFormat:@“%c”,[text characterAtIndex:i]];
[对象:ichar];
}
}

希望对您有所帮助。

您可以使用计时器拼写文本

.h

NSString *speechText;
int tempVariable;
.m

-(void)spellOut:(NSString *)text{

    speechText=[NSString stringWithFormat:@"%@",text];

    tempVariable=0;

    [fliteEngine speakText:text];   
    [fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
    [fliteEngine setVoice:@"cmu_us_rms"];

    NSTimer *popupTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    NSRunLoop *runner = [NSRunLoop currentRunLoop];
    [runner addTimer:popupTimer forMode: NSDefaultRunLoopMode];
}

-(void)timerAction:(NSTimer *)theTimer {

    if(tempVariable<speechText.length) {

        NSString *letter = [NSString stringWithFormat:@"%c",[speechText characterAtIndex:tempVariable]];

        NSLog(@"%@\n",letter);

        [fliteEngine speakText:letter];
        [fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
        [fliteEngine setVoice:@"cmu_us_rms"];
        tempVariable++;
    } else {

        [theTimer invalidate];
        theTimer=nil;
    }

}
-(void)拼写:(NSString*)文本{
speechText=[NSString stringWithFormat:@“%@”,text];
tempVariable=0;
[fliteEngine speakText:text];
[飞行发动机设定螺距:100.0变化:50.0速度:2.5];
[fliteEngine setVoice:@“cmu_us_rms”];
NSTimer*popupTimer=[NSTimer timerWithTimeInterval:1目标:自选择器:@selector(timerAction:)userInfo:nil repeats:YES];
NSRunLoop*runner=[NSRunLoop currentlunloop];
[runner addTimer:popupTimer forMode:NSDefaultRunLoopMode];
}
-(无效)计时器:(n计时器*)计时器{

如果(tempVariableI已经在我的viewDidLoad方法中启动了Flite TTs。&u编写的这部分代码只适用于完整的字符串。但是我也需要发字母的音。它们不起作用!@Leo此框架不支持发字母的音,您必须使用google API。我已经提到了代码,这可能会对您有所帮助@Divz谢谢你的建议。应该有speechText而不是lbl.text吗?好吧…兄弟,文本是发音的,但不是字母!不明白是什么问题!是的,它应该这样说,但它不起作用!非常奇怪!
-(void)spellOut:(NSString *)text{

    speechText=[NSString stringWithFormat:@"%@",text];

    tempVariable=0;

    [fliteEngine speakText:text];   
    [fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
    [fliteEngine setVoice:@"cmu_us_rms"];

    NSTimer *popupTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    NSRunLoop *runner = [NSRunLoop currentRunLoop];
    [runner addTimer:popupTimer forMode: NSDefaultRunLoopMode];
}

-(void)timerAction:(NSTimer *)theTimer {

    if(tempVariable<speechText.length) {

        NSString *letter = [NSString stringWithFormat:@"%c",[speechText characterAtIndex:tempVariable]];

        NSLog(@"%@\n",letter);

        [fliteEngine speakText:letter];
        [fliteEngine setPitch:100.0 variance:50.0 speed:2.5];
        [fliteEngine setVoice:@"cmu_us_rms"];
        tempVariable++;
    } else {

        [theTimer invalidate];
        theTimer=nil;
    }

}