1

我正在开发一个在UITextFieldusing中读取文本的应用程序,AVSpeech并且我试图在它读取特定单词时暂停阅读,例如它正在阅读这个This is awesome.,我希望它在阅读时暂停阅读 2 秒钟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];

谢谢

4

4 回答 4

0

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

于 2014-03-24T15:49:44.687 回答
0

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

请阅读文章的代表部分 - 您找到了一种显示当前说出的单词的方法。然后只需使用synthesize pauseSpeakingAtBoundary暂停 2 秒然后恢复 TTS。

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

于 2015-02-11T08:42:07.807 回答
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];
}
于 2014-12-06T07:31:41.983 回答
0

分成两个话语,并用 .preUtteranceDelay = 2.0 设置第二个

于 2017-06-05T19:36:52.150 回答