首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVSpeechSynthesizer未暂停

AVSpeechSynthesizer未暂停
EN

Stack Overflow用户
提问于 2014-07-26 23:32:23
回答 1查看 699关注 0票数 0

我在我的应用程序中使用AVSpeechSynthesizer。这些是我设置iOS 7TTS的步骤。

代码语言:javascript
复制
#import <AVFoundation/AVFoundation.h>

@interface SpeakViewController : UIViewController <AVSpeechSynthesizerDelegate> {
    BOOL speechPaused;
}
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
@end

然后在我的.m中:

代码语言:javascript
复制
-(void)viewDidLoad
{
    speechPaused = NO;
    [self playSound];
}
// The sound is playing fine. 
-(void) playSound {
    speechPaused = NO;
    AVSpeechUtterance* utter = [[AVSpeechUtterance alloc] initWithString:_text];
    utter.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
    [utter setRate:0.2f];
    if (!self.synthesizer) {
        self.synthesizer = [AVSpeechSynthesizer new];
    }
    self.synthesizer.delegate = self;
    [self.synthesizer speakUtterance:utter];
}
// This is what isn't working
- (void) pauseSpeech {
    if (speechPaused == NO) {
        [self.synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
        NSLog(@"Pause");
        speechPaused = YES;
    }
    if (self.synthesizer.speaking == NO) {
        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@""];
        utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"];
        [self.synthesizer speakUtterance:utterance];
    }
}
- (void) playSpeech {
    [self.synthesizer continueSpeaking];
    speechPaused = NO;
    NSLog(@"Play");
}
- (IBAction)pauseSpeech:(id)sender {
    [self pauseSpeech];
}
- (IBAction)startSpeech:(id)sender {
    [self playSpeech];
}

我也在这个方法中设置了一个NSLog,但它从未被调用过:

代码语言:javascript
复制
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance
{
     NSLog(@"speechSynthesizer didPauseSpeechUtterance");
}

我已经被困在这里好几天了。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2014-12-08 12:34:16

尝尝这个

代码语言:javascript
复制
-(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];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24972604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档