首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVSpeechSynthesizer postUtteranceDelay计时问题

AVSpeechSynthesizer postUtteranceDelay计时问题
EN

Stack Overflow用户
提问于 2014-02-11 05:47:33
回答 1查看 833关注 0票数 0

下面的代码获取一个方向列表,并使用AVSpeechSynthesizer读出它们。一旦完成,用户将能够选择可变的时间量,应用程序将读取指令以适应时间跨度。

问题是,当我按下播放按钮时,方向之间的延迟比正常情况下要长得多。而不是我硬编码的两分钟,它需要超过三分钟。我已经记录了我所有postUtteranceDelays的值,它们正确地累加起来。这也不是由于处理时间的原因,因为当postUtteranceDelay设置为0时,方向之间没有停顿。我不知道是怎么回事。

代码语言:javascript
复制
- (IBAction)play:(UIButton *)sender {
[sender setTitle:@"Showering" forState:UIControlStateNormal];
Shower *shower = [[SpecificShower alloc] init];

NSUInteger totalRatio = [shower calculateTotalRatio:shower];
NSNumber *offset = @18.0; // estimated time to speak instructions combined
NSNumber *seconds = @120.0; // hard coded but just for testing
int totalSeconds = seconds.intValue - offset.intValue;

self.synthesizer = [[AVSpeechSynthesizer alloc] init];

for (NSDictionary* direction in shower.directions) {

    AVSpeechUtterance *aDirection = [[AVSpeechUtterance alloc] initWithString:direction[@"text"]];
    NSNumber *directionLength = direction[@"length"];
    aDirection.rate = .3;
    aDirection.preUtteranceDelay = 0;
    // totalRatio is calculated by adding all the lengths together 
    // then the individual direction length is divided by totalRatio
    // and that fraction is multiplied by total number of seconds
    // to come up with the postUtteranceDelay for each direction
    aDirection.postUtteranceDelay = totalSeconds * [directionLength floatValue]/totalRatio;
    NSLog(@"%f", aDirection.postUtteranceDelay);
    [self.synthesizer speakUtterance:aDirection];
}

}
EN

回答 1

Stack Overflow用户

发布于 2014-05-13 17:02:55

你并不孤单。这似乎是here上的一个变通方法中提到的一个错误。

还有herehere的雷达。

让我们希望这个问题能很快得到解决。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21688624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档