我創建了一個AVSpeechSynthesizer
並開始播放AVSpeechUtterance
。這工作正常。如果用戶按下按鈕,則暫停合成器。這也適用。但是,當我嘗試用continueSpeaking
方法重啓合成器時,沒有任何反應。如果我檢查isSpeaking
財產,它仍然是NO
。我怎樣才能讓音頻從停止播放的地方開始播放?AVSpeechSynthesizer繼續說不工作
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];
}
}
我有一個類似的問題,其中'[synthesizer_pauseSpeakingAtBoundary:AVSpeechBoundaryWord]'不會暫停說話。相反,我得到多個'didPauseSpeechUtterance' /'didContinueSpeechUtterance'事件,直到話語完成。使用'pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate'似乎更好。 –
我將代碼中的所有其他引用刪除到AVAudio項目,然後我經歷了與重做'didPauseSpeechUtterance' /'didContinueSpeechUtterance'事件相同的事情。 – user2880019