AWS Code Sample
Catalog

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

PutLexicon.py

PutLexicon.py demonstrates how to store a pronunciation lexicon in an AWS Region.

# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # http://aws.amazon.com/apache2.0/ # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. from argparse import ArgumentParser from boto3 import Session from botocore.exceptions import BotoCoreError, ClientError # Define and parse the command line arguments cli = ArgumentParser(description="PutLexicon example") cli.add_argument("path", type=str, metavar="FILE_PATH") cli.add_argument("-n", "--name", type=str, required=True, metavar="LEXICON_NAME", dest="name") arguments = cli.parse_args() # Create a client using the credentials and region defined in the adminuser # section of the AWS credentials and configuration files session = Session(profile_name="adminuser") polly = session.client("polly") # Open the PLS lexicon file for reading try: with open(arguments.path, "r") as lexicon_file: # Read the pls file contents lexicon_data = lexicon_file.read() # Store the PLS lexicon on the service. # If a lexicon with that name already exists, # its contents will be updated response = polly.put_lexicon(Name=arguments.name, Content=lexicon_data) except (IOError, BotoCoreError, ClientError) as error: # Could not open/read the file or the service returned an error, # exit gracefully cli.error(error) print(u"The \"{0}\" lexicon is now available for use.".format(arguments.name))

Sample Details

Service: polly

Last tested: 2019-01-31

Author: (AWS)

Type: full-example

On this page: