DeleteLexicon - Amazon Polly

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DeleteLexicon

以下 Python 程式碼範例使用AWS SDK for Python (Boto),來刪除在您本機的AWS組態。此範例僅刪除指定的語彙。此範例會在真正刪除語彙語彙前詢問您,以確認您要繼續進行。

以下程式碼範例使用儲存於AWS軟件開發工具包配置文件。如需建立組態檔的資訊,請參閱「步驟 2.1:設定 AWS CLI」。

如需此操作的詳細資訊,請參閱 DeleteLexicon API 的參考文章。

from argparse import ArgumentParser from sys import version_info from boto3 import Session from botocore.exceptions import BotoCoreError, ClientError # Define and parse the command line arguments cli = ArgumentParser(description="DeleteLexicon example") cli.add_argument("name", type=str, metavar="LEXICON_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") # Request confirmation prompt = input if version_info >= (3, 0) else raw_input proceed = prompt((u"This will delete the \"{0}\" lexicon," " do you want to proceed? [y,n]: ").format(arguments.name)) if proceed in ("y", "Y"): print(u"Deleting {0}...".format(arguments.name)) try: # Request deletion of a lexicon by name response = polly.delete_lexicon(Name=arguments.name) except (BotoCoreError, ClientError) as error: # The service returned an error, exit gracefully cli.error(error) print("Done.") else: print("Cancelled.")