iOS - 在阅读特定单词时暂停AVSpeech

时间:2014-03-24 15:39:44

标签: ios objective-c avspeechsynthesizer

我正在使用UITextField使用AVSpeech阅读This is awesome.中的文字的应用,我试图在读取特定字时暂停阅读,例如其阅读这个is我希望它在读取AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init]; AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@"This is awesome"]; utterance.rate = 0.15; utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-us"]; [synth speakUtterance:utterance]; 时暂停阅读2秒,然后完成阅读。这是我读取字符串的代码。

{{1}}

由于

4 个答案:

答案 0 :(得分:0)

在出现" is"时将你的话语字符串分开。并将组件放在一个数组中。按顺序读取数组中的每个字符串,其间包含sleep(2)。请记住,在主线程上休眠将禁用您的UI交互。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

这是关于NSTipster关于iOS的TTS的好文章 - http://nshipster.com/avspeechsynthesizer/

请阅读文章的委托部分 - 您会找到一种方法来显示当前显示的单词。然后使用合成pauseSpeakingAtBoundary 暂停2秒然后恢复TTS。

完整的示例项目在GitHub上:https://github.com/mattt/AVSpeechSynthesizer-Example。您可以找到一些其他有用的技术来使用TTS。

答案 3 :(得分:0)

分成两个话语,用.preUtteranceDelay = 2.0

设置第二个话语