下面的代码获取一个方向列表,并使用AVSpeechSynthesizer读出它们。一旦完成,用户将能够选择可变的时间量,应用程序将读取指令以适应时间跨度。
问题是,当我按下播放按钮时,方向之间的延迟比正常情况下要长得多。而不是我硬编码的两分钟,它需要超过三分钟。我已经记录了我所有postUtteranceDelays的值,它们正确地累加起来。这也不是由于处理时间的原因,因为当postUtteranceDelay设置为0时,方向之间没有停顿。我不知道是怎么回事。
- (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];
}
}发布于 2014-05-13 17:02:55
https://stackoverflow.com/questions/21688624
复制相似问题