iOS Developer Library

Developer

AVFoundation Framework Reference AVSpeechSynthesizerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

AVSpeechSynthesizerDelegate

The AVSpeechSynthesizerDelegate protocol defines methods that the delegate of an AVSpeechSynthesizer object may implement; all methods in this protocol are optional. You can implement these methods to respond to events that occur during speech synthesis.

Delegate messages are sent by the synthesizer for three categories of events:

  • When speech pauses or resumes

  • When the synthesizer starts or finishes speaking a block of text (as encapsulated by an AVSpeechUtterance object)

  • As the synthesizer produces each individual unit of speech

For the third case, you can implement speechSynthesizer:willSpeakRangeOfSpeechString:utterance: to provide a user interface in which each word is visibly highlighted as it is spoken.

Inheritance


Not Applicable

Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 7.0 and later.
  • Tells the delegate when the synthesizer has canceled speaking an utterance.

    Declaration

    Swift

    optional func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer!, didCancelSpeechUtterance utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance

    Parameters

    synthesizer

    The synthesizer speaking the utterance that this message applies to.

    utterance

    The utterance during which speech was canceled.

    Discussion

    This message is sent only if speech is stopped (using the stopSpeakingAtBoundary: method) while an utterance is being spoken. It is not sent if the synthesizer is currently in a delay between utterances when speech stops. This message is sent only for the utterance currently being spoken, not for utterances yet to be handled.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate when the synthesizer has resumed speaking an utterance after being paused.

    Declaration

    Swift

    optional func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer!, didContinueSpeechUtterance utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance *)utterance

    Parameters

    synthesizer

    The synthesizer speaking the utterance that this message applies to.

    utterance

    The utterance being spoken.

    Discussion

    This message is sent upon resuming speech only if speech was paused (using the pauseSpeakingAtBoundary: method) while an utterance was being spoken. It is not sent if the synthesizer was paused during a delay between utterances.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate when the synthesizer has finished speaking an utterance.

    Declaration

    Swift

    optional func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer!, didFinishSpeechUtterance utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance

    Parameters

    synthesizer

    The synthesizer speaking the utterance that this message applies to.

    utterance

    The utterance that has finished being spoken.

    Discussion

    This message is sent immediately when speech ends; it is not postponed if the final utterance’s postUtteranceDelay is greater than zero.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate when the synthesizer has paused while speaking an utterance.

    Declaration

    Swift

    optional func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer!, didPauseSpeechUtterance utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance

    Parameters

    synthesizer

    The synthesizer speaking the utterance that this message applies to.

    utterance

    The utterance being spoken.

    Discussion

    This message is sent only if speech is paused (using the pauseSpeakingAtBoundary: method) while an utterance is being spoken. It is not sent if the synthesizer is currently in a delay between utterances when speech pauses.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate when the synthesizer has begun speaking an utterance.

    Declaration

    Swift

    optional func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer!, didStartSpeechUtterance utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance

    Parameters

    synthesizer

    The synthesizer speaking the utterance that this message applies to.

    utterance

    The utterance that has begun to be spoken.

    Discussion

    If the value of the utterance’s preUtteranceDelay property is grreater than zero, the message is not sent until the delay period has passed and speech has actually begun.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate when the synthesizer is about to speak a portion of an utterance’s text.

    Declaration

    Swift

    optional func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer!, willSpeakRangeOfSpeechString characterRange: NSRange, utterance utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance

    Parameters

    synthesizer

    The synthesizer speaking the utterance that this message applies to.

    characterRange

    The range of characters in the utterance’s speechString corresponding to the unit of speech about to be spoken.

    utterance

    The utterance currently being spoken.

    Discussion

    Because this delegate message is sent once for each unit of speech (generally, a word) in the utterance’s text, you can use it for such purposes as highlighting each word onscreen as it is spoken.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.