我已经创建了一个AVSpeechSynthesizer并开始播放AVSpeechUtterance。这可以很好地工作。如果用户按下按钮,我会暂停合成器。这也是可行的。但是,当我尝试使用continueSpeaking方法重新启动合成器时,什么也没有发生。如果我检查isSpeaking属性,它仍然是NO。如何才能让音频从中断的位置重新开始播放?
AVSpeechSynthesizer *synthesizer_;
synthesizer_ = [[AVSpeechSynthesizer alloc] init];
synthesizer_.delegate = self;
- (void)textToSpeech{
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:itemText];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:localeCode];
utterance.rate = UTTERANCE_RATE;
utterance.preUtteranceDelay = itemDelayTimeInterval;
[synthesizer_ speakUtterance:utterance];
}
- (IBAction)pauseButtonPressed:(id)sender {
if (synthesizer_.isSpeaking) {
[synthesizer_ pauseSpeakingAtBoundary:AVSpeechBoundaryWord];
}
else{
[synthesizer_ continueSpeaking];
}}
发布于 2013-11-23 01:48:39
你的原始代码是:
if (synthesizer_.isSpeaking) {试着这样做:
if (![synthesizer_ isPaused])原因:
一个布尔值,指示合成器是否正在说话。(只读)
@property(nonatomic, readonly, getter=isSpeaking) BOOL speaking如果合成器正在发言或有发言排队等待发言,则讨论返回YES,即使它当前处于暂停状态。如果合成器已完成其队列中的所有发声,或者尚未发出发声,则返回NO。
在iOS 7.0及更高版本中可用。在AVSpeechSynthesis.h中声明
因此,如果使用此属性,并且语音已暂停,则此属性可能为true,并且语音继续代码将不会运行。
发布于 2015-07-12 00:05:30
只要从isPaused开始,它就会工作得很好:
注意:使用AVSpeechBoundaryImmediate代替AVSpeechBoundaryWord可以获得更好的效果。
- (IBAction)pauseButtonPressed:(id)sender {
if (synthesizer_.isPaused) {
[synthesizer_ continueSpeaking];
}
else{
[synthesizer_ pauseSpeakingAtBoundary: AVSpeechBoundaryImmediate];
}
}发布于 2014-12-08 12:28:27
尝试使用以下代码
-(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];
}https://stackoverflow.com/questions/19367670
复制相似问题