【问题标题】:AVSpeechSynthesizer - does not stop when using AVSpeechBoundaryImmediateAVSpeechSynthesizer - 使用 AVSpeechBoundaryImmediate 时不会停止
【发布时间】:2014-12-11 13:43:16
【问题描述】:

我有两个视图控制器。一和二。

  1. 在 oneViewController 上,有一个使用 Storyboard 调用 TwoViewController 的按钮 - 工作正常
  2. 在 TwoViewController 上有一个按钮,可以使用按钮(侦听按钮)读取一些文本 - 工作正常
  3. TwoViewController 上有返回按钮,可将您带回 oneViewController。

问题:

如果两次单击听按钮并按下返回按钮,视图控制器会从二变为一,但语音仍在后台进行。有人可以帮忙阻止演讲吗?

TwoViewController 上的代码:

AVSpeechSynthesizer *synth;

-(IBAction) Back:(id)sender
{
    [_synth stopSpeakingAtBoundary: AVSpeechBoundaryImmediate]; --not working
    [self dismissViewControllerAnimated:YES completion:nil]; - working fine.
}

-(void) viewDidDisappear:(BOOL)animated
{
    [_synth stopSpeakingAtBoundary:AVSpeechBoundaryImmediate]; --not working
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(IBAction)listenButton:(id)sender
{
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"I am running a test."];
    [utterance setRate:0.18f];
    _synth=[[AVSpeechSynthesizer alloc] init];
    [_synth speakUtterance:utterance];

}

注意:如果单击“收听”按钮一次,然后单击“返回”按钮,则不会出现此问题。仅当多次单击“收听”按钮然后单击“返回”按钮时才会出现问题。

【问题讨论】:

    标签: ios text-to-speech avspeechsynthesizer


    【解决方案1】:

    试试这个暂停、恢复和停止选项

    -(void)stopSpeechReading
    {
        if([synthesize isSpeaking]) {
            NSLog(@"Reading has been stopped");
            [synthesize stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
            AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@""];
            [synthesize speakUtterance:utterance];
            [synthesize stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
        }
    }
    
    -(void)pauseSpeechReading
    {
        if([synthesize isSpeaking]) {
            NSLog(@"Reading paused");
            [synthesize pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
            AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@""];
            [synthesize speakUtterance:utterance];
            [synthesize pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
        }
    }
    
    -(void)resumeSpeechReading
    {
         NSLog(@"Reading resumed");
        [synthesize continueSpeaking];
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多