AWS Polly
Since Camel 4.18
Only producer is supported
The AWS2 Polly component supports text-to-speech synthesis using the AWS Polly service. AWS Polly is a cloud service that converts text into lifelike speech.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Polly. More information is available at Amazon Polly.
URI Format
aws2-polly://label[?options]
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS Polly component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The configuration that the endpoints of this component start from. Each endpoint gets a copy of it, and the options of the endpoint replace its values. | Polly2Configuration | ||
The engine that synthesizes the speech: standard, neural, long-form or generative. The voice must support it. For synthesizeSpeech and startSpeechSynthesisTask, Amazon Polly uses the standard engine when neither this option nor the CamelAwsPollyEngine header is set; for describeVoices it only lists the voices that support this engine. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| Engine | ||
A language code such as en-US or hi-IN. For synthesizeSpeech and startSpeechSynthesisTask, it selects the language of a bilingual voice, such as Aditi for en-IN or hi-IN, and if not set the voice speaks its default language; for describeVoices, it only lists the voices of this language. The CamelAwsPollyLanguageCode header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The pronunciation lexicon that putLexicon stores, as a PLS (Pronunciation Lexicon Specification) XML document. A lexicon with the same name in the region is replaced. When neither this option nor the CamelAwsPollyLexiconContent header is set, the body is used. It is not used when pojoRequest is true. | String | ||
The name of the pronunciation lexicon for getLexicon, putLexicon and deleteLexicon, which fail when neither this option nor the CamelAwsPollyLexiconName header is set. The name is a case-sensitive alphanumeric string of up to 20 characters. The header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
A comma-separated list of up to 5 names of pronunciation lexicons, stored with putLexicon, that Amazon Polly applies during synthesizeSpeech and startSpeechSynthesisTask. A lexicon applies only when its language is the language of the voice. The CamelAwsPollyLexiconNames header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
Required The operation that the producer performs. The CamelAwsPollyOperation header replaces this option. Enum values:
| synthesizeSpeech | Polly2Operations | |
The format of the output of synthesizeSpeech and startSpeechSynthesisTask: mp3, ogg_vorbis, ogg_opus, pcm (signed 16-bit, mono, little-endian), mulaw or alaw for audio, or json for speech marks. The component cannot set the speech mark types that json needs, so use a request of the AWS SDK with pojoRequest=true for speech marks. When neither this option nor the CamelAwsPollyOutputFormat header is set, mp3 is used. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| OutputFormat | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the body is the request of the AWS SDK for the operation, such as a SynthesizeSpeechRequest for synthesizeSpeech. If true, the producer sends that request as it is, without the options and headers of the operation, and a body of another type fails. Use it for the request fields that the component does not set, such as the speech mark types. If false, the producer builds the request from the options, the headers and the body. | false | boolean | |
The AWS region of Amazon Polly, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. Lexicons and speech synthesis tasks are kept per region, and Amazon Polly is not available in every region. Enum values:
| String | ||
The name of the Amazon S3 bucket in which startSpeechSynthesisTask stores the output file, which fails when neither this option nor the CamelAwsPollyS3Bucket header is set. The header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The prefix of the Amazon S3 key of the output file of startSpeechSynthesisTask, to which Amazon Polly adds the task ID and the file extension: the output URI of the returned task gives the full location. The CamelAwsPollyS3KeyPrefix header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The sample rate of the audio in Hz, as a string, for synthesizeSpeech and startSpeechSynthesisTask: 8000, 16000, 22050 or 24000 for mp3 and ogg_vorbis (also 44100 and 48000 for synthesizeSpeech), 8000 or 16000 for pcm, 48000 for ogg_opus and 8000 for mulaw and alaw. If not set, Amazon Polly uses 22050 for the standard engine and 24000 for the other engines with mp3 and ogg_vorbis, and 16000 with pcm. The CamelAwsPollySampleRate header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The ARN of the Amazon SNS topic to which Amazon Polly sends the status notifications of a task of startSpeechSynthesisTask. If not set, no notification is sent. The CamelAwsPollySnsTopicArn header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The ID of the speech synthesis task to get with getSpeechSynthesisTask, which fails when neither this option nor the CamelAwsPollyTaskId header is set. startSpeechSynthesisTask sets that header, but this option, when set, is used instead of it. Amazon Polly keeps a task for 72 hours. It is not used when pojoRequest is true. | String | ||
Whether the text of the body is plain text (text) or SSML (ssml), for synthesizeSpeech and startSpeechSynthesisTask. SSML must be valid, well-formed SSML in a speak element. When neither this option nor the CamelAwsPollyTextType header is set, text is used. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| TextType | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The ID of the voice that speaks the text, such as Joanna or Matthew, for synthesizeSpeech and startSpeechSynthesisTask, which fail when neither this option nor the CamelAwsPollyVoiceId header is set. The voice must support the engine of the request: describeVoices lists the voices and their engines. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| VoiceId | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Autowired To use a custom software.amazon.awssdk.services.polly.PollyClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | PollyClient | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy that the HTTP client of Amazon Polly connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon Polly connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon Polly uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless pollyClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless pollyClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the HTTP client of Amazon Polly trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS Polly endpoint is configured using URI syntax:
aws2-polly:label
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The engine that synthesizes the speech: standard, neural, long-form or generative. The voice must support it. For synthesizeSpeech and startSpeechSynthesisTask, Amazon Polly uses the standard engine when neither this option nor the CamelAwsPollyEngine header is set; for describeVoices it only lists the voices that support this engine. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| Engine | ||
A language code such as en-US or hi-IN. For synthesizeSpeech and startSpeechSynthesisTask, it selects the language of a bilingual voice, such as Aditi for en-IN or hi-IN, and if not set the voice speaks its default language; for describeVoices, it only lists the voices of this language. The CamelAwsPollyLanguageCode header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The pronunciation lexicon that putLexicon stores, as a PLS (Pronunciation Lexicon Specification) XML document. A lexicon with the same name in the region is replaced. When neither this option nor the CamelAwsPollyLexiconContent header is set, the body is used. It is not used when pojoRequest is true. | String | ||
The name of the pronunciation lexicon for getLexicon, putLexicon and deleteLexicon, which fail when neither this option nor the CamelAwsPollyLexiconName header is set. The name is a case-sensitive alphanumeric string of up to 20 characters. The header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
A comma-separated list of up to 5 names of pronunciation lexicons, stored with putLexicon, that Amazon Polly applies during synthesizeSpeech and startSpeechSynthesisTask. A lexicon applies only when its language is the language of the voice. The CamelAwsPollyLexiconNames header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
Required The operation that the producer performs. The CamelAwsPollyOperation header replaces this option. Enum values:
| synthesizeSpeech | Polly2Operations | |
The format of the output of synthesizeSpeech and startSpeechSynthesisTask: mp3, ogg_vorbis, ogg_opus, pcm (signed 16-bit, mono, little-endian), mulaw or alaw for audio, or json for speech marks. The component cannot set the speech mark types that json needs, so use a request of the AWS SDK with pojoRequest=true for speech marks. When neither this option nor the CamelAwsPollyOutputFormat header is set, mp3 is used. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| OutputFormat | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the body is the request of the AWS SDK for the operation, such as a SynthesizeSpeechRequest for synthesizeSpeech. If true, the producer sends that request as it is, without the options and headers of the operation, and a body of another type fails. Use it for the request fields that the component does not set, such as the speech mark types. If false, the producer builds the request from the options, the headers and the body. | false | boolean | |
The AWS region of Amazon Polly, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. Lexicons and speech synthesis tasks are kept per region, and Amazon Polly is not available in every region. Enum values:
| String | ||
The name of the Amazon S3 bucket in which startSpeechSynthesisTask stores the output file, which fails when neither this option nor the CamelAwsPollyS3Bucket header is set. The header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The prefix of the Amazon S3 key of the output file of startSpeechSynthesisTask, to which Amazon Polly adds the task ID and the file extension: the output URI of the returned task gives the full location. The CamelAwsPollyS3KeyPrefix header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The sample rate of the audio in Hz, as a string, for synthesizeSpeech and startSpeechSynthesisTask: 8000, 16000, 22050 or 24000 for mp3 and ogg_vorbis (also 44100 and 48000 for synthesizeSpeech), 8000 or 16000 for pcm, 48000 for ogg_opus and 8000 for mulaw and alaw. If not set, Amazon Polly uses 22050 for the standard engine and 24000 for the other engines with mp3 and ogg_vorbis, and 16000 with pcm. The CamelAwsPollySampleRate header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The ARN of the Amazon SNS topic to which Amazon Polly sends the status notifications of a task of startSpeechSynthesisTask. If not set, no notification is sent. The CamelAwsPollySnsTopicArn header is used only when this option is not set, and neither is used when pojoRequest is true. | String | ||
The ID of the speech synthesis task to get with getSpeechSynthesisTask, which fails when neither this option nor the CamelAwsPollyTaskId header is set. startSpeechSynthesisTask sets that header, but this option, when set, is used instead of it. Amazon Polly keeps a task for 72 hours. It is not used when pojoRequest is true. | String | ||
Whether the text of the body is plain text (text) or SSML (ssml), for synthesizeSpeech and startSpeechSynthesisTask. SSML must be valid, well-formed SSML in a speak element. When neither this option nor the CamelAwsPollyTextType header is set, text is used. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| TextType | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The ID of the voice that speaks the text, such as Joanna or Matthew, for synthesizeSpeech and startSpeechSynthesisTask, which fail when neither this option nor the CamelAwsPollyVoiceId header is set. The voice must support the engine of the request: describeVoices lists the voices and their engines. The header is used only when this option is not set, and neither is used when pojoRequest is true. Enum values:
| VoiceId | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.polly.PollyClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | PollyClient | ||
The host name of the proxy that the HTTP client of Amazon Polly connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon Polly connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon Polly uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless pollyClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless pollyClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the HTTP client of Amazon Polly trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS Polly component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsPollyOperation (producer) Constant: | The operation to perform. It replaces the operation option. | String | |
CamelAwsPollyVoiceId (producer) Constant: | The ID of the voice that speaks the text, such as Joanna, for synthesizeSpeech and startSpeechSynthesisTask. It is used only when the voiceId option is not set. Enum values:
| VoiceId | |
CamelAwsPollyOutputFormat (producer) Constant: | The output format of synthesizeSpeech and startSpeechSynthesisTask: mp3, ogg_vorbis, ogg_opus, pcm, mulaw, alaw, or json for speech marks. It is used only when the outputFormat option is not set; when neither is set, mp3 is used. Enum values:
| OutputFormat | |
CamelAwsPollyTextType (producer) Constant: | Whether the text of the body is plain text (text) or SSML (ssml), for synthesizeSpeech and startSpeechSynthesisTask. It is used only when the textType option is not set; when neither is set, text is used. Enum values:
| TextType | |
CamelAwsPollySampleRate (producer) Constant: | The sample rate of the audio in Hz, such as 16000, for synthesizeSpeech and startSpeechSynthesisTask. It is used only when the sampleRate option is not set. | String | |
CamelAwsPollyEngine (producer) Constant: | The engine: standard, neural, long-form or generative. It is the engine of synthesizeSpeech and startSpeechSynthesisTask, and the filter of describeVoices. It is used only when the engine option is not set. Enum values:
| Engine | |
CamelAwsPollyLanguageCode (producer) Constant: | A language code such as en-US: the language of a bilingual voice for synthesizeSpeech and startSpeechSynthesisTask, and the filter of describeVoices. It is used only when the languageCode option is not set. | String | |
CamelAwsPollyLexiconNames (producer) Constant: | A comma-separated list of up to 5 names of pronunciation lexicons to apply during synthesizeSpeech and startSpeechSynthesisTask. It is used only when the lexiconNames option is not set. | String | |
CamelAwsPollyLexiconName (producer) Constant: | The name of the pronunciation lexicon for getLexicon, putLexicon and deleteLexicon. It is used only when the lexiconName option is not set. | String | |
CamelAwsPollyLexiconContent (producer) Constant: | The pronunciation lexicon that putLexicon stores, as a PLS XML document. It is used only when the lexiconContent option is not set; when neither is set, the body is used. | String | |
CamelAwsPollyTaskId (producer) Constant: | The ID of a speech synthesis task. startSpeechSynthesisTask sets it to the ID of the task it started, and getSpeechSynthesisTask reads it when the taskId option is not set. | String | |
CamelAwsPollyS3Bucket (producer) Constant: | The name of the Amazon S3 bucket in which startSpeechSynthesisTask stores the output file. It is used only when the s3Bucket option is not set. | String | |
CamelAwsPollyS3KeyPrefix (producer) Constant: | The prefix of the Amazon S3 key of the output file of startSpeechSynthesisTask. It is used only when the s3KeyPrefix option is not set. | String | |
CamelAwsPollySnsTopicArn (producer) Constant: | The ARN of the Amazon SNS topic for the status notifications of a task of startSpeechSynthesisTask. It is used only when the snsTopicArn option is not set. | String | |
CamelAwsPollyContentType (producer) Constant: | The content type of the output that synthesizeSpeech returns, such as audio/mpeg for mp3, audio/ogg for ogg_vorbis and ogg_opus, audio/pcm for pcm, or application/x-json-stream for speech marks. | String | |
CamelAwsPollyRequestCharacters (producer) Constant: | The number of characters that Amazon Polly synthesized for synthesizeSpeech. | Integer | |
CamelAwsPollyNextToken (producer) Constant: | The token of the next page for the describeVoices, listLexicons and listSpeechSynthesisTasks operations. It is in and out: when set, it is sent as the next token of the request, and after the call it holds the next token of the response, or it is removed when the response has none, which is the last page. Remove it before calling a different list operation. | String |
Message Body
The message body at each side of the AWS Polly component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| The text to speak for synthesizeSpeech, the default, and startSpeechSynthesisTask: plain text, or SSML with textType=ssml. Bytes, a stream or a file are read as text, a Map or a POJO is spoken as its toString(), so take the text out of it first, and no body fails. putLexicon takes the lexicon from the body when neither the lexiconContent option nor the CamelAwsPollyLexiconContent header is set. The other operations do not use the body. With pojoRequest=true the request of the AWS SDK for the operation, such as a SynthesizeSpeechRequest: another body fails.
|
Producer output |
| The audio of synthesizeSpeech, the default, as a stream, with its content type and the number of characters in headers: read it once, or write it to a file. A List for describeVoices, listLexicons and listSpeechSynthesisTasks, the SynthesisTask for startSpeechSynthesisTask, with its id in a header, and getSpeechSynthesisTask, the Lexicon for getLexicon, and the response of the AWS SDK for putLexicon and deleteLexicon.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Required Polly component options
You have to provide the pollyClient in the Registry or your accessKey and secretKey to access the Amazon Polly service.
Usage
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Polly Producer operations
Camel-AWS Polly component provides the following operations on the producer side:
-
synthesizeSpeech
-
describeVoices
-
listLexicons
-
getLexicon
-
putLexicon
-
deleteLexicon
-
startSpeechSynthesisTask
-
getSpeechSynthesisTask
-
listSpeechSynthesisTasks
Text type and output format
The textType option, or else the CamelAwsPollyTextType header, says whether the text is plain text (TEXT) or SSML (SSML). The outputFormat option, or else the CamelAwsPollyOutputFormat header, sets the audio format. When neither the option nor the header is set, TEXT and MP3 are used. This applies to the synthesizeSpeech and startSpeechSynthesisTask operations.
The lexiconNames option, or else the CamelAwsPollyLexiconNames header, is a comma-separated list of lexicon names. The spaces around each name are removed, so a, b is the same as a,b.
Paging the list operations
The describeVoices, listLexicons and listSpeechSynthesisTasks operations return one page of results in the body. The CamelAwsPollyNextToken header is both an input and an output:
-
when it is set, it is sent as the next token of the request, so the call returns the next page;
-
after the call, it holds the next token of the response, or it is removed when the response has none, which means this was the last page.
A route can therefore call the operation again while the header is set. Because the header stays on the message, remove it before calling a different list operation, or that call starts from a token that is not its own.
-
Java
-
YAML
from("direct:start")
.to("aws2-polly://test?operation=listLexicons")
.log("Lexicons: ${body}")
.loopDoWhile(header(Polly2Constants.NEXT_TOKEN).isNotNull())
.to("aws2-polly://test?operation=listLexicons")
.log("Lexicons: ${body}")
.end()
.removeHeader(Polly2Constants.NEXT_TOKEN)
.to("aws2-polly://test?operation=describeVoices"); - route:
from:
uri: direct:start
steps:
- to:
uri: aws2-polly:test
parameters:
operation: listLexicons
- log:
message: "Lexicons: ${body}"
- loop:
doWhile: true
expression:
simple:
expression: "${header.CamelAwsPollyNextToken} != null"
steps:
- to:
uri: aws2-polly:test
parameters:
operation: listLexicons
- log:
message: "Lexicons: ${body}"
- removeHeader:
name: CamelAwsPollyNextToken
- to:
uri: aws2-polly:test
parameters:
operation: describeVoices With pojoRequest=true, the next token is taken from the request in the body, and the CamelAwsPollyNextToken header is set from the response in the same way.
Examples
Synthesize Speech example
from("direct:start")
.setHeader(Polly2Constants.VOICE_ID, constant(VoiceId.JOANNA))
.setBody(constant("Hello, this is a test of Amazon Polly text to speech synthesis."))
.to("aws2-polly://test?operation=synthesizeSpeech")
.to("file:output?fileName=speech.mp3"); As a result, you’ll get an exchange containing the audio stream (InputStream) with the synthesized speech.
Using Neural Voices
from("direct:start")
.setHeader(Polly2Constants.VOICE_ID, constant(VoiceId.MATTHEW))
.setHeader(Polly2Constants.ENGINE, constant(Engine.NEURAL))
.setBody(constant("This is synthesized using a neural voice."))
.to("aws2-polly://test?operation=synthesizeSpeech&outputFormat=MP3"); Describe Voices example
-
Java
-
XML
-
YAML
from("direct:start")
.to("aws2-polly://test?operation=describeVoices")
.log("Available voices: ${body}"); <route>
<from uri="direct:start"/>
<to uri="aws2-polly://test?operation=describeVoices"/>
<log message="Available voices: ${body}"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: aws2-polly://test
parameters:
operation: describeVoices
- log:
message: "Available voices: ${body}" Asynchronous Speech Synthesis with S3
For long text, you can use asynchronous synthesis which stores the result in S3:
from("direct:start")
.setHeader(Polly2Constants.VOICE_ID, constant(VoiceId.JOANNA))
.setHeader(Polly2Constants.S3_BUCKET, constant("my-audio-bucket"))
.setHeader(Polly2Constants.S3_KEY_PREFIX, constant("audio/"))
.setBody(constant("This is a very long text that will be synthesized asynchronously..."))
.to("aws2-polly://test?operation=startSpeechSynthesisTask"); Using a POJO as body
Sometimes building an AWS Request can be complex because of multiple options. We introduce the possibility to use a POJO as the body. In AWS Polly, you can do something like:
from("direct:start")
.setBody(SynthesizeSpeechRequest.builder()
.voiceId(VoiceId.JOANNA)
.outputFormat(OutputFormat.MP3)
.text("Hello from Camel!")
.build())
.to("aws2-polly://test?operation=synthesizeSpeech&pojoRequest=true"); In this way, you’ll pass the request directly without the need of passing headers and options specifically related to this operation.
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-polly</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.