

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# PutLexicon
<a name="PutLexiconSamplePython"></a>

Contoh kode berikut menunjukkan cara menggunakan aplikasi berbasis Python (boto3) untuk menyimpan leksikon pengucapan di Wilayah. AWS 

Untuk informasi selengkapnya tentang operasi ini, lihat referensi untuk [https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html)API. 

Perhatikan hal berikut:
+ Anda perlu memperbarui kode dengan memberikan nama file leksikon lokal dan nama leksikon yang disimpan.
+ Contoh mengasumsikan Anda memiliki file leksikon yang dibuat dalam subdirektori yang disebut. `pls` Anda perlu memperbarui jalur yang sesuai.

Contoh kode berikut menggunakan kredensi default yang disimpan dalam file konfigurasi AWS SDK. Untuk informasi tentang membuat file konfigurasi, lihat[Menyiapkan AWS CLI](setup-cli.md). 

Untuk informasi selengkapnya tentang operasi ini, lihat referensi untuk [https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html)API. 



```
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))
```

