NSSpeechSynthesizerDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.6 and later.
Companion guide
Declared in
NSSpeechSynthesizer.h

Overview

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

Tasks

Synthesizing Speech

Instance Methods

speechSynthesizer:didEncounterErrorAtIndex:ofString:message:

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

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didEncounterErrorAtIndex:(NSUInteger)characterIndex ofString:(NSString *)string message:(NSString *)message
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.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpeechSynthesizer.h

speechSynthesizer:didEncounterSyncMessage:

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

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didEncounterSyncMessage:(NSString *)message
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:.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpeechSynthesizer.h

speechSynthesizer:didFinishSpeaking:

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

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

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

success

YES when speaking completed normally, NO if speaking is stopped prematurely for any reason.

Availability
  • Available in OS X v10.3 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSSpeechSynthesizer.h

speechSynthesizer:willSpeakPhoneme:

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

- (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:).

Availability
  • Available in OS X v10.3 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSSpeechSynthesizer.h

speechSynthesizer:willSpeakWord:ofString:

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

- (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.

Availability
  • Available in OS X v10.3 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSSpeechSynthesizer.h