Partilhar via


Class SPXSpeechSynthesizer

Declaration

@class SPXSpeechSynthesizer : NSObject;

Description

Performs speech synthesis from a text to a specified audio output.

Updated in version 1.16.0

Methods

init:

Initializes a new instance of speech synthesizer using a speech config. This synthesizer will output the audio to default speaker, which will throw an exception if the speaker is not available. Please use initWithSpeechConfiguration(speechConfiguration, nil) if you just need the SPXSynthesisResult or SPXAudioDataStream.

- (instancetype _Nullable)init:(SPXSpeechConfiguration * _Nonnull)speechConfiguration

Parameters

  • speechConfiguration - speech configuration.

Returns

an instance of speech synthesizer.

init:error:

Initializes a new instance of speech synthesizer using a speech config. This synthesizer will output the audio to default speaker, which will throw an exception if the speaker is not available. Please use initWithSpeechConfiguration(speechConfiguration, nil) if you just need the SPXSynthesisResult or SPXAudioDataStream.

- (instancetype _Nullable)init:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech configuration.
  • outError - error information.

Returns

an instance of speech synthesizer.

initWithSpeechConfiguration:audioConfiguration:

Initializes a new instance of speech synthesizer using a speech config and audio config.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nullable)audioConfiguration

Parameters

  • speechConfiguration - speech configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of speech synthesizer.

initWithSpeechConfiguration:audioConfiguration:error:

Initializes a new instance of speech synthesizer using a speech config and audio config.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nullable)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech synthesizer.

initWithEmbeddedSpeechConfiguration:

Initializes a new instance of speech synthesizer using a embedded speech config. This synthesizer will output the audio to default speaker, which will throw an exception if the speaker is not available. Please use initWithEmbeddedSpeechConfiguration(speechConfiguration, nil) if you just need the SPXSynthesisResult or SPXAudioDataStream.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration

Parameters

  • speechConfiguration - embedded speech configuration.

Returns

an instance of speech synthesizer.

initWithEmbeddedSpeechConfiguration:error:

Initializes a new instance of speech synthesizer using a embedded speech config. This synthesizer will output the audio to default speaker, which will throw an exception if the speaker is not available. Please use initWithEmbeddedSpeechConfiguration(speechConfiguration, nil) if you just need the SPXSynthesisResult or SPXAudioDataStream.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - embedded speech configuration.
  • outError - error information.

Returns

an instance of speech synthesizer.

initWithEmbeddedSpeechConfiguration:audioConfiguration:

Initializes a new instance of speech synthesizer using a embedded speech config and audio config.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nullable)audioConfiguration

Parameters

  • speechConfiguration - embedded speech configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of speech synthesizer.

initWithEmbeddedSpeechConfiguration:audioConfiguration:error:

Initializes a new instance of speech synthesizer using a embedded speech config and audio config.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nullable)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - embedded speech configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech synthesizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:

Initializes a new instance of speech synthesizer using the specified configuration for auto language detection.

Added in version 1.13.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.

Returns

an instance of speech synthesizer

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:error:

Initializes a new instance of speech synthesizer using the specified configuration for auto language detection.

Added in version 1.13.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • outError - error information.

Returns

an instance of speech synthesizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:audioConfiguration:

Initializes a new instance of speech synthesizer using the specified configuration for auto language detection and audio configuration.

Added in version 1.13.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nullable)audioConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • audioConfiguration - audio configuration.

Returns

an instance of speech synthesizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:audioConfiguration:error:

Initializes a new instance of speech synthesizer using the specified configuration for auto language detection and audio configuration.

Added in version 1.13.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nullable)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech synthesizer.

speakText:

Execute the speech synthesis on plain text.

- (SPXSpeechSynthesisResult * _Nonnull)speakText:(NSString * _Nonnull)text

Parameters

  • text - the plain text for synthesis.

Returns

the result of speech synthesis.

speakText:error:

Execute the speech synthesis on plain text.

- (SPXSpeechSynthesisResult * _Nullable)speakText:(NSString * _Nonnull)text
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • text - the plain text for synthesis.
  • outError - error information.

Returns

the result of speech synthesis.

speakSsml:

Execute the speech synthesis on SSML.

- (SPXSpeechSynthesisResult * _Nonnull)speakSsml:(NSString * _Nonnull)ssml

Parameters

  • ssml - the SSML for synthesis.

Returns

the result of speech synthesis.

speakSsml:error:

Execute the speech synthesis on SSML.

- (SPXSpeechSynthesisResult * _Nullable)speakSsml:(NSString * _Nonnull)ssml
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • ssml - the SSML for synthesis.
  • outError - error information.

Returns

the result of speech synthesis.

startSpeakingText:

Start the speech synthesis on plain text.

