【问题标题】:AVSpeechSynthesizer postUtteranceDelay timing problemsAVSpeechSynthesizer postUtteranceDelay 时序问题
【发布时间】:2014-05-13 17:02:55
【问题描述】:

下面的代码获取方向列表并使用 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];
}

}

【问题讨论】:

    标签: ios objective-c avfoundation avspeechsynthesizer


    【解决方案1】:

    你并不孤单。正如here 的解决方法所指出的那样,这似乎是一个错误。
    还有雷达归档here 和here。

    希望这个问题能尽快解决。

    【讨论】:

    • 我发现了一个类似的问题,当我设置 postUtteranceDelay = 0.3 时,有时 didStartSpeechUtterance 将不再被触发,如果我设置 postUtteranceDelay = 0,一切都很好。这只发生在 iOS8 上
    • OP 询问的是延迟问题,而不是停止话语问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    相关资源
    最近更新 更多