AWSPolly Class Reference

Inherits from AWSService : NSObject
Declared in AWSPollyService.h
AWSPollyService.m

Overview

Amazon Polly is a web service that makes it easy to synthesize speech from text.

The Amazon Polly service provides API operations for synthesizing high-quality speech from plain text and Speech Synthesis Markup Language (SSML), along with managing pronunciations lexicons that enable you to get the best results for your application domain.

  configuration

The service configuration used to instantiate this service client.

@property (nonatomic, strong, readonly) AWSServiceConfiguration *configuration

Discussion

Warning: Once the client is instantiated, do not modify the configuration object. It may cause unspecified behaviors.

Declared In

AWSPollyService.h

+ defaultPolly

Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with defaultServiceConfiguration from [AWSServiceManager defaultServiceManager]. The reference to this object is maintained by the SDK, and you do not need to retain it manually.

+ (instancetype)defaultPolly

Return Value

The default service client.

Discussion

For example, set the default service configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
    let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
    AWSServiceManager.default().defaultServiceConfiguration = configuration

    return true
}

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                      identityPoolId:@"YourIdentityPoolId"];
      AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
                                                                           credentialsProvider:credentialsProvider];
      [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

      return YES;
  }

Then call the following to get the default service client:

Swift

 let Polly = AWSPolly.default()

Objective-C

 AWSPolly *Polly = [AWSPolly defaultPolly];

Declared In

AWSPollyService.h

+ registerPollyWithConfiguration:forKey:

Creates a service client with the given service configuration and registers it for the key.

+ (void)registerPollyWithConfiguration:(AWSServiceConfiguration *)configuration forKey:(NSString *)key

Parameters

configuration

A service configuration object.

key

A string to identify the service client.

Discussion

