2

を作成し、 の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];
    }

}

4

4 に答える 4

1

元のコードは次のとおりです。

if (synthesizer_.isSpeaking) {

代わりにこれを試してください:

if (![synthesizer_ isPaused])

理由:

ドキュメントから: Speaking シンセサイザーが話しているかどうかを示すブール値。(読み取り専用)

@property(nonatomic, readonly, getter=isSpeaking) BOOL speaking

ディスカッションYESシンセサイザーが話しているか、話すためにキューに入れられた発話がある場合は、現在一時停止されている場合でも戻ります。NOシンセサイザーがキュー内のすべての発話を話し終えたか、または話す発話をまだ与えられていないかどうかを返します。

提供状況 iOS 7.0 以降で利用可能です。で宣言 AVSpeechSynthesis.h

したがって、このプロパティを使用し、音声が一時停止されている場合、このプロパティが true になる可能性があり、音声継続コードは実行されません。

于 2013-11-22T17:48:39.167 に答える
1

isPaused から始めるだけで問題なく動作します。

注: より良い結果を得るには、AVSpeechBoundaryWord の代わりに AVSpeechBoundaryImmediate を使用してください。

- (IBAction)pauseButtonPressed:(id)sender {
    if (synthesizer_.isPaused) {
        [synthesizer_ continueSpeaking];
    }
    else{
        [synthesizer_ pauseSpeakingAtBoundary: AVSpeechBoundaryImmediate];
    }
}
于 2015-07-11T16:05:29.897 に答える
0

フォローコードを使用してみてください

-(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];
}
于 2014-12-08T04:28:26.760 に答える