Amazon Polly
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

DeleteLexicon

以下 Python 代码示例使用AWS SDK for Python (Boto)删除在本地 AWS 配置中指定的区域中的词典。该示例只删除指定的词典。在实际删除词典前,它会要求您确认要继续操作.

以下代码示例使用存储在 AWS 软件开发工具包配置文件中的默认凭证。有关创建配置文件的信息,请参阅 步骤 3.1:设置 AWS Command Line Interface (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.")