

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

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

次のコードサンプルは、Python (boto3) ベースのアプリケーションを使用して発音レキシコンを AWS リージョンに格納する方法を示しています。

このオペレーションの詳細については、[https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html) API リファレンスを参照してください。

次の点に注意してください。
+ ローカルのレキシコンファイル名と保存済みのレキシコンの名前を指定してコードを更新する必要があります。
+ 例では、`pls` というサブディレクトリで作成したレキシコンファイルがあると想定しています。必要に応じてパスを更新する必要があります。

次のコード例では、AWS SDK の設定ファイルに保存してあるデフォルトの認証情報を使用します。設定ファイルを作成する方法については、「[のセットアップAWS CLI](setup-cli.md)」を参照してください。

このオペレーションの詳細については、[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))
```

