Mac Developer Library

Developer

AppKit Framework Reference NSSpeechSynthesizerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSSpeechSynthesizerDelegate

Inheritance


Not Applicable

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.6 and later.

The NSSpeechSynthesizerDelegate protocol defines the optional methods implemented by delegates of NSSpeechSynthesizer objects.

  • Sent just before a synthesized word is spoken through the sound output device.

    Declaration

    Swift

    optional func speechSynthesizer(_ sender: NSSpeechSynthesizer, willSpeakWord wordToSpeak: NSRange, ofString text: String)

    Objective-C

    - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakWord:(NSRange)wordToSpeak ofString:(NSString *)text

    Parameters

    sender

    An NSSpeechSynthesizer object that’s synthesizing text into speech.

    wordToSpeak

    Word that sender is about to speak into the sound output device.

    text

    Text that is being synthesized by sender.

    Discussion

    One use of this method might be to visually highlight the word being spoken.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    startSpeakingString: (NSSpeechSynthesizer)

  • Sent just before a synthesized phoneme is spoken through the sound output device.

    Declaration

    Swift

    optional func speechSynthesizer(_ sender: NSSpeechSynthesizer, willSpeakPhoneme phonemeOpcode: Int16)

    Objective-C

    - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakPhoneme:(short)phonemeOpcode

    Parameters

    sender

    An NSSpeechSynthesizer object that’s synthesizing text into speech.

    phonemeOpcode

    Phoneme that sender is about to speak into the sound output device.

    Discussion

    One use of this method might be to animate a mouth on screen to match the generated speech.

    Special Considerations

    This method is not sent for modern voices. It is only supported for MacinTalk voices.

    In OS X v10.4 and earlier, the delegate is not sent this message when the NSSpeechSynthesizer object is synthesizing speech to a file (startSpeakingString:toURL:).

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    startSpeakingString: (NSSpeechSynthesizer)

  • Sent to the delegate when a speech synthesizer encounters an error in text being synthesized.

    Declaration

    Swift

    optional func speechSynthesizer(_ sender: NSSpeechSynthesizer, didEncounterErrorAtIndex characterIndex: Int, ofString text: String, message errorMessage: String)

    Objective-C

    - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didEncounterErrorAtIndex:(NSUInteger)characterIndex ofString:(NSString *)text message:(NSString *)errorMessage

    Parameters

    sender

    Speech synthesizer informing its delegate of an error.

    characterIndex

    Location in text where the receiver encountered the error.

    text

    Text the receiver was synthesizing when the error occurred.

    errorMessage

    Error message.

    Discussion

    The synthesizer sends an error delegate message whenever it encounters a syntax error within a command embedded in the string it is processing. This can be useful during application debugging, to detect problems with commands that you have embedded in strings that your application speaks. It can also be useful if your application allows users to embed commands within strings. Your application might display an alert indicating that the synthesizer encountered a problem in processing an embedded command.

    If your application needs information about errors that occurred prior to calling your error delegate method, the application (including the error delegate method) can call the sender’s objectForProperty:error: method with the NSSpeechErrorsProperty constant.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent to the delegate when a speech synthesizer encounters a synchronization error.

    Declaration

    Swift

    optional func speechSynthesizer(_ sender: NSSpeechSynthesizer, didEncounterSyncMessage errorMessage: String)

    Objective-C

    - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didEncounterSyncMessage:(NSString *)errorMessage

    Parameters

    sender

    Speech synthesizer informing its delegate of an error.

    errorMessage

    Error message.

    Discussion

    The synthesizer calls your synchronization delegate method whenever it encounters a synchronization command embedded in a string. You might use the synchronization delegate method to provide a callback not ordinarily provided.

    For example, you might insert synchronization commands at the end of every sentence in a string, or you might enter synchronization commands after every numeric value in the text.

    However, to synchronize your application with phonemes or words, it makes more sense to use the built-in phoneme and word delegate methods: speechSynthesizer:willSpeakPhoneme: and speechSynthesizer:willSpeakWord:ofString:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent when an NSSpeechSynthesizer object finishes speaking through the sound output device.

    Declaration

    Swift

    optional func speechSynthesizer(_ sender: NSSpeechSynthesizer, didFinishSpeaking success: Bool)

    Objective-C

    - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)success

    Parameters

    sender

    An NSSpeechSynthesizer object that has stopped speaking into the sound output device.

    success

    YEStrue when speaking completed normally, NOfalse if speaking is stopped prematurely for any reason.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    startSpeakingString: (NSSpeechSynthesizer)
    stopSpeaking (NSSpeechSynthesizer)