iOS Developer Library

Developer

AVFoundation Framework Reference AVSpeechUtterance Class Reference

Options
Deployment Target:

On This Page
Language:

AVSpeechUtterance

Inherits From


Conforms To


Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 7.0 and later

An AVSpeechUtterance is the basic unit of speech synthesis. An utterance encapsulates some amount of text to be spoken and a set of parameters affecting its speech: voice, pitch, rate, and delay.

To synthesize speech, you must:

  1. Create an AVSpeechUtterance instance containing the text to be spoken. (See Creating an Utterance.)

  2. (Optional) Change its voice, rate, or other parameters. (See Configuring Utterance Speech.)

  3. Pass the utterance to an AVSpeechSynthesizer instance to begin speech (or enqueue the utterance to be spoken later if the synthesizer is already speaking).

You may choose whether and how to split a body of text into multiple utterances for speech. Because an utterance can control speech parameters, you can split text into sections that require different parameters. For example, you can emphasize a sentence by increasing the pitch and decreasing the rate of that utterance relative to others, or you can introduce pauses between sentences by putting each one into an utterance with a leading or trailing delay. Because the speech synthesizer sends messages to its delegate as it starts or finishes speaking an utterance, you can create an utterance for each meaningful unit in a longer text in order to be notified as its speech progresses.

  • Initializes an utterance object with text to be spoken.

    Declaration

    Swift

    init!(string string: String!)

    Objective-C

    - (instancetype)initWithString:(NSString *)string

    Parameters

    string

    A string containing text to be spoken.

    Return Value

    An AVSpeechUtterance object that can speak the specified text.

    Discussion

    To speak the text, the utterance must be passed to an instance of AVSpeechSynthesizer.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

    See Also

    speakUtterance:

  • Creates an utterance object with text to be spoken.

    Declaration

    Objective-C

    + (instancetype)speechUtteranceWithString:(NSString *)string

    Parameters

    string

    A string containing text to be spoken.

    Return Value

    An AVSpeechUtterance object that can speak the specified text.

    Discussion

    To speak the text, the utterance must be passed to an instance of AVSpeechSynthesizer.

    Import Statement

    Objective-C

    @import AVFoundation;

    Availability

    Available in iOS 7.0 and later

  • The baseline pitch at which the utterance will be spoken.

    Declaration

    Swift

    var pitchMultiplier: Float

    Objective-C

    @property(nonatomic) float pitchMultiplier

    Discussion

    The default pitch is 1.0. Allowed values are in the range from 0.5 (for lower pitch) to 2.0 (for higher pitch).

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • The amount of time a speech synthesizer will wait after the utterance is spoken before handling the next queued utterance.

    Declaration

    Swift

    var postUtteranceDelay: NSTimeInterval

    Objective-C

    @property(nonatomic) NSTimeInterval postUtteranceDelay

    Discussion

    When two or more utterances are spoken by an instance of AVSpeechSynthesizer, the time between periods when either is audible will be at least the sum of the first utterance’s postUtteranceDelay and the second utterance’s preUtteranceDelay.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • The amount of time a speech synthesizer will wait before actually speaking the utterance upon beginning to handle it.

    Declaration

    Swift

    var preUtteranceDelay: NSTimeInterval

    Objective-C

    @property(nonatomic) NSTimeInterval preUtteranceDelay

    Discussion

    When two or more utterances are spoken by an instance of AVSpeechSynthesizer, the time between periods when either is audible will be at least the sum of the first utterance’s postUtteranceDelay and the second utterance’s preUtteranceDelay.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • rate rate Property

    The rate at which the utterance will be spoken.

    Declaration

    Swift

    var rate: Float

    Objective-C

    @property(nonatomic) float rate

    Discussion

    Speech rates are values in the range between AVSpeechUtteranceMinimumSpeechRate and AVSpeechUtteranceMaximumSpeechRate. Lower values correspond to slower speech, and vice versa. The default value is AVSpeechUtteranceDefaultSpeechRate.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • The text to be spoken in the utterance. (read-only)

    Declaration

    Swift

    var speechString: String! { get }

    Objective-C

    @property(nonatomic, readonly) NSString *speechString

    Discussion

    An utterance’s text cannot be changed once it is created. To speak different text, create a new utterance.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • voice voice Property

    The voice used to speak the utterance.

    Declaration

    Swift

    var voice: AVSpeechSynthesisVoice!

    Objective-C

    @property(nonatomic, retain) AVSpeechSynthesisVoice *voice

    Discussion

    The default value is nil, which causes the utterance to be spoken in the default voice.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • volume volume Property

    The volume used when speaking the utterance.

    Declaration

    Swift

    var volume: Float

    Objective-C

    @property(nonatomic) float volume

    Discussion

    Allowed values are in the range from 0.0 (silent) to 1.0 (loudest). The default volume is 1.0.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 7.0 and later

  • Allowed rates for synthesized speech.

    Declaration

    Swift

    let AVSpeechUtteranceMinimumSpeechRate: Float let AVSpeechUtteranceMaximumSpeechRate: Float let AVSpeechUtteranceDefaultSpeechRate: Float

    Objective-C

    const float AVSpeechUtteranceMinimumSpeechRate; const float AVSpeechUtteranceMaximumSpeechRate; const float AVSpeechUtteranceDefaultSpeechRate;

    Constants

    • AVSpeechUtteranceMinimumSpeechRate

      AVSpeechUtteranceMinimumSpeechRate

      The minimum allowed speech rate.

      Available in iOS 7.0 and later

    • AVSpeechUtteranceMaximumSpeechRate

      AVSpeechUtteranceMaximumSpeechRate

      The maximum allowed speech rate.

      Available in iOS 7.0 and later

    • AVSpeechUtteranceDefaultSpeechRate

      AVSpeechUtteranceDefaultSpeechRate

      The default rate at which an utterance is spoken unless its rate property is changed.

      Available in iOS 7.0 and later