ListLexicon - Amazon Polly

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

ListLexicon

下列 Python 程式碼範例使用 AWS SDK for Python (Boto) 來列出您本機 AWS 組態中指定區域中您帳戶中的詞彙。如需建立組態檔的資訊,請參閱「設定 AWS CLI」。

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

import sys from boto3 import Session from botocore.exceptions import BotoCoreError, ClientError # 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") try: # Request the list of available lexicons response = polly.list_lexicons() except (BotoCoreError, ClientError) as error: # The service returned an error, exit gracefully print(error) sys.exit(-1) # Get the list of lexicons in the response lexicons = response.get("Lexicons", []) print("{0} lexicon(s) found".format(len(lexicons))) # Output a formatted list of lexicons with some of the attributes for lexicon in lexicons: print((u" - {Name} ({Attributes[LanguageCode]}), " "{Attributes[LexemesCount]} lexeme(s)").format(**lexicon))