Managing Lexicons

Pronunciation lexicons allows you to customize the pronunciation of words. For example, you can use lexicons pronounce AWS as Amazon Web Services. You can generate lexicons in an AWS region. Those lexicons are then specific to that region. You can manage lexicons using the `list-lexicons`, `put-lexicon`, `get-lexicon` and `delete-lexicon` commands.

Create a file named lexicon1.pls and add below text to it.

<?xml version="1.0" encoding="UTF-8"?>
<lexicon version="1.0"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
alphabet="ipa"
xml:lang="en-US">
<lexeme>
<grapheme>AWS</grapheme>
<alias>Amazon Web Services</alias>
</lexeme>
</lexicon>

The <lexeme> tags describes the mapping between <grapheme> and <alias>. <graphene> describes the which text needs modified pronunciation and <alias> defines how it should be pronounced. In this example, AWS will be pronounced as Amazon Web Services in the synthesized speech when this lexicon is used during speech synthesis.

To add this lexeme use the put-lexicon command. The –name option is used to specify the name of the lexicon. You can use it to refer to it during speech synthesis.

aws polly put-lexicon \
--name awslexicon \
--content file://lexicon1.pls

Now generate speech using the lexicon.

aws polly synthesize-speech \
--text 'Hello, This is a sample text recorded using AWS Polly.' \
--voice-id Joanna \
--output-format mp3 \
--lexicon-names="awslexicon" \
speech.mp3

Now AWS is synthesized as Amazon Web Services in speech.mp3

You can also include multiple lexeme in a single lexicon. For example,

<?xml version="1.0" encoding="UTF-8"?>
<lexicon version="1.0"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
alphabet="ipa"
xml:lang="en-US">
<lexeme>
<grapheme>AWS</grapheme>
<alias>Amazon Web Services</alias>
</lexeme>
<lexeme>
<grapheme>CLI</grapheme>
<alias>Command Line Interface</alias>
</lexeme>
</lexicon>

If two lexemes have same grapheme then the synthesis engine uses the one that comes first.

You can even use multiple lexicons in a single command.

aws polly synthesize-speech \
--text 'Hello, This is a sample text recorded using AWS Polly.' \
--voice-id Joanna \
--output-format mp3 \
--lexicon-names '["lexicon1","lexicon2"]' \
speech.mp3

Here, lexicon1 and lexicon2 are two lexicons. If any grapheme in both of them are same, the ones in the first lexicon that is lexicon1 will be used.

List all the available lexicons using the list-lexicons command

aws polly list-lexicons

Output:

Get a single lexicon by name using the get-lexicon command

aws polly get-lexicon --name awslexicon

Delete a lexicon using the `delete-lexicon` command

aws polly delete-lexicon --name awslexicon

Using Amazon Polly on the AWS CLI

Amazon Polly is a managed service provided by AWS that makes it easy to synthesize speech from text. In this article, we will learn how to use Polly through the AWS CLI. We will learn how to use all the commands available in Polly along with some examples.

Similar Reads

Using Polly with AWS CLI

Make sure you have the latest version of AWS CLI and configured your access keys before proceeding further....

Finding Help with AWS Polly in the CLI

Use the help command to get a list of commands that are available in AWS Polly CLI....

Synthesizing speech using AWS CLI commands

To synthesize speech use the `synthesize-speech` command.aws polly synthesize-speech \ --output-format mp3 \ --voice-id Joanna \ --text 'Hello, This is a sample text recorded using AWS Polly.' \ hello.mp3...

Managing Lexicons

Pronunciation lexicons allows you to customize the pronunciation of words. For example, you can use lexicons pronounce AWS as Amazon Web Services. You can generate lexicons in an AWS region. Those lexicons are then specific to that region. You can manage lexicons using the `list-lexicons`, `put-lexicon`, `get-lexicon` and `delete-lexicon` commands....

Using Amazon Polly on the AWS CLI – FAQs

How do I get help for AWS Polly CLI?...