iOS Developer Library

Developer

AVFoundation Framework Reference AVSpeechSynthesizer Class Reference

Options
Deployment Target:

On This Page
Language:

AVSpeechSynthesizer

The AVSpeechSynthesizer class produces synthesized speech from text on an iOS device, and provides methods for controlling or monitoring the progress of ongoing speech.

To speak some amount of text, you must first create an AVSpeechUtterance instance containing the text. (Optionally, you may also use the utterance object to control parameters affecting its speech, such as voice, pitch, and rate.) Then, pass it to the speakUtterance: method on a speech synthesizer instance to speak that utterance.

The speech synthesizer maintains a queue of utterances to be spoken. If the synthesizer is not currently speaking, calling speakUtterance: begins speaking that utterance immediately (or begin waiting through its preUtteranceDelay if one is set). If the synthesizer is speaking, utterances are added to a queue and spoken in the order they are received.

After speech has begun, you can use the synthesizer object to pause or stop speech. After speech is paused, it may be continued from the point at which it left off; stopping ends speech entirely, removing any utterances yet to be spoken from the synthesizer’s queue.

You may monitor the speech synthesizer by examining its speaking and paused properties, or by setting a delegate. Messages in the AVSpeechSynthesizerDelegate protocol are sent as significant events occur during speech synthesis.

Inheritance


Conforms To


Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 7.0 and later.
  • Enqueues an utterance to be spoken.

    Declaration

    Swift

    func speakUtterance(_ utterance: AVSpeechUtterance!)

    Objective-C

    - (void)speakUtterance:(AVSpeechUtterance *)utterance

    Parameters

    utterance

    An AVSpeechUtterance object containing text to be spoken.

    Discussion

    The AVSpeechUtterance object not only contains the text to be spoken, but also parameters controlling speech synthesis such as voice, pitch, and delays between utterances.

    Calling this method adds the utterance to a queue; utterances are spoken in the order in which they are added to the queue. If the synthesizer is not currently speaking, the utterance is spoken immediately. Attempting to enqueue AVSpeechUtterance instance multiple times throws an exception.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Continues speech from the point at which it left off.

    Declaration

    Swift

    func continueSpeaking() -> Bool

    Objective-C

    - (BOOL)continueSpeaking

    Return Value

    YEStrue if speech has continued, or NOfalse otherwise.

    Discussion

    This method only has any effect if the synthesizer is paused.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Pauses speech at the specified boundary constraint.

    Declaration

    Swift

    func pauseSpeakingAtBoundary(_ boundary: AVSpeechBoundary) -> Bool

    Objective-C

    - (BOOL)pauseSpeakingAtBoundary:(AVSpeechBoundary)boundary

    Parameters

    boundary

    A constant describing whether speech should pause immediately or only after finishing the word currently being spoken.

    Return Value

    YEStrue if speech has paused, or NOfalse otherwise.

    Discussion

    The boundary parameter also affects the manner in which the synthesizer, once paused, continues speech upon a call to continueSpeaking. If paused with boundary constraint AVSpeechBoundaryImmediate, speech continues from exactly the point at which it was paused, even if that point occurred in the middle of pronouncing a word. If paused with AVSpeechBoundaryWord, speech continues from the word following the word on which it was paused.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • paused paused Property

    A Boolean value that indicates whether speech has been paused. (read-only)

    Declaration

    Swift

    var paused: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isPaused) BOOL paused

    Discussion

    Returns YEStrue if the synthesizer has begun speaking an utterance and was paused using pauseSpeakingAtBoundary:; NOfalse otherwise.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • speaking speaking Property

    A Boolean value that indicates whether the synthesizer is speaking. (read-only)

    Declaration

    Swift

    var speaking: Bool { get }

    Objective-C

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

    Discussion

    Returns YEStrue if the synthesizer is speaking or has utterances enqueued to speak, even if it is currently paused. Returns NOfalse if the synthesizer has finished speaking all utterances in its queue or if it has not yet been given an utterance to speak.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Stops all speech at the specified boundary constraint.

    Declaration

    Swift

    func stopSpeakingAtBoundary(_ boundary: AVSpeechBoundary) -> Bool

    Objective-C

    - (BOOL)stopSpeakingAtBoundary:(AVSpeechBoundary)boundary

    Parameters

    boundary

    A constant describing whether speech should stop immediately or only after finishing the word currently being spoken.

    Return Value

    YEStrue if speech has stopped, or NOfalse otherwise.

    Discussion

    Stopping the synthesizer cancels any further speech; in constrast with when the synthesizer is paused, speech cannot be resumed where it left off. Any utterances yet to be spoken are removed from the synthesizer’s queue.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.

  • Constraints describing when speech may be paused or stopped.

    Declaration

    Swift

    enum AVSpeechBoundary : Int { case Immediate case Word }

    Objective-C

    typedef enum : NSInteger { AVSpeechBoundaryImmediate, AVSpeechBoundaryWord } AVSpeechBoundary;

    Constants

    • Immediate

      AVSpeechBoundaryImmediate

      Indicates that speech should pause or stop immediately.

      Available in iOS 7.0 and later.

    • Word

      AVSpeechBoundaryWord

      Indicates that speech should pause or stop after the word currently being spoken.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later.