Applying lexicons (Synthesizing Speech)
The lexicons you use must conform to the Pronunciation Lexicon Specification (PLS) W3C recommendation. For more information, see Pronunciation Lexicon Specification (PLS) Version 1.0
- Console
-
The following procedure demonstrates how to apply a lexicon to your input text by applying the
W3c.pls
lexicon to substitute "World Wide Web Consortium" for "W3C". If you apply multiple lexicons to your text they are applied in a top-down order with the first match taking precedence over later matches. A lexicon is applied to the text only if the language specified in the lexicon is the same as the language chosen.You can apply a lexicon to plain text or SSML input.
Example – Applying the W3C.pls Lexicon
To create the lexicon you'll need for this exercise, see Uploading a lexicon. Use a plain text editor to create the W3C.pls lexicon shown at the top of the topic. Remember where you save this file.
To apply the W3C.pls lexicon to your input
In this example we introduce a lexicon to substitute "World Wide Web Consortium" for "W3C". Compare the results of this exercise with that of Using SSML on the console for both US English and another language.
Sign in to the AWS Management Console and open the Amazon Polly console at https://console.aws.amazon.com/polly/
. -
Do one of the following:
-
Turn off SSML and then type or paste this text into the text input box.
He was caught up in the game. In the middle of the 10/3/2014 W3C meeting he shouted, "Score!" quite loudly.
-
Turn on SSML and then type or paste this text into the text input box.
<speak>He wasn't paying attention.<break time="1s"/> In the middle of the 10/3/2014 W3C meeting he shouted, "Score!" quite loudly.</speak>
-
-
From the Language list, choose English, US, then choose the voice you want to use for this text.
-
Expand Additional settings and turn on Customize pronunciation.
-
From the list of lexicons, choose
W3C (English, US)
.If the
W3C (English, US)
lexicon is not listed, choose Upload lexicon and upload it, then choose it from the list. To create this lexicon, see Uploading a lexicon. To listen to the speech immediately, choose Listen.
-
To save the speech to a file,
-
Choose Download.
-
To change to a different file format, turn on Speech file format settings, choose the file format you want, and then choose Download.
-
Repeat the previous steps, but choose a different language and notice the difference in the output.
- AWS CLI
-
In a call to
SynthesizeSpeech
, you can specify multiple lexicons. In this case, the first lexicon specified (in order from left to right) overrides any preceding lexicons.Consider the following two lexicons. Note that each lexicon describes different aliases for the same grapheme W3C.
-
Lexicon 1:
w3c.pls
<?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>W3C</grapheme> <alias>World Wide Web Consortium</alias> </lexeme> </lexicon>
-
Lexicon 2:
w3cAlternate.pls
<?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>W3C</grapheme> <alias>WWW Consortium</alias> </lexeme> </lexicon>
Suppose you store these lexicons as
w3c
andw3cAlternate
respectively. If you specify lexicons in order (w3c
followed byw3cAlternate
) in aSynthesizeSpeech
call, the alias for W3C defined in the first lexicon has precedence over the second. To test the lexicons, do the following:Save the lexicons locally in files called
w3c.pls
andw3cAlternate.pls
.Upload these lexicons using the
put-lexicon
AWS CLI command.-
Upload the
w3c.pls
lexicon and store it asw3c
.aws polly put-lexicon \ --name w3c \ --content file://w3c.pls
-
Upload the
w3cAlternate.pls
lexicon on the service asw3cAlternate
.aws polly put-lexicon \ --name w3cAlternate \ --content file://w3cAlternate.pls
-
Run the
synthesize-speech
command to synthesize sample text to an audio stream (speech.mp3
), and specify both lexicons using thelexicon-name
parameter.aws polly synthesize-speech \ --text 'PLS is a W3C recommendation' \ --voice-id Joanna \ --output-format mp3 \ --lexicon-names '["w3c","w3cAlternative"]' \ speech.mp3
-
Test the resulting
speech.mp3
. It should read as follows:PLS is a World Wide Web Consortium recommendation
-