For example, set the default service configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
    let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
    AWSPolly.register(with: configuration!, forKey: "USWest2Polly")

    return true
}

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                     identityPoolId:@"YourIdentityPoolId"];
     AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                          credentialsProvider:credentialsProvider];

     [AWSPolly registerPollyWithConfiguration:configuration forKey:@"USWest2Polly"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let Polly = AWSPolly(forKey: "USWest2Polly")

Objective-C

 AWSPolly *Polly = [AWSPolly PollyForKey:@"USWest2Polly"];

Warning: After calling this method, do not modify the configuration object. It may cause unspecified behaviors.

Declared In

AWSPollyService.h

+ PollyForKey:

Retrieves the service client associated with the key. You need to call + registerPollyWithConfiguration:forKey: before invoking this method.

+ (instancetype)PollyForKey:(NSString *)key

Parameters

key

A string to identify the service client.

Return Value

An instance of the service client.

Discussion

For example, set the default service configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
    let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
    AWSPolly.register(with: configuration!, forKey: "USWest2Polly")

    return true
}

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                     identityPoolId:@"YourIdentityPoolId"];
     AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                          credentialsProvider:credentialsProvider];

     [AWSPolly registerPollyWithConfiguration:configuration forKey:@"USWest2Polly"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let Polly = AWSPolly(forKey: "USWest2Polly")

Objective-C

 AWSPolly *Polly = [AWSPolly PollyForKey:@"USWest2Polly"];

Declared In

AWSPollyService.h

+ removePollyForKey:

Removes the service client associated with the key and release it.

+ (void)removePollyForKey:(NSString *)key

Parameters

key

A string to identify the service client.

Discussion

Warning: Before calling this method, make sure no method is running on this client.

Declared In

AWSPollyService.h

– deleteLexicon:

Deletes the specified pronunciation lexicon stored in an AWS Region. A lexicon which has been deleted is not available for speech synthesis, nor is it possible to retrieve it using either the GetLexicon or ListLexicon APIs.

For more information, see Managing Lexicons.

- (AWSTask<AWSPollyDeleteLexiconOutput*> *)deleteLexicon:(AWSPollyDeleteLexiconInput *)request

Parameters

request

A container for the necessary parameters to execute the DeleteLexicon service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSPollyDeleteLexiconOutput. On failed execution, task.error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorLexiconNotFound, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– deleteLexicon:completionHandler:

Deletes the specified pronunciation lexicon stored in an AWS Region. A lexicon which has been deleted is not available for speech synthesis, nor is it possible to retrieve it using either the GetLexicon or ListLexicon APIs.

For more information, see Managing Lexicons.

- (void)deleteLexicon:(AWSPollyDeleteLexiconInput *)request completionHandler:(void ( ^ _Nullable ) ( AWSPollyDeleteLexiconOutput *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the DeleteLexicon service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorLexiconNotFound, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– describeVoices:

Returns the list of voices that are available for use when requesting speech synthesis. Each voice speaks a specified language, is either male or female, and is identified by an ID, which is the ASCII version of the voice name.

When synthesizing speech ( SynthesizeSpeech ), you provide the voice ID for the voice you want from the list of voices returned by DescribeVoices.

For example, you want your news reader application to read news in a specific language, but giving a user the option to choose the voice. Using the DescribeVoices operation you can provide the user with a list of available voices to select from.

You can optionally specify a language code to filter the available voices. For example, if you specify en-US, the operation returns a list of all available US English voices.

This operation requires permissions to perform the polly:DescribeVoices action.

- (AWSTask<AWSPollyDescribeVoicesOutput*> *)describeVoices:(AWSPollyDescribeVoicesInput *)request

Parameters

request

A container for the necessary parameters to execute the DescribeVoices service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSPollyDescribeVoicesOutput. On failed execution, task.error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorInvalidNextToken, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– describeVoices:completionHandler:

Returns the list of voices that are available for use when requesting speech synthesis. Each voice speaks a specified language, is either male or female, and is identified by an ID, which is the ASCII version of the voice name.

When synthesizing speech ( SynthesizeSpeech ), you provide the voice ID for the voice you want from the list of voices returned by DescribeVoices.

For example, you want your news reader application to read news in a specific language, but giving a user the option to choose the voice. Using the DescribeVoices operation you can provide the user with a list of available voices to select from.

You can optionally specify a language code to filter the available voices. For example, if you specify en-US, the operation returns a list of all available US English voices.

This operation requires permissions to perform the polly:DescribeVoices action.

- (void)describeVoices:(AWSPollyDescribeVoicesInput *)request completionHandler:(void ( ^ _Nullable ) ( AWSPollyDescribeVoicesOutput *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the DescribeVoices service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorInvalidNextToken, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– getLexicon:

Returns the content of the specified pronunciation lexicon stored in an AWS Region. For more information, see Managing Lexicons.

- (AWSTask<AWSPollyGetLexiconOutput*> *)getLexicon:(AWSPollyGetLexiconInput *)request

Parameters

request

A container for the necessary parameters to execute the GetLexicon service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSPollyGetLexiconOutput. On failed execution, task.error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorLexiconNotFound, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– getLexicon:completionHandler:

Returns the content of the specified pronunciation lexicon stored in an AWS Region. For more information, see Managing Lexicons.

- (void)getLexicon:(AWSPollyGetLexiconInput *)request completionHandler:(void ( ^ _Nullable ) ( AWSPollyGetLexiconOutput *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the GetLexicon service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorLexiconNotFound, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– listLexicons:

Returns a list of pronunciation lexicons stored in an AWS Region. For more information, see Managing Lexicons.

- (AWSTask<AWSPollyListLexiconsOutput*> *)listLexicons:(AWSPollyListLexiconsInput *)request

Parameters

request

A container for the necessary parameters to execute the ListLexicons service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSPollyListLexiconsOutput. On failed execution, task.error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorInvalidNextToken, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– listLexicons:completionHandler:

Returns a list of pronunciation lexicons stored in an AWS Region. For more information, see Managing Lexicons.

- (void)listLexicons:(AWSPollyListLexiconsInput *)request completionHandler:(void ( ^ _Nullable ) ( AWSPollyListLexiconsOutput *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the ListLexicons service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorInvalidNextToken, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– putLexicon:

Stores a pronunciation lexicon in an AWS Region. If a lexicon with the same name already exists in the region, it is overwritten by the new lexicon. Lexicon operations have eventual consistency, therefore, it might take some time before the lexicon is available to the SynthesizeSpeech operation.

For more information, see Managing Lexicons.

- (AWSTask<AWSPollyPutLexiconOutput*> *)putLexicon:(AWSPollyPutLexiconInput *)request

Parameters

request

A container for the necessary parameters to execute the PutLexicon service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSPollyPutLexiconOutput. On failed execution, task.error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorInvalidLexicon, AWSPollyErrorUnsupportedPlsAlphabet, AWSPollyErrorUnsupportedPlsLanguage, AWSPollyErrorLexiconSizeExceeded, AWSPollyErrorMaxLexemeLengthExceeded, AWSPollyErrorMaxLexiconsNumberExceeded, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– putLexicon:completionHandler:

Stores a pronunciation lexicon in an AWS Region. If a lexicon with the same name already exists in the region, it is overwritten by the new lexicon. Lexicon operations have eventual consistency, therefore, it might take some time before the lexicon is available to the SynthesizeSpeech operation.

For more information, see Managing Lexicons.

- (void)putLexicon:(AWSPollyPutLexiconInput *)request completionHandler:(void ( ^ _Nullable ) ( AWSPollyPutLexiconOutput *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the PutLexicon service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorInvalidLexicon, AWSPollyErrorUnsupportedPlsAlphabet, AWSPollyErrorUnsupportedPlsLanguage, AWSPollyErrorLexiconSizeExceeded, AWSPollyErrorMaxLexemeLengthExceeded, AWSPollyErrorMaxLexiconsNumberExceeded, AWSPollyErrorServiceFailure.

Declared In

AWSPollyService.h

– synthesizeSpeech:

Synthesizes UTF-8 input, plain text or SSML, to a stream of bytes. SSML input must be valid, well-formed SSML. Some alphabets might not be available with all the voices (for example, Cyrillic might not be read at all by English voices) unless phoneme mapping is used. For more information, see How it Works.

- (AWSTask<AWSPollySynthesizeSpeechOutput*> *)synthesizeSpeech:(AWSPollySynthesizeSpeechInput *)request

Parameters

request

A container for the necessary parameters to execute the SynthesizeSpeech service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSPollySynthesizeSpeechOutput. On failed execution, task.error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorTextLengthExceeded, AWSPollyErrorInvalidSampleRate, AWSPollyErrorInvalidSsml, AWSPollyErrorLexiconNotFound, AWSPollyErrorServiceFailure, AWSPollyErrorMarksNotSupportedForFormat, AWSPollyErrorSsmlMarksNotSupportedForTextType.

Declared In

AWSPollyService.h

– synthesizeSpeech:completionHandler:

Synthesizes UTF-8 input, plain text or SSML, to a stream of bytes. SSML input must be valid, well-formed SSML. Some alphabets might not be available with all the voices (for example, Cyrillic might not be read at all by English voices) unless phoneme mapping is used. For more information, see How it Works.

- (void)synthesizeSpeech:(AWSPollySynthesizeSpeechInput *)request completionHandler:(void ( ^ _Nullable ) ( AWSPollySynthesizeSpeechOutput *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the SynthesizeSpeech service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSPollyErrorDomain domain and the following error code: AWSPollyErrorTextLengthExceeded, AWSPollyErrorInvalidSampleRate, AWSPollyErrorInvalidSsml, AWSPollyErrorLexiconNotFound, AWSPollyErrorServiceFailure, AWSPollyErrorMarksNotSupportedForFormat, AWSPollyErrorSsmlMarksNotSupportedForTextType.

Declared In

AWSPollyService.h