- (SPXSpeechSynthesisResult * _Nonnull)startSpeakingText:(NSString * _Nonnull)text

Parameters

  • text - the plain the for synthesis.

Returns

the result of speech synthesis.

startSpeakingText:error:

Start the speech synthesis on plain text.

- (SPXSpeechSynthesisResult * _Nullable)startSpeakingText:(NSString * _Nonnull)text
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • text - the plain text for synthesis.
  • outError - error information.

Returns

the result of speech synthesis.

startSpeakingSsml:

Start the speech synthesis on SSML.

- (SPXSpeechSynthesisResult * _Nonnull)startSpeakingSsml:(NSString * _Nonnull)ssml

Parameters

  • ssml - the SSML for synthesis.

Returns

the result of speech synthesis.

startSpeakingSsml:error:

Start the speech synthesis on SSML.

- (SPXSpeechSynthesisResult * _Nullable)startSpeakingSsml:(NSString * _Nonnull)ssml
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • ssml - the SSML for synthesis.
  • outError - error information.

Returns

the result of speech synthesis.

stopSpeaking

Stops synthesis. This method will stop the playback and clear the unread data in SPXPullAudioOutputStream

Added in version 1.14.0

- (void)stopSpeaking

stopSpeaking:

Stops synthesis. This method will stop the playback and clear the unread data in SPXPullAudioOutputStream

Added in version 1.14.0

- (BOOL)stopSpeaking:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.

getVoicesWithLocale:

Get the available voices.

Added in version 1.16.0

- (SPXSynthesisVoicesResult * _Nonnull)getVoicesWithLocale:(NSString * _Nonnull)locale

Parameters

  • locale - Specify the locale of voices, in BCP-47 format; or leave it empty to get all available voices.

Returns

the result of voices retrieved.

getVoicesWithLocale:error:

Get the available voices.

Added in version 1.16.0

- (SPXSynthesisVoicesResult * _Nullable)getVoicesWithLocale:(NSString * _Nonnull)locale
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • locale - Specify the locale of voices, in BCP-47 format; or leave it empty to get all available voices.
  • outError - error information.

Returns

the result of voices retrieved.

getVoices

Get the available voices in all locales.

Added in version 1.16.0

- (SPXSynthesisVoicesResult * _Nonnull)getVoices

Returns

the result of voices retrieved.

getVoices:

Get the available voices in all locales.

Added in version 1.16.0

- (SPXSynthesisVoicesResult * _Nullable)getVoices:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.

Returns

the result of voices retrieved.

addSynthesisStartedEventHandler:

Subscribes to the SynthesisStarted event which indicates that the synthesis just started.

- (void)addSynthesisStartedEventHandler:(SPXSpeechSynthesisEventHandler _Nonnull)eventHandler

addSynthesizingEventHandler:

Subscribes to the Synthesizing event which indicates that the synthesis is on going.

- (void)addSynthesizingEventHandler:(SPXSpeechSynthesisEventHandler _Nonnull)eventHandler

addSynthesisCompletedEventHandler:

Subscribes to the SynthesisCompleted event which indicates that the synthesis completed.

- (void)addSynthesisCompletedEventHandler:(SPXSpeechSynthesisEventHandler _Nonnull)eventHandler

addSynthesisCanceledEventHandler:

Subscribes to the SynthesisCanceled event which indicates that the synthesis is canceled.

- (void)addSynthesisCanceledEventHandler:(SPXSpeechSynthesisEventHandler _Nonnull)eventHandler

addSynthesisWordBoundaryEventHandler:

Subscribes to the SynthesisWordBoundary event which indicates that a word boundary is received.

- (void)addSynthesisWordBoundaryEventHandler:(SPXSpeechSynthesisWordBoundaryEventHandler _Nonnull)eventHandler

addVisemeReceivedEventHandler:

Subscribes to the VisemeReceived event which indicates that a viseme is received.

- (void)addVisemeReceivedEventHandler:(SPXSpeechSynthesisVisemeEventHandler _Nonnull)eventHandler

addBookmarkReachedEventHandler:

Subscribes to the BookmarkReached event which indicates that a bookmark is reached.

- (void)addBookmarkReachedEventHandler:(SPXSpeechSynthesisBookmarkEventHandler _Nonnull)eventHandler

Properties

properties

@property (readonly, atomic) id<SPXPropertyCollection> _Nullable properties;

The collection of properties and their values defined for this SPXSpeechSynthesizer.

authorizationToken

@property (readwrite, copy, nonatomic) NSString * _Nullable authorizationToken;

Authorization token used to communicate with the speech synthesis service.

Note: The caller needs to ensure that the authorization token is valid. Before the authorization token expires, the caller needs to refresh it by calling this setter with a new valid token. Otherwise, the synthesizer will encounter errors during speech synthesis.